Skip to content

BUG?: div method with timedelta #9396

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
TomAugspurger opened this issue Feb 2, 2015 · 1 comment · Fixed by #14906
Closed

BUG?: div method with timedelta #9396

TomAugspurger opened this issue Feb 2, 2015 · 1 comment · Fixed by #14906
Milestone

Comments

@TomAugspurger
Copy link
Contributor

Not sure if this is a bug or not.

import datetime

In [24]: s = pd.Series(pd.to_datetime(['2015-01-01', '2015-02-02']))

In [25]: s
Out[25]:
0   2015-01-01
1   2015-02-02
dtype: datetime64[ns]

In [26]: s.diff() / datetime.timedelta(1)
Out[26]:
0   NaN
1    32
dtype: float64

In [27]: s.diff().div(datetime.timedelta(1))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-1197779902ae> in <module>()
----> 1 s.diff().div(datetime.timedelta(1))

C:\Miniconda\lib\site-packages\pandas\core\ops.pyc in flex_wrapper(self, other,
level, fill_value, axis)
    716                                level=level, fill_value=fill_value)
    717         else:
--> 718             return self._constructor(op(self.values, other),
    719                                      self.index).__finalize__(self)
    720

TypeError: ufunc true_divide cannot use operands with types dtype('<m8[ns]') and
 dtype('O')

Works with our Timedelta though, as suggested by the error message:

In [28]: s.diff().div(pd.Timedelta(1, unit='D'))
Out[28]:
0   NaN
1    32
dtype: float64

It at least seems strange that / worked while .div didn't.

This is the released 0.15.2, and python 2.

@jreback
Copy link
Contributor

jreback commented Feb 3, 2015

you can mark this as a bug / enhancement
timedelta generally need wrapping internally in TimeDelta in order to work

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

Successfully merging a pull request may close this issue.

2 participants