BUG: IndexError: positional indexers are out-of-bounds iloc boolean indexing (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.
Code Sample, a copy-pastable example
import pandas as pd df = pd.DataFrame([[0, 1, 2]], columns=['a', 'b', 'c']) mask = pd.DataFrame([[False, True, False]], columns=['a', 'b', 'c']) df.iloc[mask] = 3 # Works fine with assignment print(df.iloc[mask]) # Throws IndexError, but should give similar result as df.values[mask]
Problem description
Documentation of Pandas says I can use boolean array with iloc. The iloc call with the assignment works fine, but without assignment fails. Just as a note here: In pandas 1.0.1 not even the assignment works (it starts working again if there are more than 1 rows of data).
Expected Output
3 (similar as df.values[mask])
Output of pd.show_versions()
DetailsINSTALLED VERSIONS ------------------ commit : 3e89b4cpython : 3.8.5.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-58-generic Version : #64-Ubuntu SMP Wed Dec 9 08:16:25 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.2.0 numpy : 1.18.4 pytz : 2019.3 dateutil : 2.7.3 pip : 20.2 setuptools : 46.2.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 4.5.0 html5lib : 1.0.1 pymysql : None psycopg2 : 2.8.5 (dt dec pq3 ext lo64) jinja2 : 2.11.2 IPython : 7.19.0 pandas_datareader: None bs4 : 4.8.2 bottleneck : None fsspec : 0.7.3 fastparquet : None gcsfs : None matplotlib : 3.2.1 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyxlsb : None s3fs : None scipy : 1.4.1 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : 1.2.0 xlwt : None numba : 0.49.1