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)