Skip to content

Commit c50c5db

Browse files
committed
Test resampling error with monotonic decreasing data.
1 parent 192b2f6 commit c50c5db

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

xarray/core/groupby.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,11 @@ def __init__(
400400
unique_coord: DataArray | IndexVariable | _DummyGroup
401401
if grouper is not None:
402402
index = safe_cast_to_index(group)
403-
if not _unique_and_monotonic(group):
403+
if not index.is_montonic_increasing:
404404
# TODO: sort instead of raising an error
405-
raise ValueError("index must be monotonic for resampling")
405+
raise ValueError(
406+
"Index must be monotonic and increasing for resampling."
407+
)
406408
full_index, first_items = self._get_index_and_items(index, grouper)
407409
sbins = first_items.values.astype(np.int64)
408410
group_indices = [slice(i, j) for i, j in zip(sbins[:-1], sbins[1:])] + [

xarray/tests/test_groupby.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,10 @@ def test_resample(self):
15071507
with pytest.raises(ValueError, match=r"index must be monotonic"):
15081508
array[[2, 0, 1]].resample(time="1D")
15091509

1510+
reverse = array.isel(time=slice(-1, None, -1))
1511+
with pytest.raises(ValueError):
1512+
reverse.resample(time="1D").mean()
1513+
15101514
def test_da_resample_func_args(self):
15111515
def func(arg1, arg2, arg3=0.0):
15121516
return arg1.mean("time") + arg2 + arg3

0 commit comments

Comments
 (0)