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

compatibility with xr.DataTree #607

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mathause
Copy link
Member

  • Closes #xxx
  • Tests added
  • Fully documented, including CHANGELOG.rst

Adds compatibility with xr.DataTree. Works (at least locally) but is not finished and needs some ugly workarounds due to some design decisions in the new version... The new code path is only tested in upstream-dev ci.

I am not sure we should support both, datatree and xarray datatree, but this was actually the smaller part of the whole operation.

Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 81.66667% with 11 lines in your changes missing coverage. Please review.

Project coverage is 80.31%. Comparing base (bd011cf) to head (37d49e2).

Files with missing lines Patch % Lines
mesmer/core/_datatreecompat.py 42.10% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #607      +/-   ##
==========================================
- Coverage   80.42%   80.31%   -0.12%     
==========================================
  Files          49       50       +1     
  Lines        3076     3114      +38     
==========================================
+ Hits         2474     2501      +27     
- Misses        602      613      +11     
Flag Coverage Δ
unittests 80.31% <81.66%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mathause mathause closed this Jan 31, 2025
@mathause mathause reopened this Jan 31, 2025
@mathause
Copy link
Member Author

The upstream packages seem flaky

Copy link
Collaborator

@veni-vidi-vici-dormivi veni-vidi-vici-dormivi left a comment

Choose a reason for hiding this comment

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

Wow thanks, that is a lot of work! I think it's okay not to support xarray-datatree at all then, since it is not recommended to use it anyway.

tests/integration/test_calibrate_mesmer_newcodepath.py Outdated Show resolved Hide resolved
Copy link
Member Author

@mathause mathause left a comment

Choose a reason for hiding this comment

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

Thanks. It was mostly annoying because 98 % I did not understand what is happening 🤷‍♂️

As long as we need to patch xr.map_over_datasets we can just as well support datatree (because we need to import from _datatreecompat anyway.

It's annoying that the new version has become so bothersome to work with 😒


# https://github.com/pydata/xarray/issues/10013
# tas_anoms = dt - ref.ds
tas_anoms = map_over_datasets(operator.sub, dt, ref.ds)
Copy link
Member Author

Choose a reason for hiding this comment

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

This takes all the fun out of using xr.DataTree and cannot be expected from a user. The other 'issues' (missing methods) will probably be fixed in time but this seems to be a design decision. 👎

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I agree.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think what we have to do is write a helper function calc_anomaly(dt, ref_period) with this inside.

tests/integration/test_calibrate_mesmer_newcodepath.py Outdated Show resolved Hide resolved
@mathause
Copy link
Member Author

mathause commented Feb 3, 2025

I have not yet updated the example scripts and we need to fix the pin for xarray (so it's not only tested in upstream-dev ci).

@mathause
Copy link
Member Author

I opened pydata/xarray#10042 - there seems to be some willingness to enable skipping empty nodes. With this change we could avoid the skip_empty_nodes helper function and I'd say that's the moment we can "fully" support xr.DataTree.

But not super convinced this PR gets a fast turnaround 😒

@mathause
Copy link
Member Author

Ah yes and after 507cd1c this definitely requires xarray main, i.e. we require

xarray >=2023.07, < 2024.10, > 2025.1

(thats probably not a valid specifier)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants