Skip to content

Conversation

tomvothecoder
Copy link
Contributor

@tomvothecoder tomvothecoder commented Sep 18, 2025

A user reported an issue in #594 where _get_ordered_vertices fails to set the endpoints variable when the order of core dims are "mixed". In their case, the longitude coordinates are circular (0–360), and the 1-D core dimension isn’t strictly monotonic because it crosses the seam at 0°.

We should raise a ValueError for "mixed" cases, rather than silently fail (or normalize).

Long-term solution

Longer term, somebody can open a PR to consider opt-in support for circular axes, e.g. bounds_to_vertices(..., circular_period=360.0, start=None). With circular_period set, cf-xarray could detect circular monotonicity, rotate away from the seam, and proceed safely.

Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.75%. Comparing base (a9cebee) to head (bde699c).
⚠️ Report is 73 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #595      +/-   ##
==========================================
+ Coverage   85.78%   86.75%   +0.96%     
==========================================
  Files          13       15       +2     
  Lines        2364     3155     +791     
  Branches      183      302     +119     
==========================================
+ Hits         2028     2737     +709     
- Misses        303      367      +64     
- Partials       33       51      +18     
Flag Coverage Δ
mypy 45.25% <100.00%> (+6.72%) ⬆️
unittests 92.67% <0.00%> (-1.32%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@malmans2 malmans2 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

I think it makes sense to address #594 right away, and then work on the long-term solution in a separate PR.

Since this PR will close #594, could you please open a dedicated issue for the long-term solution you are proposing?

elif order == "descending":
endpoints = np.maximum(bounds[..., :, 0], bounds[..., :, 1])
last_endpoint = np.minimum(bounds[..., -1, 0], bounds[..., -1, 1])
elif order == "mixed":
Copy link
Member

Choose a reason for hiding this comment

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

Even if this is a private function, I would avoid having code that can result in an UnboundLocalError.
I suggest either replacing it with a bare else, or adding something like:

else:
    raise NotImplementedError(f"{order = }")

Copy link
Contributor Author

@tomvothecoder tomvothecoder Sep 24, 2025

Choose a reason for hiding this comment

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

The new code raises a ValueError with order=mixed, so it shouldn't result in UnboundLocalError. However, I updated this conditional to else as a fall-back for any order value (even if it should only be ascending, descending, or mixed).

Comment on lines +342 to +344
else:
raise NotImplementedError(
f"Cannot determine vertices for non-monotonic bounds with {order} core "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @malmans2, I addressed your comment here. This PR is ready for another review.

The new else statement will catch any order that is not "ascending" or "descending". I kept the same error message (beside specifying the order value) because it should be helpful for the user.

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

Successfully merging this pull request may close these issues.

Variable endpoints undefined when order is not ascending or descending
2 participants