Skip to content
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

eq and ne not consistent with other comparison operators #4968

Closed
cpcloud opened this issue Sep 24, 2013 · 3 comments · Fixed by #4970
Closed

eq and ne not consistent with other comparison operators #4968

cpcloud opened this issue Sep 24, 2013 · 3 comments · Fixed by #4970
Labels
Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@cpcloud
Copy link
Member

cpcloud commented Sep 24, 2013

works

In [1]: df = DataFrame(randint(10, size=(10, 1)), columns=['a'])

In [2]: df['dates'] = date_range('20010101', periods=len(df))

In [3]: df.a == df.dates
Out[3]:
0    False
1    False
2    False
3    False
4    False
5    False
6    False
7    False
8    False
9    False
dtype: bool

doesn't work:

In [4]: df.a <= df.dates
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-74e89260dea7> in <module>()
----> 1 df.a <= df.dates

/home/phillip/Documents/code/py/pandas/pandas/core/series.pyc in wrapper(self, other)
    336             if len(self) != len(other):
    337                 raise ValueError('Series lengths must match to compare')
--> 338             return self._constructor(na_op(self.values, other.values),
    339                                      index=self.index, name=name)
    340         elif isinstance(other, DataFrame):  # pragma: no cover

/home/phillip/Documents/code/py/pandas/pandas/core/series.pyc in na_op(x, y)
    325                 result = lib.scalar_compare(x, y, op)
    326         else:
--> 327             result = op(x, y)
    328
    329         return result

TypeError: invalid type promotion
@jtratner
Copy link
Contributor

It's a general issue with datetime comparison to integers not being consistent. Further, == is not at all the same as <=. <= implies ordering, whereas == implies 'is the object at this position the same as the object at this other position'. earlier @jreback and I were considering an idea where we would limit boolean comparisons (except for ==) to objects of the same type.

For example, what would you expect for 1 <= date(2011, 01, 5)?

@cpcloud
Copy link
Member Author

cpcloud commented Sep 24, 2013

@jtratner All of those things are why I raised this issue.

@jtratner
Copy link
Contributor

Got it, guess I wasn't clear earlier.

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