Skip to content

BUG: np.timedelta64 arithmetic appears buggy #4135

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 Jul 5, 2013 · 3 comments · Fixed by #4534
Closed

BUG: np.timedelta64 arithmetic appears buggy #4135

jreback opened this issue Jul 5, 2013 · 3 comments · Fixed by #4534
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Timedelta Timedelta data type
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Jul 5, 2013

Buggy timedelta arithmetic with np.timedelta64 in np 1.7.1

In [41]: s = Series([Timestamp('20130301'),Timestamp('20130228 23:00:00'),Timestamp('20130228 22:00:00'),Timestamp('20130228 21:00:00')])

In [42]: s
Out[42]: 
0   2013-03-01 00:00:00
1   2013-02-28 23:00:00
2   2013-02-28 22:00:00
3   2013-02-28 21:00:00
dtype: datetime64[ns]

In [43]: s + timedelta(hours=1)
Out[43]: 
0   2013-03-01 01:00:00
1   2013-03-01 00:00:00
2   2013-02-28 23:00:00
3   2013-02-28 22:00:00
dtype: datetime64[ns]

Should be the same as above

In [45]: s + np.timedelta64(1,'h')
Out[45]: 
0   2013-03-01 00:00:00.000000001
1   2013-02-28 23:00:00.000000001
2   2013-02-28 22:00:00.000000001
3   2013-02-28 21:00:00.000000001
dtype: datetime64[ns]
@cpcloud
Copy link
Member

cpcloud commented Jul 5, 2013

does pandas handle timedelta and timedelta64 differently?

In [12]: (s + timedelta(hours=1)).values
Out[12]:
array(['2013-02-28T20:00:00.000000000-0500',
       '2013-02-28T19:00:00.000000000-0500',
       '2013-02-28T18:00:00.000000000-0500',
       '2013-02-28T17:00:00.000000000-0500'], dtype='datetime64[ns]')

In [13]: (s + timedelta64(1, 'h')).values
Out[13]:
array(['2013-02-28T19:00:00.000000001-0500',
       '2013-02-28T18:00:00.000000001-0500',
       '2013-02-28T17:00:00.000000001-0500',
       '2013-02-28T16:00:00.000000001-0500'], dtype='datetime64[ns]')

In [14]: (s.values + timedelta64(1, 'h'))
Out[14]:
array(['2013-02-28T20:00:00.000000000-0500',
       '2013-02-28T19:00:00.000000000-0500',
       '2013-02-28T18:00:00.000000000-0500',
       '2013-02-28T17:00:00.000000000-0500'], dtype='datetime64[ns]')

@cpcloud
Copy link
Member

cpcloud commented Jul 5, 2013

things are not being converted to ns. i got this...

@jreback
Copy link
Contributor Author

jreback commented Aug 10, 2013

@cpcloud #4534 fixes the compat with 1.6 in a different way that I originally suggest to you

seem that
s.astype('O') + timedelta(...) when s is a timedelta64[ns] series works in 1.6 (and then is converted back to timedelta64[ns] when created

can you you rebase off of this and see if you tests work out? (also I think your compat checking (the _is_numpy_less_17) stuff.. is a bit cleaner than mine)....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Timedelta Timedelta data type
Projects
None yet
2 participants