Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cf_xarray/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ def _get_ordered_vertices(
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).

raise ValueError(
"Cannot determine vertices for non-monotonic bounds with mixed core "
"dimension orders. Try normalizing the coordinates to a monotonic "
"convention and try again."
)

vertices = np.concatenate(
[endpoints, np.expand_dims(last_endpoint, axis=-1)], axis=-1
Expand Down
Loading