Skip to content

Inconsistent comparison between datetime and series of datetime #3428

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
hemflit opened this issue Apr 23, 2013 · 4 comments
Closed

Inconsistent comparison between datetime and series of datetime #3428

hemflit opened this issue Apr 23, 2013 · 4 comments
Assignees
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@hemflit
Copy link

hemflit commented Apr 23, 2013

similar to #3416 (also failing in 0.11)

Using pandas 0.10.1 and numpy 1.6.1:

>>> import pandas; import numpy
>>> s = pandas.Series(pandas.date_range('2013-01-01', periods=3))
>>> d = numpy.datetime64('2013-01-02')
>>> s > d
0    False
1    False
2     True
>>> d < s
0    True
1    True
2    True
>>> s.dtype
dtype('datetime64[ns]')
>>> d.dtype
dtype('datetime64[us]')

All other comparison operators also give expected results with operands (s,d), and seem to compare them as unscaled integers when the order is (d,s).

@ghost ghost assigned jreback Apr 23, 2013
@jreback
Copy link
Contributor

jreback commented Apr 23, 2013

thanks for the report, this fails in 0.11 as well, for now use use a datetime object instead

@hemflit
Copy link
Author

hemflit commented Apr 23, 2013

Thanks.

For completeness, at least in 0.10.1, a datetime.datetime as the left operand triggers a "TypeError: can't compare datetime.datetime to Series". (Still definitely preferable to the numpy.datetime64 treatment.)

I guess the workaround for the moment is to convert to datetime.datetime and reorder operands.

@jreback
Copy link
Contributor

jreback commented Apr 30, 2013

This will have to wait till 0.12 (I just tried to fix this), because of the way python tried to do reverse comparison operators.....

@jreback
Copy link
Contributor

jreback commented Aug 24, 2013

@hemflit

This actually does work in 0.12 and numpy 1.7.

but the semantics are weird here anyhow

you are comparing a scalar (like) on the lhs with a Series on the rhs

and that's why I can't intercept it

so just reverse the comparison

closing as unfixable/not-a-bug

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
Projects
None yet
Development

No branches or pull requests

2 participants