File tree 2 files changed +15
-7
lines changed 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 7
7
import numpy as np
8
8
import pandas as pd
9
9
import pytest
10
+ from pandas .tseries .frequencies import to_offset
10
11
11
12
import xarray as xr
12
13
from xarray import (
@@ -2990,9 +2991,13 @@ def test_resample(self):
2990
2991
actual = array .resample (time = "24H" ).reduce (np .mean )
2991
2992
assert_identical (expected , actual )
2992
2993
2994
+ # Our use of `loffset` may change if we align our API with pandas' changes.
2995
+ # ref https://github.com/pydata/xarray/pull/4537
2993
2996
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 )
2996
3001
2997
3002
with raises_regex (ValueError , "index must be monotonic" ):
2998
3003
array [[2 , 0 , 1 ]].resample (time = "1D" )
Original file line number Diff line number Diff line change 9
9
import pandas as pd
10
10
import pytest
11
11
from pandas .core .indexes .datetimes import DatetimeIndex
12
+ from pandas .tseries .frequencies import to_offset
12
13
13
14
import xarray as xr
14
15
from xarray import (
@@ -3899,11 +3900,13 @@ def test_resample_loffset(self):
3899
3900
)
3900
3901
ds .attrs ["dsmeta" ] = "dsdata"
3901
3902
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 )
3907
3910
3908
3911
def test_resample_by_mean_discarding_attrs (self ):
3909
3912
times = pd .date_range ("2000-01-01" , freq = "6H" , periods = 10 )
You can’t perform that action at this time.
0 commit comments