Skip to content

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

KevsterAmp pushed a commit to KevsterAmp/pandas that referenced this pull request Mar 12, 2025
…pandas-dev#60459)

* Add test

* replace concat with np

* Revert "replace concat with np"

This reverts commit b48fc35.

* Revert "Revert "replace concat with np""

This reverts commit 6b45ac5.

* try fixing mypy error

* Add whatsnew

---------

Co-authored-by: Matthew Roeschke <[email protected]>
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