Fix negligible coordinate dimension matching - #3447
sylvesterkaczmarek wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3447 +/- ##
=======================================
Coverage 96.33% 96.34%
=======================================
Files 467 465 -2
Lines 59142 59168 +26
=======================================
+ Hits 56977 57007 +30
+ Misses 2165 2161 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Sorry, I'm confused by this. So we have DataArray A that has dimensions |
Yes, exactly. xarray allows a DataArray with dimensions (time, y, x) to have a coordinate named time whose own dimensions are (y,). That is the second reproducer in #3353. The current logic only checks whether the coordinate name time exists in ds.dims, so it incorrectly treats that time(y) coordinate as the coordinate variable for the time dimension. This PR instead checks the coordinate's own dimensions and only preserves the true dimension-coordinate case time(time). |
|
That is a strange case and it seems I said the same thing in my comment in #3353. Unfortunately @gerritholl is going on holiday for a while so we can't get his perspective on the issue as he saw it. Two requests:
|
ce80651 to
0df7cd3
Compare
Thanks, both suggestions make sense. I’ve moved the regression cases into the existing test_core.py module alongside the other CompositeBase coordinate tests, and extracted the coordinate-variable check into _is_coord_var. The filtering now reads explicitly in terms of whether the coordinate is the variable for its same-named dimension. CI is rerunning now. |
Manny7717
left a comment
There was a problem hiding this comment.
Verified locally on CPU (head f091316 vs the pre-fix core.py blob from the PR diff base 1b124eb88a).
Bug is real: old logic kept any negligible coord whose NAME is a dim (coord not in ds.dims was False), so time(y) riding on an array that separately has a time dimension survived drop_coordinates even though it does not describe the time dimension. The new _is_coord_var check (ds.coords[name].dims == (name,)) is the correct criterion for "this coordinate is the variable for its own dimension".
Regression proof (executed): the 3 new tests pass at head; with the pre-fix drop_coordinates logic, test_drop_coordinates_drops_mismatched_same_named_coordinate FAILS (the genuine #3353 case — time(y) retained alongside a real time dim) while the other two pass pre-fix as expected (they lock pre-existing behavior: true dimension coord kept, non-dim time(y) without a time dim dropped). Honest, targeted coverage.
No collateral: full satpy/tests/compositor_tests/test_core.py → 36/36 at head. NEGLIGIBLE_COORDS = ["time"] substring matching is unchanged; the helper only tightens the retention rule for same-named coords on foreign dims.
Not stale: the PR diff-base core.py is byte-identical to current main's core.py except the removed GPL header (relicense #3451), so the change applies cleanly post-relicense; mergeable=MERGEABLE.
Repo CI already fully green on this head (CodeFactor, CodeScene, codecov, coveralls, RTD, pre-commit.ci, full test matrix). No human reviews yet — this is the first independent human-equivalent verification.
|
@gerritholl I think you're back at work right? Any chance you have time to review this since it was your original issue? |
There was a problem hiding this comment.
I'm sorry it has been a while, but I have one more request. Could you combine these 3 new tests into a single test and use pytest's parametrize? The data creation is very similar and the checks are very similar so I'm hoping it only needs to be 2-4 arguments and maybe even improved checks (checking dims and coords in the result).
Fixes #3353.
CompositeBase.drop_coordinatescurrently checks only whether a coordinate name also appears inDataArray.dims. This can preservetime(y)whenever the array separately has atimedimension, even though that coordinate does not describe thetimedimension.This changes the check to preserve a negligible coordinate only when its own dimensions are exactly its same-named dimension, for example
time(time).Tests cover:
time(y)without atimedimensiontime(y)when a separatetimedimension existstime(time)dimension coordinateTesting: