From 77a41a604eddf321bade0e146ed67e4e304163fc Mon Sep 17 00:00:00 2001 From: Katelyn FitzGerald <7872563+kafitzgerald@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:07:42 -0700 Subject: [PATCH 1/3] change back to using to_offset in first_items --- xarray/core/resample_cftime.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xarray/core/resample_cftime.py b/xarray/core/resample_cftime.py index 5e3f2f57397..7241faa1c61 100644 --- a/xarray/core/resample_cftime.py +++ b/xarray/core/resample_cftime.py @@ -151,7 +151,10 @@ def first_items(self, index: CFTimeIndex): f"Got {self.loffset}." ) - labels = labels + pd.to_timedelta(self.loffset) + if isinstance(self.loffset, datetime.timedelta): + labels = labels + self.loffset + else: + labels = labels + to_offset(self.loffset) # check binner fits data if index[0] < datetime_bins[0]: From 72f140b4da92fd14f4dca439cbb86fbe81cd4b7f Mon Sep 17 00:00:00 2001 From: Katelyn FitzGerald <7872563+kafitzgerald@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:18:43 -0700 Subject: [PATCH 2/3] add date offset to loffset test --- xarray/tests/test_cftimeindex_resample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/tests/test_cftimeindex_resample.py b/xarray/tests/test_cftimeindex_resample.py index f8e6e80452a..284460c3686 100644 --- a/xarray/tests/test_cftimeindex_resample.py +++ b/xarray/tests/test_cftimeindex_resample.py @@ -260,7 +260,7 @@ def test_timedelta_offset() -> None: xr.testing.assert_identical(timedelta_result, string_result) -@pytest.mark.parametrize("loffset", ["12H", datetime.timedelta(hours=-12)]) +@pytest.mark.parametrize("loffset", ["MS", "12H", datetime.timedelta(hours=-12)]) def test_resample_loffset_cftimeindex(loffset) -> None: datetimeindex = pd.date_range("2000-01-01", freq="6H", periods=10) da_datetimeindex = xr.DataArray(np.arange(10), [("time", datetimeindex)]) From 383bbd85d1eeb9f8f2132b83dbe133c30508a8c2 Mon Sep 17 00:00:00 2001 From: Katelyn FitzGerald <7872563+kafitzgerald@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:38:22 -0700 Subject: [PATCH 3/3] add to release notes --- doc/whats-new.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 3a9be494db2..b6bad62dd7c 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -50,6 +50,9 @@ Bug fixes ``"right"`` to xarray's implementation of resample for data indexed by a :py:class:`CFTimeIndex` (:pull:`8393`). By `Spencer Clark `_. +- Fix to once again support date offset strings as input to the loffset + parameter of resample and test this functionality (:pull:`8422`, :issue:`8399`). + By `Katelyn FitzGerald `_. Documentation ~~~~~~~~~~~~~