Skip to content

BUG?: div method with timedelta #9396

Closed
@TomAugspurger

Description

@TomAugspurger

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions