Skip to content

Commit 8710e08

Browse files
author
Joe Hamman
authored
Fix resample/interpolate for non-upsampling case (#1608)
* regression test for 1605 * fix to Resample.interpolate to allow application on equal frequencies * new assert statement
1 parent c748062 commit 8710e08

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

xarray/core/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ def __init__(self, obj, group, squeeze=False, grouper=None, bins=None,
236236
raise ValueError('index must be monotonic for resampling')
237237
s = pd.Series(np.arange(index.size), index)
238238
first_items = s.groupby(grouper).first()
239+
full_index = first_items.index
239240
if first_items.isnull().any():
240-
full_index = first_items.index
241241
first_items = first_items.dropna()
242242
sbins = first_items.values.astype(np.int64)
243243
group_indices = ([slice(i, j)

xarray/tests/test_dataarray.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,15 @@ def test_upsample_interpolate(self):
20772077
# done here due to floating point arithmetic
20782078
self.assertDataArrayAllClose(expected, actual, rtol=1e-16)
20792079

2080+
@requires_scipy
2081+
def test_upsample_interpolate_regression_1605(self):
2082+
dates = pd.date_range('2016-01-01', '2016-03-31', freq='1D')
2083+
expected = xr.DataArray(np.random.random((len(dates), 2, 3)),
2084+
dims=('time', 'x', 'y'),
2085+
coords={'time': dates})
2086+
actual = expected.resample(time='1D').interpolate('linear')
2087+
assert_allclose(actual, expected, rtol=1e-16)
2088+
20802089
@requires_dask
20812090
def test_upsample_interpolate_dask(self):
20822091
import dask.array as da

0 commit comments

Comments
 (0)