Skip to content

Commit

Permalink
ENH: add .resample(..).interpolate() #12925
Browse files Browse the repository at this point in the history
closes #12925

Author: Benoît Vinot <benoit.vinot@inria.fr>

Closes #12974 from benoit9126/bug_12925 and squashes the following commits:

b860b5b [Benoît Vinot] ENH resample().interpolate() #12925
  • Loading branch information
Benoît Vinot authored and jreback committed Apr 26, 2016
1 parent 7fbc600 commit 8ab7d3a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v0.18.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,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 <reshaping.crosstabulations>`.

- ``.resample(..).interpolate()`` is now supported (:issue:`12925`)



.. _whatsnew_0181.sparse:

Expand Down
8 changes: 5 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3521,6 +3519,10 @@ 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):
if self.ndim > 2:
raise NotImplementedError("Interpolate has not been implemented "
"on Panel and Panel 4D objects.")
Expand Down
16 changes: 16 additions & 0 deletions pandas/tseries/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -454,6 +458,18 @@ 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):
"""
.. versionadded:: 0.18.1
"""
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,
Expand Down
7 changes: 7 additions & 0 deletions pandas/tseries/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,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
Expand Down

0 comments on commit 8ab7d3a

Please sign in to comment.