@@ -453,20 +453,13 @@ def get_adjustment() -> TextAdjustment:
453
453
class TableFormatter :
454
454
455
455
show_dimensions : Union [bool , str ]
456
+ formatters : FormattersType
456
457
457
458
@property
458
459
def is_truncated (self ) -> bool :
459
460
self ._is_truncated : bool
460
461
return self ._is_truncated
461
462
462
- @property
463
- def formatters (self ) -> FormattersType :
464
- return self ._formatters
465
-
466
- @formatters .setter
467
- def formatters (self , formatters : FormattersType ) -> None :
468
- self ._formatters : FormattersType = formatters
469
-
470
463
@property
471
464
def columns (self ) -> Index :
472
465
return self ._columns
@@ -585,15 +578,7 @@ def __init__(
585
578
self .show_index_names = index_names
586
579
self .sparsify = self ._initialize_sparsify (sparsify )
587
580
self .float_format = float_format
588
-
589
- # Ignoring error
590
- # expression has type "Union[List[Callable[..., Any]],
591
- # Tuple[Callable[..., Any], ...],
592
- # Mapping[Union[str, int], Callable[..., Any]], None]",
593
- # variable has type "Union[List[Callable[..., Any]],
594
- # Tuple[Callable[..., Any], ...], Mapping[Union[str, int],
595
- # Callable[..., Any]]]")
596
- self .formatters = formatters # type: ignore[assignment]
581
+ self .formatters = self ._initialize_formatters (formatters )
597
582
self .na_rep = na_rep
598
583
self .decimal = decimal
599
584
@@ -628,23 +613,18 @@ def _initialize_sparsify(self, sparsify: Optional[bool]) -> bool:
628
613
return get_option ("display.multi_sparse" )
629
614
return sparsify
630
615
631
- @property
632
- def formatters (self ) -> FormattersType :
633
- return self ._formatters
634
-
635
- @formatters .setter
636
- def formatters (self , formatters : Optional [FormattersType ]) -> None :
637
- self ._formatters : FormattersType
616
+ def _initialize_formatters (
617
+ self , formatters : Optional [FormattersType ]
618
+ ) -> FormattersType :
638
619
if formatters is None :
639
- self . _formatters = {}
620
+ return {}
640
621
elif len (self .frame .columns ) == len (formatters ) or isinstance (formatters , dict ):
641
- self . _formatters = formatters
622
+ return formatters
642
623
else :
643
624
raise ValueError (
644
625
f"Formatters length({ len (formatters )} ) should match "
645
626
f"DataFrame number of columns({ len (self .frame .columns )} )"
646
627
)
647
- assert self ._formatters is not None
648
628
649
629
@property
650
630
def justify (self ) -> str :
@@ -813,7 +793,7 @@ def _truncate_horizontally(self) -> None:
813
793
# truncate formatter
814
794
if isinstance (self .formatters , (list , tuple )):
815
795
slicer = itemgetter (* cols_to_keep )
816
- self ._formatters = slicer (self .formatters )
796
+ self .formatters = slicer (self .formatters )
817
797
else :
818
798
col_num = cast (int , self .max_cols )
819
799
self .tr_frame = self .tr_frame .iloc [:, :col_num ]
0 commit comments