Skip to content

interpolate w/ method=time does not work with timedeltas #6424

Closed
@cancan101

Description

@cancan101
In [98]: pd.DataFrame({'v':[1,2,3]},index=pd.to_timedelta([1,2,3], unit="d")).interpolate(method="time")

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-98-9c399944f329> in <module>()
----> 1 pd.DataFrame({'v':[1,2,3]},index=pd.to_timedelta([1,2,3], unit="d")).interpolate(method="time")

/usr/lib64/python2.7/site-packages/pandas/core/generic.py in interpolate(self, method, axis, limit, inplace, downcast, **kwargs)
   2530                                           inplace=inplace,
   2531                                           downcast=downcast,
-> 2532                                           **kwargs)
   2533 
   2534         if inplace:

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in interpolate(self, *args, **kwargs)
   2402 
   2403     def interpolate(self, *args, **kwargs):
-> 2404         return self.apply('interpolate', *args, **kwargs)
   2405 
   2406     def shift(self, *args, **kwargs):

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in apply(self, f, *args, **kwargs)
   2373 
   2374             else:
-> 2375                 applied = getattr(blk, f)(*args, **kwargs)
   2376 
   2377             if isinstance(applied, list):

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in interpolate(self, method, axis, index, values, inplace, limit, fill_value, coerce, downcast, **kwargs)
    819                                      inplace=inplace,
    820                                      downcast=downcast,
--> 821                                      **kwargs)
    822 
    823         raise ValueError("invalid method '{0}' to interpolate.".format(method))

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in _interpolate(self, method, index, values, fill_value, axis, limit, inplace, downcast, **kwargs)
    880 
    881         # interp each column independently
--> 882         interp_values = np.apply_along_axis(func, axis, data)
    883 
    884         blocks = [make_block(interp_values, self.items, self.ref_items,

/usr/lib64/python2.7/site-packages/numpy/lib/shape_base.pyc in apply_along_axis(func1d, axis, arr, *args)
     77     outshape = asarray(arr.shape).take(indlist)
     78     i.put(indlist, ind)
---> 79     res = func1d(arr[tuple(i.tolist())],*args)
     80     #  if res is a number, then we have a smaller output array
     81     if isscalar(res):

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in func(x)
    877             return com.interpolate_1d(index, x, method=method, limit=limit,
    878                                       fill_value=fill_value,
--> 879                                       bounds_error=False, **kwargs)
    880 
    881         # interp each column independently

/usr/lib64/python2.7/site-packages/pandas/core/common.py in interpolate_1d(xvalues, yvalues, method, limit, fill_value, bounds_error, **kwargs)
   1362         if not getattr(xvalues, 'is_all_dates', None):
   1363         # if not issubclass(xvalues.dtype.type, np.datetime64):
-> 1364             raise ValueError('time-weighted interpolation only works '
   1365                              'on Series or DataFrames with a '
   1366                              'DatetimeIndex')

ValueError: time-weighted interpolation only works on Series or DataFrames with a DatetimeIndex

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions