Skip to content

[BUG] NumPy timedelta64 order of magnitude not changed during date operations #4865

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
dmvianna opened this issue Sep 18, 2013 · 2 comments
Closed

Comments

@dmvianna
Copy link

It seems that whatever the unit of time used in timedelta64 (day, week, hour, year), when operating with a datetime64[ns] value, the timedelta integer is operated as nanosecond. Hence, if we intend to add or subtract one week (or day, or hour, or year), only one nanosecond is subtracted instead.

In [7]: import numpy as np

In [8]: import pandas as pd

In [9]: from pandas import Series

In [10]: a = np.timedelta64(1, 'W')

In [11]: a
Out[11]: numpy.timedelta64(1,'W')

In [12]: b = Series(pd.to_datetime('1/1/2010'))

In [13]: b
Out[13]:
0   2010-01-01 00:00:00
dtype: datetime64[ns]

In [14]: b - a
Out[14]:
0   2009-12-31 23:59:59.999999999
dtype: datetime64[ns]

In [15]: pd.__version__, np.__version__
Out[15]: ('0.12.0', '1.7.1')
@hayd
Copy link
Contributor

hayd commented Sep 18, 2013

I think this will be fixed in 0.13 (as it appears to be working in current master):

In [7]: b - a
Out[7]:
0   2009-12-25 00:00:00
dtype: datetime64[ns]

@jreback
Copy link
Contributor

jreback commented Sep 18, 2013

not the exact fix #4534, but timedelta support is much improved in master/0.13

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

3 participants