Skip to content

divide does not work for Series of timedelta64[ns] #6050

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 Jan 23, 2014 · 3 comments
Closed

divide does not work for Series of timedelta64[ns] #6050

cancan101 opened this issue Jan 23, 2014 · 3 comments

Comments

@cancan101
Copy link
Contributor

Using this Series:

In [38]: pd.Series([timedelta(1)])

Out[38]:
0   1 days, 00:00:00
dtype: timedelta64[ns]

This works:

In [36]: pd.Series([timedelta(1)])[0]/ np.timedelta64(1,'D')

Out[36]:
1.0

But this does not:

In [39]:

pd.Series([timedelta(1)])/ np.timedelta64(1,'D')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-39-753422ac6b07> in <module>()
----> 1 pd.Series([timedelta(1)])/ np.timedelta64(1,'D')

/usr/lib64/python2.7/site-packages/pandas/core/series.py in wrapper(self, other, name)
    128                 elif is_timedelta_lhs and name not in ['__add__','__sub__']:
    129                     raise TypeError("can only operate on a timedeltas for "
--> 130                                     "addition and subtraction, but the operator [%s] was passed" % name)
    131 
    132                 dtype = 'timedelta64[ns]'

TypeError: can only operate on a timedeltas for addition and subtraction, but the operator [__div__] was passed
@jreback
Copy link
Contributor

jreback commented Jan 23, 2014

works on current master (fixed recently)

In [29]: pd.Series([timedelta(1)])[0]/ np.timedelta64(1,'D')
Out[29]: 1.0

In [30]: pd.Series([timedelta(1)])/ np.timedelta64(1,'D')
Out[30]: 
0    1
dtype: float64

@jreback jreback closed this as completed Jan 23, 2014
@jreback
Copy link
Contributor

jreback commented Jan 23, 2014

#5995

@jreback
Copy link
Contributor

jreback commented Jan 23, 2014

Note this difference (on purpose), see here: http://pandas.pydata.org/pandas-docs/dev/timeseries.html#time-deltas-conversions

In [31]: pd.Series([timedelta(days=1,seconds=10)])/ np.timedelta64(1,'D')
Out[31]: 
0    1.000116
dtype: float64

In [32]: pd.Series([timedelta(days=1,seconds=10)]).astype('timedelta64[D]')
Out[32]: 
0    1
dtype: float64

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

No branches or pull requests

2 participants