BUG: setting with loc breaks in 1.4.0 when indexing using an all-False boolean series · Issue #45778 · pandas-dev/pandas (original) (raw)
Pandas version checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd foo = pd.Series([1,2,3,4,5], index=['a','b','c','d','e']) bar = pd.Series([6,7,8,9,10], index=['a','b','c','d','e'])
works in 1.3 and 1.4
foo.loc[foo>2] = bar
works in 1.3 but breaks in 1.4
foo.loc[foo>100] = bar
Issue Description
The above code works fine in pandas 1.3.5, with foo.loc[foo>100] = bar
having no effect on foo
, as desired. (You can imagine that this code is run on many different values of foo
, where some of them have values greater than 100 and some don't.)
Now in pandas 1.4.0, foo.loc[foo>100] = bar
fails with the error:ValueError: cannot set using a list-like indexer with a different length than the value
Perhaps this is a deliberate change in 1.4.0? If so, I cannot find any reference to the new behavior in the release notes. The old behavior (no change to the dataframe) seems very sensible to me.
Expected Behavior
The code should not produce an error but should instead have no effect on the dataframe.
Installed Versions
INSTALLED VERSIONS
commit : bb1f651
python : 3.8.12.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United States.1252
pandas : 1.4.0
numpy : 1.20.3
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.2
setuptools : 58.0.4
Cython : 0.29.25
pytest : 6.2.4
hypothesis : None
sphinx : 4.4.0
blosc : None
feather : None
xlsxwriter : 3.0.2
lxml.etree : 4.7.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.29.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fastparquet : None
gcsfs : None
matplotlib : 3.5.0
numba : 0.54.1
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.27
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
zstandard : None