Skip to content

BUG: loc setitem fails with shape mismatch #51450

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
sam-infinity opened this issue Feb 17, 2023 · 1 comment · Fixed by #51585
Closed
3 tasks done

BUG: loc setitem fails with shape mismatch #51450

sam-infinity opened this issue Feb 17, 2023 · 1 comment · Fixed by #51585
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

@sam-infinity
Copy link

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

df = pd.DataFrame({
    "A": [],
    "B": []
}).astype('str')

df.loc[df['A'].str.contains('STUFF'), ['A']] = df['A'] + '-' + df['B']

Issue Description

In versions 1.5+ this errors with ValueError: shape mismatch: value array of shape (0,) could not be broadcast to indexing result of shape (0,1)

Expected Behavior

In pre 1.5 this behaved as a no-op.

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.9.7.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Mon Dec 19 20:44:01 PST 2022; root:xnu-8020.240.18~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 57.4.0
pip : 21.2.3
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
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@sam-infinity sam-infinity added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 17, 2023
@simonjayhawkins simonjayhawkins added the Regression Functionality that used to work in a prior pandas version label Feb 23, 2023
@phofl
Copy link
Member

phofl commented Feb 23, 2023

yep regression on 1.5, fixing is easier on 2.0 since we changed logic since then

@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 23, 2023
@phofl phofl added this to the 2.0 milestone Feb 23, 2023
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