From 4c5650934aee405139adfa027654eebc1d563744 Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Wed, 4 Oct 2017 09:47:01 -0700 Subject: [PATCH 1/3] regression test for 1605 --- xarray/tests/test_dataarray.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index e7920570fc8..ee98fe58e1f 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -2077,6 +2077,12 @@ def test_upsample_interpolate(self): # done here due to floating point arithmetic self.assertDataArrayAllClose(expected, actual, rtol=1e-16) + @requires_scipy + def test_upsample_interpolate_regression_1605(self): + ds = xr.tutorial.load_dataset('air_temperature') + array = ds['air'] + array.resample(time='15d').interpolate(kind='linear') + @requires_dask def test_upsample_interpolate_dask(self): import dask.array as da From 25e24ca173655beeb84b44468b6534c36645d626 Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Wed, 4 Oct 2017 10:47:59 -0700 Subject: [PATCH 2/3] fix to Resample.interpolate to allow application on equal frequencies --- xarray/core/groupby.py | 2 +- xarray/tests/test_dataarray.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index b5fb02a8083..320dcdd3847 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -236,8 +236,8 @@ def __init__(self, obj, group, squeeze=False, grouper=None, bins=None, raise ValueError('index must be monotonic for resampling') s = pd.Series(np.arange(index.size), index) first_items = s.groupby(grouper).first() + full_index = first_items.index if first_items.isnull().any(): - full_index = first_items.index first_items = first_items.dropna() sbins = first_items.values.astype(np.int64) group_indices = ([slice(i, j) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index ee98fe58e1f..9e921d94d2d 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -2079,9 +2079,12 @@ def test_upsample_interpolate(self): @requires_scipy def test_upsample_interpolate_regression_1605(self): - ds = xr.tutorial.load_dataset('air_temperature') - array = ds['air'] - array.resample(time='15d').interpolate(kind='linear') + dates = pd.date_range('2016-01-01', '2016-03-31', freq='1D') + expected = xr.DataArray(np.random.random((len(dates), 2, 3)), + dims=('time', 'x', 'y'), + coords={'time': dates}) + actual = expected.resample(time='1D').interpolate('linear') + self.assertDataArrayAllClose(actual, expected, rtol=1e-16) @requires_dask def test_upsample_interpolate_dask(self): From 9c5601384fb4500daf2d8cabd74377312e5d1a1b Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Thu, 5 Oct 2017 09:13:18 -0700 Subject: [PATCH 3/3] new assert statement --- xarray/tests/test_dataarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 9e921d94d2d..4b1a9d7880f 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -2084,7 +2084,7 @@ def test_upsample_interpolate_regression_1605(self): dims=('time', 'x', 'y'), coords={'time': dates}) actual = expected.resample(time='1D').interpolate('linear') - self.assertDataArrayAllClose(actual, expected, rtol=1e-16) + assert_allclose(actual, expected, rtol=1e-16) @requires_dask def test_upsample_interpolate_dask(self):