Skip to content

Commit 8e7db2a

Browse files
committed
STEP pandas-dev#2 added interpolate_at() and interpolate_na() on top of interpolate(), some error handling and filtering may be missing, testing is not done yet
1 parent 340da19 commit 8e7db2a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pandas/core/internals.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import copy
1+
import copy
22
import itertools
33
import re
44
import operator
@@ -745,10 +745,18 @@ def putmask(self, mask, new, align=True, inplace=False,
745745

746746
return [make_block(new_values, placement=self.mgr_locs, fastpath=True)]
747747

748-
def interpolate(self, method='pad', axis=0, index=None,
748+
def interpolate_na(self, inplace=False, **kwargs):
749+
return self.interpolate(new_idxs=None, inplace=inplace, **kwargs)
750+
751+
def interpolate_at(self, new_idxs, **kwargs):
752+
#TODO: check dupes, nans, unique idx
753+
return self.interpolate(new_idxs=new_idxs,inplace=False,**kwargs)
754+
755+
def interpolate(self, new_idxs=None, method='pad', axis=0, index=None,
749756
values=None, inplace=False, limit=None,
750757
fill_value=None, coerce=False, downcast=None, **kwargs):
751-
758+
if inplace and new_idxs:
759+
raise ValueError('inplace=True and new_idxs not empty are incompatible options')
752760
def check_int_bool(self, inplace):
753761
# Only FloatBlocks will contain NaNs.
754762
# timedelta subclasses IntBlock
@@ -785,7 +793,8 @@ def check_int_bool(self, inplace):
785793
r = check_int_bool(self, inplace)
786794
if r is not None:
787795
return r
788-
return self._interpolate(method=m,
796+
return self._interpolate(new_idxs=new_idxs,
797+
method=m,
789798
index=index,
790799
values=values,
791800
axis=axis,
@@ -827,7 +836,7 @@ def _interpolate_with_fill(self, method='pad', axis=0, inplace=False,
827836
fastpath=True, placement=self.mgr_locs)]
828837
return self._maybe_downcast(blocks, downcast)
829838

830-
def _interpolate(self, method=None, index=None, values=None,
839+
def _interpolate(self, new_idxs=None, method=None, index=None, values=None,
831840
fill_value=None, axis=0, limit=None,
832841
inplace=False, downcast=None, **kwargs):
833842
""" interpolate using scipy wrappers """
@@ -854,7 +863,7 @@ def func(x):
854863
# process a 1-d slice, returning it
855864
# should the axis argument be handled below in apply_along_axis?
856865
# i.e. not an arg to com.interpolate_1d
857-
return com.interpolate_1d(index, x, method=method, limit=limit,
866+
return com.interpolate_1d(index, x, new_idxs=new_idxs, method=method, limit=limit,
858867
fill_value=fill_value,
859868
bounds_error=False, **kwargs)
860869

0 commit comments

Comments
 (0)