Skip to content
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

BUG: Cannot use .loc to set a ndarray as the value of an empty dataframe #49972

Open
2 of 3 tasks
LouisLU9911 opened this issue Nov 30, 2022 · 1 comment
Open
2 of 3 tasks
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@LouisLU9911
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
import numpy as np
result = pd.DataFrame()
result.loc[0, 0] = np.asarray([0])     # This assignment statement will raise an IndexError

Issue Description

  • This error occurs when I want to upgrade my pandas==1.1.5 to a higher version, including the newest one(pandas==1.5.2).
  • Cannot use result.loc[0, 0] = np.asarray([0]) to set a ndarray as the value of an empty dataframe
  • I try to figure out what's wrong with it by myself, but I am not familiar with pandas's internal. Maybe BUG: Adding Series to empty DataFrame can reset dtype to float64 #42099 has changed the indexing behavior for a ndarray.
  • Finally, I am not sure whether it is a bug or not. 😂

Expected Behavior

  • The assignment statement will not raise an IndexError and set the value correctly and successfully.

Expected Output (When I use pandas==1.1.5):

...
>>> result.loc[0, 0] = np.asarray([0])
>>> print(result)
     0
0  0.0

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.8.11.final.0
python-bits : 64
OS : Darwin
OS-release : 20.3.0
Version : Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 1.5.2
numpy : 1.23.5
pytz : 2022.6
dateutil : 2.8.2
setuptools : 57.0.0
pip : 21.1.3
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 1.0.2
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
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 : 0.8.10
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@LouisLU9911 LouisLU9911 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 30, 2022
@jbrockmendel jbrockmendel added Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). and removed Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). labels Nov 30, 2022
@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 Dec 5, 2022
@LouisLU9911
Copy link
Author

Any update on this? #50065 seems to have made some progress. 😃

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

Successfully merging a pull request may close this issue.

3 participants