Skip to content

Commit 6948d47

Browse files
committed
Fix logic for checking strictly monotonic
1 parent d7ad089 commit 6948d47

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cf_xarray/helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,12 @@ def _is_bounds_strictly_monotonic(arr: np.ndarray) -> bool:
301301
# np.diff.
302302
arr_numeric = arr.astype("float64").flatten()
303303
diffs = np.diff(arr_numeric)
304-
return np.all(diffs > 0) or np.all(diffs < 0)
304+
nonzero_diffs = diffs[diffs != 0]
305+
306+
if nonzero_diffs.size == 0:
307+
return True # All values are equal, treat as monotonic
308+
309+
return np.all(nonzero_diffs > 0) or np.all(nonzero_diffs < 0)
305310

306311

307312
def is_bounds_ascending(bounds: np.ndarray) -> bool:

0 commit comments

Comments
 (0)