Skip to content

BUG: numpy bug in np.abs on timedelta64 #2957

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
jreback opened this issue Mar 1, 2013 · 1 comment
Closed

BUG: numpy bug in np.abs on timedelta64 #2957

jreback opened this issue Mar 1, 2013 · 1 comment
Labels
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Mar 1, 2013

This is a very subtle bug in how np.abs operates on timedelta64[ns]
It converts them to us for some reason on numpy <= 1.6.2. (maybe numpy 1.7 is better)
workaround is to wrap in a Series and astype

tricky to fix this because we really can't detect is except in finalize, but then
have to check all return dtypes from the operations.....

exhibited also in #2948

In [23]: s1 = pd.Series(pd.date_range('20120101',periods=3))

In [24]: s2 = pd.Series(pd.date_range('20120102',periods=3))

In [27]: s1-s2
Out[27]: 
0   -1 days, 00:00:00
1   -1 days, 00:00:00
2   -1 days, 00:00:00
Dtype: timedelta64[ns]

#### notice this is timedelta64[us] and not ns!
In [28]: np.abs(s1-s2)
Out[28]: 
0   1 days, 00:00:00
1   1 days, 00:00:00
2   1 days, 00:00:00
Dtype: timedelta64[us]

# workaround
In [30]: pd.Series(np.abs(s1-s2)).astype('timedelta64[ns]')
Out[30]: 
0   1 days, 00:00:00
1   1 days, 00:00:00
2   1 days, 00:00:00
Dtype: timedelta64[ns]

@jreback
Copy link
Contributor Author

jreback commented Mar 6, 2013

going to close this....but handling timedelta64[ns] in general is still somewhat of an issue with generic numpy functions....

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

No branches or pull requests

1 participant