diff --git a/doc/source/whatsnew/v0.18.1.txt b/doc/source/whatsnew/v0.18.1.txt index cc2269afa6e61..f46dcb97a013d 100644 --- a/doc/source/whatsnew/v0.18.1.txt +++ b/doc/source/whatsnew/v0.18.1.txt @@ -94,8 +94,12 @@ Other Enhancements idx = pd.Index(['a|b', 'a|c', 'b|c']) idx.str.get_dummies('|') + - ``pd.crosstab()`` has gained a ``normalize`` argument for normalizing frequency tables (:issue:`12569`). Examples in the updated docs :ref:`here `. +- ``.resample(..).interpolate()`` is now supported (:issue:`12925`) + + .. _whatsnew_0181.sparse: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3b68bfc6b05ea..5c26c3ff1a9cb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3445,9 +3445,7 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None, else: return self._constructor(new_data).__finalize__(self) - def interpolate(self, method='linear', axis=0, limit=None, inplace=False, - limit_direction='forward', downcast=None, **kwargs): - """ + _shared_docs['interpolate'] = """ Interpolate values according to different methods. Please note that only ``method='linear'`` is supported for @@ -3521,6 +3519,14 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False, dtype: float64 """ + + @Appender(_shared_docs['interpolate'] % _shared_doc_kwargs) + def interpolate(self, method='linear', axis=0, limit=None, inplace=False, + limit_direction='forward', downcast=None, **kwargs): + """ + .. versionadded:: 0.18.1 + ``.resample(..).interpolate()`` is now supported (:issue:`12925`) + """ if self.ndim > 2: raise NotImplementedError("Interpolate has not been implemented " "on Panel and Panel 4D objects.") diff --git a/pandas/tseries/resample.py b/pandas/tseries/resample.py index 4a6592da0cb41..4b59dda1c8aba 100644 --- a/pandas/tseries/resample.py +++ b/pandas/tseries/resample.py @@ -21,6 +21,10 @@ import pandas.lib as lib import pandas.tslib as tslib +from pandas.util.decorators import Appender +from pandas.core.generic import _shared_docs +_shared_docs_kwargs = dict() + class Resampler(_GroupBy): @@ -448,6 +452,15 @@ def fillna(self, method, limit=None): """ return self._upsample(method, limit=limit) + @Appender(_shared_docs['interpolate'] % _shared_docs_kwargs) + def interpolate(self, method='linear', axis=0, limit=None, inplace=False, + limit_direction='forward', downcast=None, **kwargs): + result = self._upsample(None) + return result.interpolate(method=method, axis=axis, limit=limit, + inplace=inplace, + limit_direction=limit_direction, + downcast=downcast, **kwargs) + def asfreq(self): """ return the values at the new freq, diff --git a/pandas/tseries/tests/test_resample.py b/pandas/tseries/tests/test_resample.py index 091e36ad7c049..f6cd9afba0579 100644 --- a/pandas/tseries/tests/test_resample.py +++ b/pandas/tseries/tests/test_resample.py @@ -620,6 +620,13 @@ def test_asfreq_upsample(self): expected = frame.reindex(new_index) assert_frame_equal(result, expected) + def test_resample_interpolate(self): + # # 12925 + df = self.create_series().to_frame('value') + assert_frame_equal( + df.resample('1T').asfreq().interpolate(), + df.resample('1T').interpolate()) + class TestDatetimeIndex(Base, tm.TestCase): _multiprocess_can_split_ = True