Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,9 @@ def _truncate_horizontally(self) -> None:
assert self.max_cols_fitted is not None
col_num = self.max_cols_fitted // 2
if col_num >= 1:
left = self.tr_frame.iloc[:, :col_num]
right = self.tr_frame.iloc[:, -col_num:]
self.tr_frame = concat((left, right), axis=1)
_len = len(self.tr_frame.columns)
_slice = np.hstack([np.arange(col_num), np.arange(_len - col_num, _len)])
self.tr_frame = self.tr_frame.iloc[:, _slice]

# truncate formatter
if isinstance(self.formatters, (list, tuple)):
Expand All @@ -682,7 +682,7 @@ def _truncate_horizontally(self) -> None:
else:
col_num = cast(int, self.max_cols)
self.tr_frame = self.tr_frame.iloc[:, :col_num]
self.tr_col_num = col_num
self.tr_col_num: int = col_num

def _truncate_vertically(self) -> None:
"""Remove rows, which are not to be displayed.
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def test_repr_truncation_preserves_na(self):
with option_context("display.max_rows", 2, "display.show_dimensions", False):
assert repr(df) == " a\n0 <NA>\n.. ...\n9 <NA>"

def test_repr_truncation_dataframe_attrs(self):
# 60455
df = DataFrame([[0] * 10])
df.attrs["b"] = DataFrame([])
with option_context("display.max_columns", 2, "display.show_dimensions", False):
assert repr(df) == " 0 ... 9\n0 0 ... 0"

def test_max_colwidth_negative_int_raises(self):
# Deprecation enforced from:
# https://github.com/pandas-dev/pandas/issues/31532
Expand Down
Loading