Skip to content

Commit 8ab7d3a

Browse files
Benoît Vinotjreback
Benoît Vinot
authored andcommitted
ENH: add .resample(..).interpolate() #12925
closes #12925 Author: Benoît Vinot <[email protected]> Closes #12974 from benoit9126/bug_12925 and squashes the following commits: b860b5b [Benoît Vinot] ENH resample().interpolate() #12925
1 parent 7fbc600 commit 8ab7d3a

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

doc/source/whatsnew/v0.18.1.txt

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

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

174+
- ``.resample(..).interpolate()`` is now supported (:issue:`12925`)
175+
176+
173177

174178
.. _whatsnew_0181.sparse:
175179

pandas/core/generic.py

Lines changed: 5 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,10 @@ 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):
35243526
if self.ndim > 2:
35253527
raise NotImplementedError("Interpolate has not been implemented "
35263528
"on Panel and Panel 4D objects.")

pandas/tseries/resample.py

Lines changed: 16 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

@@ -454,6 +458,18 @@ def fillna(self, method, limit=None):
454458
"""
455459
return self._upsample(method, limit=limit)
456460

461+
@Appender(_shared_docs['interpolate'] % _shared_docs_kwargs)
462+
def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
463+
limit_direction='forward', downcast=None, **kwargs):
464+
"""
465+
.. versionadded:: 0.18.1
466+
"""
467+
result = self._upsample(None)
468+
return result.interpolate(method=method, axis=axis, limit=limit,
469+
inplace=inplace,
470+
limit_direction=limit_direction,
471+
downcast=downcast, **kwargs)
472+
457473
def asfreq(self):
458474
"""
459475
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
@@ -612,6 +612,13 @@ def test_asfreq_upsample(self):
612612
expected = frame.reindex(new_index)
613613
assert_frame_equal(result, expected)
614614

615+
def test_resample_interpolate(self):
616+
# # 12925
617+
df = self.create_series().to_frame('value')
618+
assert_frame_equal(
619+
df.resample('1T').asfreq().interpolate(),
620+
df.resample('1T').interpolate())
621+
615622

616623
class TestDatetimeIndex(Base, tm.TestCase):
617624
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)