Comparison to string is broken for nullable int · Issue #28930 · pandas-dev/pandas (original) (raw)
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