2
2
from datetime import datetime
3
3
import operator
4
4
from textwrap import dedent
5
- from typing import TYPE_CHECKING , Any , Callable , FrozenSet , Hashable , Optional , Union
5
+ from typing import (
6
+ TYPE_CHECKING ,
7
+ Any ,
8
+ Callable ,
9
+ FrozenSet ,
10
+ Hashable ,
11
+ List ,
12
+ Optional ,
13
+ Union ,
14
+ )
6
15
import warnings
7
16
8
17
import numpy as np
@@ -910,15 +919,12 @@ def format(self, name: bool = False, formatter=None, **kwargs):
910
919
911
920
return self ._format_with_header (header , ** kwargs )
912
921
913
- def _format_with_header (self , header , na_rep = "NaN" , ** kwargs ):
914
- values = self ._values
915
-
922
+ def _format_with_header (self , header , na_rep = "NaN" ) -> List [str_t ]:
916
923
from pandas .io .formats .format import format_array
917
924
918
- if is_categorical_dtype (values .dtype ):
919
- values = np .array (values )
925
+ values = self ._values
920
926
921
- elif is_object_dtype (values .dtype ):
927
+ if is_object_dtype (values .dtype ):
922
928
values = lib .maybe_convert_objects (values , safe = 1 )
923
929
924
930
if is_object_dtype (values .dtype ):
@@ -929,10 +935,9 @@ def _format_with_header(self, header, na_rep="NaN", **kwargs):
929
935
if mask .any ():
930
936
result = np .array (result )
931
937
result [mask ] = na_rep
932
- result = result .tolist ()
933
-
938
+ result = result .tolist () # type: ignore
934
939
else :
935
- result = _trim_front (format_array (values , None , justify = "left" ))
940
+ result = trim_front (format_array (values , None , justify = "left" ))
936
941
return header + result
937
942
938
943
def to_native_types (self , slicer = None , ** kwargs ):
@@ -5611,7 +5616,7 @@ def ensure_has_len(seq):
5611
5616
return seq
5612
5617
5613
5618
5614
- def _trim_front (strings ) :
5619
+ def trim_front (strings : List [ str ]) -> List [ str ] :
5615
5620
"""
5616
5621
Trims zeros and decimal points.
5617
5622
"""
0 commit comments