Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for date offset strings with resample loffset #8422

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion xarray/core/resample_cftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_cftimeindex_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
Loading