Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should xarray.align sort indexes in alignment? #2719

Closed
shoyer opened this issue Jan 27, 2019 · 1 comment
Closed

Should xarray.align sort indexes in alignment? #2719

shoyer opened this issue Jan 27, 2019 · 1 comment

Comments

@shoyer
Copy link
Member

shoyer commented Jan 27, 2019

I noticed in pandas-dev/pandas#24959 (which turned up as a failure in our test suite) that pandas sorts by default in Index.union and now Index.intersection, unless the indexes are the same or either index has duplicates. (These aspects are probably bugs.)

It occurs to me that we should make an intentional choice about sorting in xarray.align(), rather than merely following the whims of changed upstream behavior. Note that align() is called internally by all xarray operations that combine multiple objects (e.g., in arithmetic).

My proposal is to use "order of appearance" and not sort by default, but add a sort keyword argument to allow users to control this. Reasons for the default behavior of not sorting:

  1. Sorting can't be undone if the original order is lost, so this preserve maximum flexibility for users.
  2. This matches how we handle the ordering of dimensions in broadcasting.
  3. Pandas is quite inconsistent with how it applies sorting and we don't want to copy that in xarray. We definitely don't want to sort in all cases by default (e.g., if objects have the same index), so we should avoid sorting in others.
@shoyer
Copy link
Member Author

shoyer commented Jan 28, 2019

We may not need to change this in xarray after all -- its seems that the upstream consensus is that alignment operations shouldn't sort by default, and the breaking change in pandas 0.24.x is going to be reverted (see pandas-dev/pandas#24959).

@max-sixty max-sixty closed this as not planned Won't fix, can't repro, duplicate, stale Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants