Skip to content

Commit 58e247e

Browse files
committed
Avoid warning
1 parent 3c0d585 commit 58e247e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

xarray/tests/test_groupby.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import pandas as pd
88
import pytest
9-
from pandas.tseries.frequencies import to_offset
109

1110
import xarray as xr
1211
from xarray import DataArray, Dataset, Variable
@@ -1860,7 +1859,9 @@ def test_resample_base(self) -> None:
18601859

18611860
with pytest.warns(FutureWarning, match="the `base` parameter to resample"):
18621861
actual = array.resample(time="24H", base=base).mean()
1863-
expected = DataArray(array.to_series().resample("24H", base=base).mean())
1862+
expected = DataArray(
1863+
array.to_series().resample("24H", offset=f"{base}H").mean()
1864+
)
18641865
assert_identical(expected, actual)
18651866

18661867
def test_resample_offset(self) -> None:
@@ -1897,15 +1898,22 @@ def test_resample_loffset(self, loffset) -> None:
18971898

18981899
with pytest.warns(FutureWarning, match="`loffset` parameter"):
18991900
actual = array.resample(time="24H", loffset=loffset).mean()
1900-
expected = DataArray(array.to_series().resample("24H", loffset=loffset).mean())
1901+
series = array.to_series().resample("24H").mean()
1902+
if not isinstance(loffset, pd.DateOffset):
1903+
loffset = pd.Timedelta(loffset)
1904+
series.index = series.index + loffset
1905+
expected = DataArray(series)
19011906
assert_identical(actual, expected)
19021907

19031908
def test_resample_invalid_loffset(self) -> None:
19041909
times = pd.date_range("2000-01-01", freq="6H", periods=10)
19051910
array = DataArray(np.arange(10), [("time", times)])
19061911

1907-
with pytest.raises(ValueError, match="`loffset` must be"):
1908-
array.resample(time="24H", loffset=1).mean() # type: ignore
1912+
with pytest.warns(
1913+
FutureWarning, match="Following pandas, the `loffset` parameter"
1914+
):
1915+
with pytest.raises(ValueError, match="`loffset` must be"):
1916+
array.resample(time="24H", loffset=1).mean() # type: ignore
19091917

19101918

19111919
class TestDatasetResample:
@@ -1993,14 +2001,6 @@ def test_resample_loffset(self):
19932001
)
19942002
ds.attrs["dsmeta"] = "dsdata"
19952003

1996-
# Our use of `loffset` may change if we align our API with pandas' changes.
1997-
# ref https://github.com/pydata/xarray/pull/4537
1998-
actual = ds.resample(time="24H", loffset="-12H").mean().bar
1999-
expected_ = ds.bar.to_series().resample("24H").mean()
2000-
expected_.index += to_offset("-12H")
2001-
expected = DataArray.from_series(expected_)
2002-
assert_allclose(actual, expected)
2003-
20042004
def test_resample_by_mean_discarding_attrs(self):
20052005
times = pd.date_range("2000-01-01", freq="6H", periods=10)
20062006
ds = Dataset(

0 commit comments

Comments
 (0)