From 15c709e715d0872bc462d2387517dbfc0aa64710 Mon Sep 17 00:00:00 2001 From: Tom Vo Date: Thu, 18 Sep 2025 13:43:28 -0700 Subject: [PATCH 1/3] Raise a ValueError in `_get_ordered_vertices()` with `"mixed"` core dim order --- cf_xarray/helpers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cf_xarray/helpers.py b/cf_xarray/helpers.py index 1053a55b..613fe68b 100644 --- a/cf_xarray/helpers.py +++ b/cf_xarray/helpers.py @@ -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": + 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 From 1a5eb22fb7a139026e00099142ac66dcb57ca9d4 Mon Sep 17 00:00:00 2001 From: Tom Vo Date: Wed, 24 Sep 2025 14:25:19 -0700 Subject: [PATCH 2/3] Replace ValueError with NotImplementedError --- cf_xarray/helpers.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cf_xarray/helpers.py b/cf_xarray/helpers.py index 613fe68b..81a03a15 100644 --- a/cf_xarray/helpers.py +++ b/cf_xarray/helpers.py @@ -332,15 +332,16 @@ def _get_ordered_vertices( if _is_bounds_monotonic(bounds): vertices = np.concatenate((bounds[..., :, 0], bounds[..., -1:, 1]), axis=-1) else: + if order == "ascending": endpoints = np.minimum(bounds[..., :, 0], bounds[..., :, 1]) last_endpoint = np.maximum(bounds[..., -1, 0], bounds[..., -1, 1]) elif order == "descending": endpoints = np.maximum(bounds[..., :, 0], bounds[..., :, 1]) last_endpoint = np.minimum(bounds[..., -1, 0], bounds[..., -1, 1]) - elif order == "mixed": - raise ValueError( - "Cannot determine vertices for non-monotonic bounds with mixed core " + else: + raise NotImplementedError( + f"Cannot determine vertices for non-monotonic bounds with {order} core " "dimension orders. Try normalizing the coordinates to a monotonic " "convention and try again." ) From bde699c5663cd732d5e945729acbaedc2f3fbd83 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Sep 2025 21:25:30 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cf_xarray/helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cf_xarray/helpers.py b/cf_xarray/helpers.py index 81a03a15..1fe34471 100644 --- a/cf_xarray/helpers.py +++ b/cf_xarray/helpers.py @@ -332,7 +332,6 @@ def _get_ordered_vertices( if _is_bounds_monotonic(bounds): vertices = np.concatenate((bounds[..., :, 0], bounds[..., -1:, 1]), axis=-1) else: - if order == "ascending": endpoints = np.minimum(bounds[..., :, 0], bounds[..., :, 1]) last_endpoint = np.maximum(bounds[..., -1, 0], bounds[..., -1, 1])