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: ValueError when printing a DataFrame's column having a DataFrame in its attrs #60568

Closed
3 tasks done
kaba439 opened this issue Dec 14, 2024 · 1 comment · Fixed by #60574
Closed
3 tasks done

BUG: ValueError when printing a DataFrame's column having a DataFrame in its attrs #60568

kaba439 opened this issue Dec 14, 2024 · 1 comment · Fixed by #60574
Labels
Bug metadata _metadata, .attrs

Comments

@kaba439
Copy link

kaba439 commented Dec 14, 2024

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

n=50

a = pd.DataFrame(np.random.randint(0, 10, size=(n,n)))
b = pd.DataFrame(np.random.randint(0, 10, size=(5,5)))

a.attrs['b'] = b

a[0]

Issue Description

same error as in #60455 (which was already solved for DataFrames by #60459) but here output is a Series

Expected Behavior

selected column is printed abbreviated form, no KeyError

Traceback (most recent call last): File "", line 1, in File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/core/series.py", line 1437, in __repr__ return self.to_string(**repr_params) File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/util/_decorators.py", line 332, in wrapper return func(*args, **kwargs) File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/core/series.py", line 1534, in to_string formatter = fmt.SeriesFormatter( File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/io/formats/format.py", line 226, in __init__ self._chk_truncate() File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/io/formats/format.py", line 248, in _chk_truncate series = concat((series.iloc[:row_num], series.iloc[-row_num:])) File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/core/reshape/concat.py", line 440, in concat return _get_result( File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/core/reshape/concat.py", line 547, in _get_result return result.__finalize__( File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/core/generic.py", line 6070, in __finalize__ have_same_attrs = all(obj.attrs == attrs for obj in objs[1:]) File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/core/generic.py", line 6070, in have_same_attrs = all(obj.attrs == attrs for obj in objs[1:]) File "/py/envs/pandas-dev/lib/python3.10/site-packages/pandas/core/generic.py", line 1496, in __bool__ raise ValueError( ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Installed Versions

INSTALLED VERSIONS ------------------ commit : 9501650 python : 3.10.16 python-bits : 64 OS : Linux OS-release : 6.11.10-2-MANJARO Version : #1 SMP PREEMPT_DYNAMIC Mon, 25 Nov 2024 05:29:44 +0000 machine : x86_64 processor : byteorder : little LC_ALL : None LANG : de_DE.UTF-8 LOCALE : de_DE.UTF-8

pandas : 0+untagged.1.g9501650
numpy : 1.26.4
dateutil : 2.9.0.post0
pip : 24.3.1
Cython : 3.0.11
sphinx : 8.1.3
IPython : 8.30.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : 1.4.2
fastparquet : 2024.11.0
fsspec : 2024.10.0
html5lib : 1.1
hypothesis : 6.122.3
gcsfs : 2024.10.0
jinja2 : 3.1.4
lxml.etree : 5.3.0
matplotlib : 3.9.4
numba : 0.60.0
numexpr : 2.10.2
odfpy : None
openpyxl : 3.1.5
psycopg2 : 2.9.9
pymysql : 1.4.6
pyarrow : 18.1.0
pyreadstat : 1.2.8
pytest : 8.3.4
python-calamine : None
pytz : 2024.2
pyxlsb : 1.0.10
s3fs : 2024.10.0
scipy : 1.14.1
sqlalchemy : 2.0.36
tables : 3.10.1
tabulate : 0.9.0
xarray : 2024.9.0
xlrd : 2.0.1
xlsxwriter : 3.2.0
zstandard : 0.23.0
tzdata : 2024.2
qtpy : None
pyqt5 : None

@kaba439 kaba439 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 14, 2024
@kaba439 kaba439 changed the title BUG: ValueError when printing a DataFrame's column having a DatFrame in its attrs BUG: ValueError when printing a DataFrame's column having a DataFrame in its attrs Dec 14, 2024
@yuanx749
Copy link
Contributor

Thank you for the report. I would also take this issue, using a similar fix.

@asishm asishm added metadata _metadata, .attrs and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug metadata _metadata, .attrs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants