Skip to content

Commit dfe50b8

Browse files
max-sixtykeewis
andauthored
Adjust tests to use updated pandas syntax for offsets (#4537)
* Adjust tests to use updated pandas syntax for offsets * Revert irrelevant change * Retain calcs for `actual` * Update xarray/tests/test_dataarray.py Co-authored-by: keewis <[email protected]> * Apply suggestions from code review * fix imports Co-authored-by: keewis <[email protected]> Co-authored-by: Keewis <[email protected]>
1 parent 229829f commit dfe50b8

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

xarray/tests/test_dataarray.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import pandas as pd
99
import pytest
10+
from pandas.tseries.frequencies import to_offset
1011

1112
import xarray as xr
1213
from xarray import (
@@ -2990,9 +2991,13 @@ def test_resample(self):
29902991
actual = array.resample(time="24H").reduce(np.mean)
29912992
assert_identical(expected, actual)
29922993

2994+
# Our use of `loffset` may change if we align our API with pandas' changes.
2995+
# ref https://github.com/pydata/xarray/pull/4537
29932996
actual = array.resample(time="24H", loffset="-12H").mean()
2994-
expected = DataArray(array.to_series().resample("24H", loffset="-12H").mean())
2995-
assert_identical(expected, actual)
2997+
expected_ = array.to_series().resample("24H").mean()
2998+
expected_.index += to_offset("-12H")
2999+
expected = DataArray.from_series(expected_)
3000+
assert_identical(actual, expected)
29963001

29973002
with raises_regex(ValueError, "index must be monotonic"):
29983003
array[[2, 0, 1]].resample(time="1D")

xarray/tests/test_dataset.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pandas as pd
1010
import pytest
1111
from pandas.core.indexes.datetimes import DatetimeIndex
12+
from pandas.tseries.frequencies import to_offset
1213

1314
import xarray as xr
1415
from xarray import (
@@ -3899,11 +3900,13 @@ def test_resample_loffset(self):
38993900
)
39003901
ds.attrs["dsmeta"] = "dsdata"
39013902

3902-
actual = ds.resample(time="24H", loffset="-12H").mean("time").time
3903-
expected = xr.DataArray(
3904-
ds.bar.to_series().resample("24H", loffset="-12H").mean()
3905-
).time
3906-
assert_identical(expected, actual)
3903+
# Our use of `loffset` may change if we align our API with pandas' changes.
3904+
# ref https://github.com/pydata/xarray/pull/4537
3905+
actual = ds.resample(time="24H", loffset="-12H").mean().bar
3906+
expected_ = ds.bar.to_series().resample("24H").mean()
3907+
expected_.index += to_offset("-12H")
3908+
expected = DataArray.from_series(expected_)
3909+
assert_identical(actual, expected)
39073910

39083911
def test_resample_by_mean_discarding_attrs(self):
39093912
times = pd.date_range("2000-01-01", freq="6H", periods=10)

0 commit comments

Comments
 (0)