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

Fix multiindex error on upstream xr #1450

Merged
merged 4 commits into from
Aug 3, 2023
Merged

Fix multiindex error on upstream xr #1450

merged 4 commits into from
Aug 3, 2023

Conversation

aulemahal
Copy link
Collaborator

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features)
    • (If applicable) Documentation has been added / updated (for bug fixes / features)
  • CHANGES.rst has been updated (with summary of main changes)
    • Link to issue (:issue:number) and pull request (:pull:number) has been added

What kind of change does this PR introduce?

Overriding a coordinate with a pandas MultiIndex was not working properly before, but this didn't result in any errors up to a recent change in xarray's master. When calling assign_coords with a multiindex on a coordinate that already existed, the sub-indexes would not appear in the DataArray repr. In the most recent xarray master, that now triggers an error when trying to unstack the multiindex, but only if dask is used. Before, the unstacking would proceed as normal and the sub-indexes would magically appear on the result. Dropping the previous coordinate solves this problem.

The next xarray will implement a new public xr.Coordinates class that should be used to assign coords, instead of a raw pd.MultiIndex. Nonetheless, overriding is still not possible and dropping the previous coordinate is still needed.

Does this PR introduce a breaking change?

No.

Other information:

See pydata/xarray#8039.

Copy link
Collaborator

@Zeitsperre Zeitsperre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +679 to +680
# xarray > 2023.7.0 will deprecate passing a Pandas MultiIndex directly.
# TODO: Remove this condition when pinning xarray above 2023.7.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can never figure out whether it makes to wrap this in a try/except, perform a version check, make some other conditional check.

This looks good, but we have these kinds of workarounds scattered throughout the code base, and I imagine that some of these are now obsolete. We should perform an inventory of these at some point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing with this one is that the other line does work even with the newest master of xarray! But there's discussions to deprecate it.

I thought that with a "TODO:" it would be easier to find ? But yes indeed, we could try to find all version-dependent code paths at some point and prune what's not needed anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to add a theme to my todo like TODO: [version-specific] .... or TODO: [deprecation] ...
It make it slightly easier to grep and make an inventory.

@github-actions github-actions bot added the approved Approved for additional tests label Aug 3, 2023
@aulemahal aulemahal merged commit f126728 into master Aug 3, 2023
22 checks passed
@aulemahal aulemahal deleted the fix-upsxr-percdoy branch August 3, 2023 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved for additional tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

⚠️ Nightly upstream-dev CI failed ⚠️
3 participants