We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
This does not work:
>>> import pandas as pd >>> index = pd.MultiIndex.from_arrays([['a', 'a', 'b'], ['c', 'd', 'e']], names=['level1', 'level2']) >>> test = pd.DataFrame([[1, 2],[3, 4],[5, 6]], index=index, dtype=pd.UInt32Dtype()) >>> column_sums = test.sum(level='level1') >>> to_remove = column_sums < 100 >>> test.mask(to_remove, inplace=True, level='level1', axis=0, other=pd.NA) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "./site-packages/pandas/core/generic.py", line 9034, in mask return self.where( File "./site-packages/pandas/core/generic.py", line 9004, in where return self._where( File "./site-packages/pandas/core/generic.py", line 8854, in _where new_data = self._mgr.putmask( File "./site-packages/pandas/core/internals/managers.py", line 547, in putmask return self.apply( File "./site-packages/pandas/core/internals/managers.py", line 406, in apply applied = getattr(b, f)(**kwargs) File "./site-packages/pandas/core/internals/blocks.py", line 1606, in putmask mask = _extract_bool_array(mask) File "./site-packages/pandas/core/internals/blocks.py", line 2869, in _extract_bool_array assert mask.dtype == bool, mask.dtype AssertionError: object
This does work:
>>> import pandas as pd >>> index = pd.MultiIndex.from_arrays([['a', 'a', 'b'], ['c', 'd', 'e']], names=['level1', 'level2']) >>> test = pd.DataFrame([[1, 2],[3, 4],[5, 6]], index=index, dtype=pd.UInt32Dtype()) >>> column_sums = test.sum(level='level1') >>> to_remove = (column_sums < 100).astype(bool) >>> test.mask(to_remove, inplace=True, level='level1', axis=0, other=pd.NA) >>> test.info() <class 'pandas.core.frame.DataFrame'> MultiIndex: 3 entries, ('a', 'c') to ('b', 'e') Data columns (total 2 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 0 0 non-null UInt32 1 1 0 non-null UInt32 dtypes: UInt32(2) memory usage: 346.0+ bytes
Using mask() or where() with the BooleanDtype as condition raises an AssertionError.
mask() and where() should work with both the bool and the pandas.core.arrays.boolean.BooleanDtype dtype.
pd.show_versions()
commit : db08276 python : 3.8.5.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-42-generic Version : #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 1.1.3 numpy : 1.19.2 pytz : 2020.1 dateutil : 2.8.1 pip : 20.0.2 setuptools : 44.0.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None fsspec : None fastparquet : None gcsfs : None matplotlib : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pytables : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None numba : None
The text was updated successfully, but these errors were encountered:
Thanks for reporting. I think this is a duplicate of #35429 and #36395. Let me know if not.
Sorry, something went wrong.
@TomAugspurger I seem to have missed those. Thanks!
No branches or pull requests
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
This does not work:
This does work:
Problem description
Using mask() or where() with the BooleanDtype as condition raises an AssertionError.
Expected Output
mask() and where() should work with both the bool and the pandas.core.arrays.boolean.BooleanDtype dtype.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : db08276
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-42-generic
Version : #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 44.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: