neuroinformatics-unit / movement

Python tools for analysing body movements across space and time
http://movement.neuroinformatics.dev
BSD 3-Clause "New" or "Revised" License
96 stars 8 forks source link

Fix xarray FutureWarning about dims vs sizes #297

Closed niksirbi closed 3 weeks ago

niksirbi commented 4 weeks ago

Description

What is this PR

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:

codecov[bot] commented 4 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sonarcloud[bot] commented 3 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud