Skip to content

Commit b860b5b

Browse files
author
Benoît Vinot
committed
ENH resample().interpolate() #12925
1 parent a544e9e commit b860b5b

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

doc/source/whatsnew/v0.18.1.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ Other Enhancements
9494
idx = pd.Index(['a|b', 'a|c', 'b|c'])
9595
idx.str.get_dummies('|')
9696

97+
9798
- ``pd.crosstab()`` has gained a ``normalize`` argument for normalizing frequency tables (:issue:`12569`). Examples in the updated docs :ref:`here <reshaping.crosstabulations>`.
9899

100+
- ``.resample(..).interpolate()`` is now supported (:issue:`12925`)
101+
102+
99103

100104
.. _whatsnew_0181.sparse:
101105

pandas/core/generic.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,9 +3445,7 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
34453445
else:
34463446
return self._constructor(new_data).__finalize__(self)
34473447

3448-
def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
3449-
limit_direction='forward', downcast=None, **kwargs):
3450-
"""
3448+
_shared_docs['interpolate'] = """
34513449
Interpolate values according to different methods.
34523450
34533451
Please note that only ``method='linear'`` is supported for
@@ -3521,6 +3519,14 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
35213519
dtype: float64
35223520
35233521
"""
3522+
3523+
@Appender(_shared_docs['interpolate'] % _shared_doc_kwargs)
3524+
def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
3525+
limit_direction='forward', downcast=None, **kwargs):
3526+
"""
3527+
.. versionadded:: 0.18.1
3528+
``.resample(..).interpolate()`` is now supported (:issue:`12925`)
3529+
"""
35243530
if self.ndim > 2:
35253531
raise NotImplementedError("Interpolate has not been implemented "
35263532
"on Panel and Panel 4D objects.")

pandas/tseries/resample.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import pandas.lib as lib
2222
import pandas.tslib as tslib
2323

24+
from pandas.util.decorators import Appender
25+
from pandas.core.generic import _shared_docs
26+
_shared_docs_kwargs = dict()
27+
2428

2529
class Resampler(_GroupBy):
2630

@@ -448,6 +452,15 @@ def fillna(self, method, limit=None):
448452
"""
449453
return self._upsample(method, limit=limit)
450454

455+
@Appender(_shared_docs['interpolate'] % _shared_docs_kwargs)
456+
def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
457+
limit_direction='forward', downcast=None, **kwargs):
458+
result = self._upsample(None)
459+
return result.interpolate(method=method, axis=axis, limit=limit,
460+
inplace=inplace,
461+
limit_direction=limit_direction,
462+
downcast=downcast, **kwargs)
463+
451464
def asfreq(self):
452465
"""
453466
return the values at the new freq,

pandas/tseries/tests/test_resample.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,13 @@ def test_asfreq_upsample(self):
620620
expected = frame.reindex(new_index)
621621
assert_frame_equal(result, expected)
622622

623+
def test_resample_interpolate(self):
624+
# # 12925
625+
df = self.create_series().to_frame('value')
626+
assert_frame_equal(
627+
df.resample('1T').asfreq().interpolate(),
628+
df.resample('1T').interpolate())
629+
623630

624631
class TestDatetimeIndex(Base, tm.TestCase):
625632
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)