From 33c803324e0b511b0e77b7d78b120a034ef34eab Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 2 Jan 2024 20:40:42 -0700 Subject: [PATCH] Don't skip for resampling --- xarray/core/groupby.py | 3 ++- xarray/tests/test_groupby.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 6cd818d3235..ebb488d42c9 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -414,8 +414,9 @@ def group_as_index(self) -> pd.Index: @property def can_squeeze(self) -> bool: + is_resampler = isinstance(self.grouper, TimeResampleGrouper) is_dimension = self.group.dims == (self.group.name,) - return is_dimension and self.is_unique_and_monotonic + return not is_resampler and is_dimension and self.is_unique_and_monotonic @dataclass diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py index cd0df4b93b1..e45d8ed0bef 100644 --- a/xarray/tests/test_groupby.py +++ b/xarray/tests/test_groupby.py @@ -1786,6 +1786,10 @@ def test_resample_first(self): times = pd.date_range("2000-01-01", freq="6h", periods=10) array = DataArray(np.arange(10), [("time", times)]) + # resample to same frequency + actual = array.resample(time="6h").first() + assert_identical(array, actual) + actual = array.resample(time="1D").first() expected = DataArray([0, 4, 8], [("time", times[::4])]) assert_identical(expected, actual)