BUG: Unexpected IndexingError when filtering with .loc · Issue #46551 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@bikoboshi

Description

@bikoboshi

Pandas version checks

Reproducible Example

a = pd.Series([True, False]) b = pd.Series([np.nan, False]).astype('boolean') s = pd.Series([1,2]) s.loc[a].loc[b] ... pandas.core.indexing.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).

Issue Description

The example throws an unexpected indexing error. The error seems to trigger if the first filter is neither the identity nor empty and when combined with the second filter with nan is empty. The error does not seem to trigger otherwise.

Expected Behavior

I expect this identity to hold s.loc[a].loc[b] == s.loc[b].loc[a] == s.loc[a & b] which it does except for the exception above.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 66e3805python : 3.7.2.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.22000 machine : AMD64 processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : None.None

pandas : 1.3.5
numpy : 1.17.4
pytz : 2019.1
dateutil : 2.8.0
pip : 21.2.4
setuptools : 46.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 : 2.10
IPython : 7.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.5
tables : None
tabulate : 0.8.3
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None