@@ -989,15 +989,13 @@ def __repr__(self) -> str:
989
989
"""
990
990
Return a string representation for a particular DataFrame.
991
991
"""
992
- buf = StringIO ("" )
993
992
if self ._info_repr ():
993
+ buf = StringIO ()
994
994
self .info (buf = buf )
995
995
return buf .getvalue ()
996
996
997
997
repr_params = fmt .get_dataframe_repr_params ()
998
- self .to_string (buf = buf , ** repr_params )
999
-
1000
- return buf .getvalue ()
998
+ return self .to_string (** repr_params )
1001
999
1002
1000
def _repr_html_ (self ) -> str | None :
1003
1001
"""
@@ -1006,7 +1004,7 @@ def _repr_html_(self) -> str | None:
1006
1004
Mainly for IPython notebook.
1007
1005
"""
1008
1006
if self ._info_repr ():
1009
- buf = StringIO ("" )
1007
+ buf = StringIO ()
1010
1008
self .info (buf = buf )
1011
1009
# need to escape the <class>, should be the first line.
1012
1010
val = buf .getvalue ().replace ("<" , r"<" , 1 )
@@ -1043,6 +1041,56 @@ def _repr_html_(self) -> str | None:
1043
1041
else :
1044
1042
return None
1045
1043
1044
+ @overload
1045
+ def to_string (
1046
+ self ,
1047
+ buf : None = ...,
1048
+ columns : Sequence [str ] | None = ...,
1049
+ col_space : int | list [int ] | dict [Hashable , int ] | None = ...,
1050
+ header : bool | Sequence [str ] = ...,
1051
+ index : bool = ...,
1052
+ na_rep : str = ...,
1053
+ formatters : fmt .FormattersType | None = ...,
1054
+ float_format : fmt .FloatFormatType | None = ...,
1055
+ sparsify : bool | None = ...,
1056
+ index_names : bool = ...,
1057
+ justify : str | None = ...,
1058
+ max_rows : int | None = ...,
1059
+ max_cols : int | None = ...,
1060
+ show_dimensions : bool = ...,
1061
+ decimal : str = ...,
1062
+ line_width : int | None = ...,
1063
+ min_rows : int | None = ...,
1064
+ max_colwidth : int | None = ...,
1065
+ encoding : str | None = ...,
1066
+ ) -> str :
1067
+ ...
1068
+
1069
+ @overload
1070
+ def to_string (
1071
+ self ,
1072
+ buf : FilePathOrBuffer [str ],
1073
+ columns : Sequence [str ] | None = ...,
1074
+ col_space : int | list [int ] | dict [Hashable , int ] | None = ...,
1075
+ header : bool | Sequence [str ] = ...,
1076
+ index : bool = ...,
1077
+ na_rep : str = ...,
1078
+ formatters : fmt .FormattersType | None = ...,
1079
+ float_format : fmt .FloatFormatType | None = ...,
1080
+ sparsify : bool | None = ...,
1081
+ index_names : bool = ...,
1082
+ justify : str | None = ...,
1083
+ max_rows : int | None = ...,
1084
+ max_cols : int | None = ...,
1085
+ show_dimensions : bool = ...,
1086
+ decimal : str = ...,
1087
+ line_width : int | None = ...,
1088
+ min_rows : int | None = ...,
1089
+ max_colwidth : int | None = ...,
1090
+ encoding : str | None = ...,
1091
+ ) -> None :
1092
+ ...
1093
+
1046
1094
@Substitution (
1047
1095
header_type = "bool or sequence of strings" ,
1048
1096
header = "Write out the column names. If a list of strings "
@@ -1058,7 +1106,7 @@ def to_string(
1058
1106
self ,
1059
1107
buf : FilePath | WriteBuffer [str ] | None = None ,
1060
1108
columns : Sequence [str ] | None = None ,
1061
- col_space : int | None = None ,
1109
+ col_space : int | list [ int ] | dict [ Hashable , int ] | None = None ,
1062
1110
header : bool | Sequence [str ] = True ,
1063
1111
index : bool = True ,
1064
1112
na_rep : str = "NaN" ,
0 commit comments