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

Comparing DataFrame with columns with mixed types to a scalar should fail #20876

Closed
michcio1234 opened this issue Apr 30, 2018 · 2 comments
Closed

Comments

@michcio1234
Copy link

Code Sample, a copy-pastable example if possible

>>> s = pd.Series(['foo', 1])

>>> s > 1  # fails as expected
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mdank/anaconda3/envs/pd-mixed/lib/python3.6/site-packages/pandas/core/ops.py", line 879, in wrapper
    res = na_op(values, other)
  File "/home/mdank/anaconda3/envs/pd-mixed/lib/python3.6/site-packages/pandas/core/ops.py", line 783, in na_op
    result = _comp_method_OBJECT_ARRAY(op, x, y)
  File "/home/mdank/anaconda3/envs/pd-mixed/lib/python3.6/site-packages/pandas/core/ops.py", line 763, in _comp_method_OBJECT_ARRAY
    result = lib.scalar_compare(x, y, op)
  File "pandas/_libs/lib.pyx", line 706, in pandas._libs.lib.scalar_compare
TypeError: '>' not supported between instances of 'str' and 'int'

>>> s.to_frame() > 1  # should also fail, gives wrong result instead
      0
0  True
1  True

Problem description

String to int comparison doesn't fail when comparing a DataFrame. It fails when comparing Series with mixed types, but in case of DataFrame it just silently produces wrong result.

Expected Output

TypeError in both cases - Series and DataFrame.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-104-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: None
pip: 9.0.3
setuptools: 39.0.1
Cython: None
numpy: 1.14.2
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jbrockmendel
Copy link
Member

Closed by #22163.

@michcio1234
Copy link
Author

Thanks for fixing it!

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

No branches or pull requests

2 participants