Skip to content

BUG: setting with loc breaks in 1.4.0 when indexing using an all-False boolean series #45778

New issue

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

Closed
3 tasks done
kroche98 opened this issue Feb 2, 2022 · 1 comment · Fixed by #45784
Closed
3 tasks done
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@kroche98
Copy link

kroche98 commented Feb 2, 2022

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

@kroche98 kroche98 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 2, 2022
@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 2, 2022
@phofl phofl added this to the 1.4.1 milestone Feb 2, 2022
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Feb 7, 2022
@simonjayhawkins
Copy link
Member

first bad commit: [776857a] BUG: Fix bug in loc setitem changing the dtype when condition is False (#37672)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants