Skip to content

scalar subtraction doesn't work on Series with dtype datetime64 #2945

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
changhiskhan opened this issue Feb 27, 2013 · 3 comments
Closed

scalar subtraction doesn't work on Series with dtype datetime64 #2945

changhiskhan opened this issue Feb 27, 2013 · 3 comments
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@changhiskhan
Copy link
Contributor

In [34]: df
Out[34]:
0 1 time
0 -0.602181 -0.657444 2009-07-01 00:00:00
1 -2.102987 -0.486064 2009-07-02 00:00:00
2 0.819956 -0.800478 2009-07-03 00:00:00
3 1.118629 -0.008019 2009-07-04 00:00:00
4 0.404452 0.606187 2009-07-05 00:00:00

In [35]: df.time.dtype
Out[35]: dtype('datetime64[ns]')

In [36]: image_time
Out[36]: datetime.datetime(2009, 7, 28, 13, 39, 2)

In [37]: df.time - image_time

ValueError Traceback (most recent call last)
in ()
----> 1 df.time - image_time

/Users/changshe/code/pandas/pandas/core/series.pyc in wrapper(self, other)
94 dtype = 'timedelta64[ns]'
95 else:
---> 96 raise ValueError("cannot operate on a series with out a rhs of a series/ndarray of type datetime64[ns] or a timedelta")
97
98 lvalues = lvalues.view('i8')

ValueError: cannot operate on a series with out a rhs of a series/ndarray of type datetime64[ns] or a timedelta

@jreback
Copy link
Contributor

jreback commented Feb 27, 2013

works on master for me

(Pdb) df
                    A         D         F
0 2012-01-01 00:00:00  0.580460  0.634610
1 2012-01-02 00:00:00  0.920764  0.830067
2 2012-01-03 00:00:00  0.984371  0.386249
(Pdb) df.dtypes
A    datetime64[ns]
D           float64
F           float64
Dtype: object
(Pdb) df['A'] - datetime(2009,7,28,13,39,2)
0   886 days, 10:20:58
1   887 days, 10:20:58
2   888 days, 10:20:58
Name: A, Dtype: timedelta64[ns]

@jreback
Copy link
Contributor

jreback commented Feb 27, 2013

almost certain you have older code there the error is on line 131 (and the prior lines look different)....this was recently fixed in PR #2899

@changhiskhan
Copy link
Contributor Author

Yeah, that was it. Oops. False alarm

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

No branches or pull requests

2 participants