Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cancan101 opened this issue Feb 20, 2014 · 14 comments · Fixed by #14799
Closed

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

cancan101 opened this issue Feb 20, 2014 · 14 comments · Fixed by #14799
Labels
Enhancement Timedelta Timedelta data type
Milestone

Comments

@cancan101
Copy link
Contributor

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
@jreback
Copy link
Contributor

jreback commented Feb 20, 2014

unless their is real interest, won't do this

@jreback jreback closed this as completed Feb 20, 2014
@cancan101
Copy link
Contributor Author

Can we leave this open then and mark as milestone "Someday"?

@jreback jreback added this to the Someday milestone Feb 20, 2014
@jreback jreback reopened this Feb 20, 2014
@hayd
Copy link
Contributor

hayd commented Dec 16, 2015

came up on SO http://stackoverflow.com/q/34315753/1240268

@rldleblanc
Copy link

Run into this today as well.

@vtselfa
Copy link

vtselfa commented May 2, 2016

I have also run into this today.

@TomAugspurger
Copy link
Contributor

If someone is interested in working on this, it'd follow a similar pattern to #14737 (convert to i8, interpolate, convert back to timedelta).

@aileronajay
Copy link
Contributor

@TomAugspurger i can take this up post #14737 :)

@aileronajay
Copy link
Contributor

aileronajay commented Dec 4, 2016

@TomAugspurger is this still an issue? when i run the code fragment given in the initial post of this issue, i get this output

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

@cancan101
Copy link
Contributor Author

cancan101 commented Dec 4, 2016

I filed this a long time ago, so bear with me. This does not seem to work:

pd.DataFrame({'v':[1,np.nan,5]},index=pd.to_timedelta([1,2,3], unit="d")).interpolate(method="time")

whereas this does:

pd.DataFrame({'v':[1,np.nan,5]},index=pd.to_datetime([1,2,3], unit="d")).interpolate(method="time")

I am seeing the same issue as in the above linked SO post.

@aileronajay
Copy link
Contributor

@cancan101 so it fails when we try to pass timedelta, is that correct?

@cancan101
Copy link
Contributor Author

What do you mean?
This line works fine:

pd.DataFrame({'v':[1,np.nan,5]},index=pd.to_timedelta([1,2,3], unit="d"))

@aileronajay
Copy link
Contributor

@cancan101 yes that is fine, what i am trying to say is that it fails when you try to interpolate the timedelta data,

pd.DataFrame({'v':[1,np.nan,5]},index=pd.to_timedelta([1,2,3], unit="d")).interpolate(method="time")

whereas when you call interpolate for datetime data, it works. That is the difference between the two lines that you've posted earlier (as examples of what works and what doesnt), right?

@cancan101
Copy link
Contributor Author

yes

@aileronajay
Copy link
Contributor

added this PR, #14799

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants