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 xarray FutureWarning about dims vs sizes #297

Merged
merged 3 commits into from
Sep 6, 2024

Conversation

niksirbi
Copy link
Member

@niksirbi niksirbi commented Sep 3, 2024

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?

pytest caught a bunch of FutureWarnings of this type:

FutureWarning: The return type of Dataset.dims will be changed to return a set of dimension names in future, in order to be more consistent with DataArray.dims. To access a mapping from dimension names to lengths, please use Dataset.sizes.

To reproduce, run pytest locally on the main branch.

What does this PR do?

For cases when we actually access a dimensions size, we now switch to using ds.sizes (which returns a dict("dim_name": dims_size)), instead of ds.dims (which will return a set of dimensions names in future).

For cases when we just need the dim names (e.g. for checking if a given dimension exists), we keep using ds.dims, which works now (because it returns the dict keys) and should continue working in the future (will return a set).

References

I think some of the "offending" uses of ds.dims where introduced in #267 and I hadn't caught them during review.

How has this PR been tested?

All test pass without warnings.

Is this a breaking change?

No.

Does this PR require an update to the documentation?

No.

Checklist:

  • The code has been tested locally
  • [n/a] Tests have been added to cover all new functionality
  • [n/a] The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

Copy link

codecov bot commented Sep 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.77%. Comparing base (95965f8) to head (d4ec24d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #297   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files          14       14           
  Lines         883      883           
=======================================
  Hits          881      881           
  Misses          2        2           

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

@niksirbi niksirbi requested a review from sfmig September 3, 2024 11:28
@niksirbi niksirbi marked this pull request as ready for review September 3, 2024 11:28
Copy link

sonarcloud bot commented Sep 6, 2024

Copy link
Contributor

@sfmig sfmig left a comment

Choose a reason for hiding this comment

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

thanks @niksirbi 🚀
I added the ones from the kinematics tests - I think that should be all!

@sfmig sfmig added this pull request to the merge queue Sep 6, 2024
Merged via the queue into main with commit f4f46df Sep 6, 2024
23 checks passed
@sfmig sfmig deleted the ns-fix-xarray-future-warnings branch September 6, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants