10
10
from functools import partial
11
11
from io import StringIO
12
12
import math
13
- from operator import itemgetter
14
13
import re
15
14
from shutil import get_terminal_size
16
15
from typing import (
@@ -592,6 +591,7 @@ def __init__(
592
591
self .max_cols_fitted = self ._calc_max_cols_fitted ()
593
592
self .max_rows_fitted = self ._calc_max_rows_fitted ()
594
593
594
+ self .tr_frame = self .frame
595
595
self ._truncate ()
596
596
self .adj = get_adjustment ()
597
597
@@ -730,8 +730,6 @@ def _truncate(self) -> None:
730
730
"""
731
731
Check whether the frame should be truncated. If so, slice the frame up.
732
732
"""
733
- self .tr_frame = self .frame .copy ()
734
-
735
733
if self .is_truncated_horizontally :
736
734
self ._truncate_horizontally ()
737
735
@@ -749,17 +747,16 @@ def _truncate_horizontally(self) -> None:
749
747
assert self .max_cols_fitted is not None
750
748
col_num = self .max_cols_fitted // 2
751
749
if col_num >= 1 :
752
- cols_to_keep = [
753
- x
754
- for x in range (self .frame .shape [1 ])
755
- if x < col_num or x >= len (self .frame .columns ) - col_num
756
- ]
757
- self .tr_frame = self .tr_frame .iloc [:, cols_to_keep ]
750
+ left = self .tr_frame .iloc [:, :col_num ]
751
+ right = self .tr_frame .iloc [:, - col_num :]
752
+ self .tr_frame = concat ((left , right ), axis = 1 )
758
753
759
754
# truncate formatter
760
755
if isinstance (self .formatters , (list , tuple )):
761
- slicer = itemgetter (* cols_to_keep )
762
- self .formatters = slicer (self .formatters )
756
+ self .formatters = [
757
+ * self .formatters [:col_num ],
758
+ * self .formatters [- col_num :],
759
+ ]
763
760
else :
764
761
col_num = cast (int , self .max_cols )
765
762
self .tr_frame = self .tr_frame .iloc [:, :col_num ]
@@ -775,12 +772,9 @@ def _truncate_vertically(self) -> None:
775
772
assert self .max_rows_fitted is not None
776
773
row_num = self .max_rows_fitted // 2
777
774
if row_num >= 1 :
778
- rows_to_keep = [
779
- x
780
- for x in range (self .frame .shape [0 ])
781
- if x < row_num or x >= len (self .frame ) - row_num
782
- ]
783
- self .tr_frame = self .tr_frame .iloc [rows_to_keep , :]
775
+ head = self .tr_frame .iloc [:row_num , :]
776
+ tail = self .tr_frame .iloc [- row_num :, :]
777
+ self .tr_frame = concat ((head , tail ))
784
778
else :
785
779
row_num = cast (int , self .max_rows )
786
780
self .tr_frame = self .tr_frame .iloc [:row_num , :]
0 commit comments