Skip to content

Comparison to string is broken for nullable int #28930

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
stolpovsky opened this issue Oct 11, 2019 · 0 comments · Fixed by #28945
Closed

Comparison to string is broken for nullable int #28930

stolpovsky opened this issue Oct 11, 2019 · 0 comments · Fixed by #28945
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@stolpovsky
Copy link

stolpovsky commented Oct 11, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({'x': [1, None]})
df.x.astype(pd.Int64Dtype()) == 'a'

Problem description

The above raises TypeError on line 627 in integer.py:

result[mask] = op_name == "ne"

Here, the result is bool. Here is the exception:

Traceback (most recent call last):
File "", line 1, in
File "C:\Python37\lib\site-packages\pandas\core\ops.py", line 1731, in wrapper
return dispatch_to_extension_op(op, self, other)
File "C:\Python37\lib\site-packages\pandas\core\ops.py", line 1220, in dispatch_to_extension_op
res_values = op(new_left, new_right)
File "C:\Python37\lib\site-packages\pandas\core\arrays\integer.py", line 564, in cmp_method
result[mask] = True if op_name == 'ne' else False
TypeError: 'bool' object does not support item assignment

The above works as expected for float64 and other numeric types.

Expected Output

0 False
1 False
Name: x, dtype: bool

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.0.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 0.25.1
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.2.3
setuptools : 39.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.3.4
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.3.4
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.0
sqlalchemy : 1.3.5
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@jreback jreback added Compat pandas objects compatability with Numpy or Python functions ExtensionArray Extending pandas with custom dtypes or arrays. labels Oct 16, 2019
@jreback jreback added this to the 1.0 milestone Oct 16, 2019
@jbrockmendel jbrockmendel added the Numeric Operations Arithmetic, Comparison, and Logical operations label Oct 16, 2019
@jorisvandenbossche jorisvandenbossche removed the Compat pandas objects compatability with Numpy or Python functions label Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants