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 with DataFrame in its attrs #60459

Merged
merged 9 commits into from
Dec 3, 2024

Conversation

yuanx749
Copy link
Contributor

@yuanx749 yuanx749 commented Dec 1, 2024

This PR replaces concat with slice in _truncate_horizontally as in _truncate_vertically to avoid the ValueError.

_len = len(self.tr_frame)
_slice = np.hstack([np.arange(row_num), np.arange(_len - row_num, _len)])
self.tr_frame = self.tr_frame.iloc[_slice]

@yuanx749 yuanx749 marked this pull request as draft December 1, 2024 11:29
@yuanx749 yuanx749 marked this pull request as ready for review December 1, 2024 12:37
@yuanx749
Copy link
Contributor Author

yuanx749 commented Dec 1, 2024

Hmm, I don't understand why there is a mypy error after this change:
pandas/io/formats/string.py:82: error: Cannot determine type of "tr_col_num" [has-type]

I don't get this error locally.

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could you add a whatsnew entry in v3.0.0.rst?

@mroeschke mroeschke added Output-Formatting __repr__ of pandas objects, to_string metadata _metadata, .attrs labels Dec 2, 2024
@yuanx749
Copy link
Contributor Author

yuanx749 commented Dec 3, 2024

Looks good. Could you add a whatsnew entry in v3.0.0.rst?

Not sure where the right place is, I added in the Other section.

@mroeschke mroeschke added this to the 3.0 milestone Dec 3, 2024
@mroeschke mroeschke merged commit 8911238 into pandas-dev:main Dec 3, 2024
51 checks passed
@mroeschke
Copy link
Member

Thanks @yuanx749

@yuanx749 yuanx749 deleted the truncate_horizontally branch December 4, 2024 00:32
@kaba439
Copy link

kaba439 commented Dec 4, 2024

Many thanks @yuanx749

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
metadata _metadata, .attrs Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: ValueError when executing a DataFrame with another DatFrame in its attrs
3 participants