ENH: Support logical and/or (bitwise ops) for nullable IntegerArray · Issue #34463 · pandas-dev/pandas (original) (raw)
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- (optional) I have confirmed this bug exists on the master branch of pandas: cc6348
Logical and/or (&
, |
) on integer Series returns an integer Series:
>>> import pandas as pd
>>> df = pd.DataFrame({'A': [1, 1, 0, 0], 'B': [1, 0, 1, 0]})
>>> df.A & df.B
0 1
1 0
2 0
3 0
dtype: int64
Doing this for a nullable IntegerArray, I expect the result to be another IntegerArray, but it raises a TypeError:
>>> df.A.astype('Int64') & df.B.astype('Int64')
Traceback
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "(snip)/pandas/core/ops/common.py", line 65, in new_method
return method(self, other)
File "(snip)/pandas/core/ops/__init__.py", line 393, in wrapper
res_values = logical_op(lvalues, rvalues, op)
File "(snip)/pandas/core/ops/array_ops.py", line 336, in logical_op
res_values = op(lvalues, rvalues)
TypeError: unsupported operand type(s) for &: 'IntegerArray' and 'IntegerArray'
Output of pd.show_versions()
INSTALLED VERSIONS
commit : cc63484
python : 3.7.7.final.0
python-bits : 64
OS : Darwin
OS-release : 19.4.0
Version : Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.0.dev0+1710.gcc634842a
numpy : 1.18.4
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 41.2.0
Cython : 0.29.19
pytest : 5.4.2
hypothesis : 5.16.0
sphinx : 3.0.4
blosc : 1.9.1
feather : None
xlsxwriter : 1.2.8
lxml.etree : 4.5.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.14.0
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.3.2
fastparquet : 0.4.0
gcsfs : None
matplotlib : 3.2.1
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : 0.17.1
pytables : None
pyxlsb : None
s3fs : 0.4.2
scipy : 1.4.1
sqlalchemy : 1.3.17
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.15.1
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.49.1