Skip to content

BUG: empty slice assignment raises if datetime column is present #50942

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

Open
3 tasks done
christopherdoyle opened this issue Jan 23, 2023 · 1 comment
Open
3 tasks done
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@christopherdoyle
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
# works
df = pd.DataFrame({"A": [1, 1]})
df.loc[[False, False]] = df
# raises
df = pd.DataFrame({"X": [pd.Timestamp(2023, 1, 1)] * 2})
df.loc[[False, False]] = df

Issue Description

If the dataframe contains a datetime or timedelta column, whether there are other coulmns present or not, it will raise:

ValueError: shape mismatch: value array of shape (2,) could not be broadcast to indexing result of shape (0,)

This does not happen when there is only one row, or when there are no datetime or timedelta columns. Object dtype is also fine, even if the values are timestamps.

On the nightly build we hit an infinite recursion instead of a ValueError.

Possibly related #45981.

Expected Behavior

This should not raise and it should be a no-op:

df = pd.DataFrame({"X": [pd.Timestamp(2023, 1, 1)] * 2})
df.loc[[False, False]] = df

Installed Versions

INSTALLED VERSIONS ------------------ commit : 2e218d1 python : 3.11.1.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19044 machine : AMD64 processor : AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD byteorder : little LC_ALL : None LANG : None LOCALE : English_United States.1252

pandas : 1.5.3
numpy : 1.24.1
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3.1
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

@christopherdoyle christopherdoyle added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 23, 2023
@topper-123 topper-123 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 May 6, 2023
@topper-123
Copy link
Contributor

This works in the main branch, so I'm closing. I don't know when or how this was fixed, which is annoying, but if you see anything here not working as expected, feel free to reopen.

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
Projects
None yet
Development

No branches or pull requests

2 participants