-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG (Regression): Using a tuple as first column name in empty dataframe creates a non functional dataframe and memory errors #54385
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
Comments
This seems to be a regression. |
I also experienced it. import pandas as pd
df = pd.DataFrame([1, 2, 3])
df[0, 0] = 4 if you will try to print this dataframe it will fail with this error
But if you set another index import pandas as pd
df = pd.DataFrame([1, 2, 3])
df[1, 0] = 4 print will fail with another exception
What is really important here, that exception does not occur while setting values, but only while working with the dataframe. |
I get the same ValueError in both cases using python 3.9. It seems that the double index is split into 2 columns while only having values for 1. This results in ValueErrors when trying to print the dataframe with undefined values. Your second example ( |
The bug still exists in the latest python and pandas release. Especially the memory errors seem concerning. |
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
Issue Description
A dataframe becomes completely unusable when the first column was assigned using a tuple as key. (example df1)
The tuple gets transformed in 2 different columns while data for only one is given. This cause print statements to return "ValueError: Length of values (1) does not match length of index (2)".
When a dataframe already has an existing column (example df2) the assignment works as expected.
Running the assignment on the df1 dataframe 5 times results in a wide range of memory related errors such as:
malloc(): unaligned tcache chunk detected
IndexError: index 94573497622112 is out of bounds for axis 0 with size 5
corrupted size vs. prev_size
double free or corruption (out)
Expected Behavior
The assignment should behave the same in both examples and use the tuple as single header.
Installed Versions
INSTALLED VERSIONS
commit : 0f43794
python : 3.10.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.19.0-50-generic
Version : #50-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul 10 18:24:29 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.3
numpy : 1.25.1
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.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 : 3.1.2
IPython : 8.14.0
pandas_datareader: None
bs4 : 4.12.2
bottleneck : None
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.3.1
pyqt5 : None
The text was updated successfully, but these errors were encountered: