Skip to content

Inconsistent Series/scalar comparison behavior based upon the scalar's type #10363

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
naftaliharris opened this issue Jun 15, 2015 · 4 comments
Closed
Labels

Comments

@naftaliharris
Copy link

It's pretty unexpected that the behavior of x <= pd.Series(...) depends on whether x is a python float or a np.float64:

>>> import pandas as pd
>>> import numpy as np
>>> 5 <= pd.Series(range(10))
0    False
1    False
2    False
3    False
4    False
5     True
6     True
7     True
8     True
9     True
dtype: bool
>>> np.float64(5) <= pd.Series(range(10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pandas/core/ops.py", line 588, in wrapper
    if len(self) != len(other):
TypeError: len() of unsized object
>>> pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.2.0-54-virtual
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.16.2
nose: 1.3.3
Cython: None
numpy: 1.9.2
scipy: 0.14.0
statsmodels: 0.5.0
IPython: 0.12.1
sphinx: None
patsy: 0.3.0
dateutil: 2.2
pytz: 2014.4
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.3.1
openpyxl: 1.8.6
xlrd: 0.9.3
xlwt: None
xlsxwriter: None
lxml: 3.3.2
bs4: None
html5lib: None
httplib2: 0.7.2
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: 2.5.2 (dt dec pq3 ext)
>>>
@naftaliharris
Copy link
Author

Note that the issue isn't present on the other side:

>>> pd.Series(range(10)) >= 5
0    False
1    False
2    False
3    False
4    False
5     True
6     True
7     True
8     True
9     True
dtype: bool
>>> pd.Series(range(10)) >= np.float64(5)
0    False
1    False
2    False
3    False
4    False
5     True
6     True
7     True
8     True
9     True
dtype: bool

Apologies if this is a duplicate!

@shoyer shoyer added the Bug label Jun 15, 2015
@shoyer
Copy link
Member

shoyer commented Jun 15, 2015

I can replicate this on 0.16.2 This definitely looks like a bug to me -- I guess we just didn't have test coverage for this.

@jreback
Copy link
Contributor

jreback commented Jun 15, 2015

dupe of #9369 thanks for the report though!

@jreback jreback closed this as completed Jun 15, 2015
@naftaliharris
Copy link
Author

Excellent, thanks!

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

3 participants