Skip to content

Commit de01518

Browse files
committed
TYP: improve typing for type DataFrame.to_string
1 parent 7e51bd7 commit de01518

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

pandas/core/frame.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,15 +989,13 @@ def __repr__(self) -> str:
989989
"""
990990
Return a string representation for a particular DataFrame.
991991
"""
992-
buf = StringIO("")
993992
if self._info_repr():
993+
buf = StringIO("")
994994
self.info(buf=buf)
995995
return buf.getvalue()
996996

997997
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)
1001999

10021000
def _repr_html_(self) -> str | None:
10031001
"""
@@ -1043,6 +1041,56 @@ def _repr_html_(self) -> str | None:
10431041
else:
10441042
return None
10451043

1044+
@overload
1045+
def to_string(
1046+
self,
1047+
buf: None = None,
1048+
columns: Sequence[str] | None = None,
1049+
col_space: int | None = None,
1050+
header: bool | Sequence[str] = True,
1051+
index: bool = True,
1052+
na_rep: str = "NaN",
1053+
formatters: fmt.FormattersType | None = None,
1054+
float_format: fmt.FloatFormatType | None = None,
1055+
sparsify: bool | None = None,
1056+
index_names: bool = True,
1057+
justify: str | None = None,
1058+
max_rows: int | None = None,
1059+
min_rows: int | None = None,
1060+
max_cols: int | None = None,
1061+
show_dimensions: bool = False,
1062+
decimal: str = ".",
1063+
line_width: int | None = None,
1064+
max_colwidth: int | None = None,
1065+
encoding: str | None = None,
1066+
) -> str:
1067+
...
1068+
1069+
@overload
1070+
def to_string(
1071+
self,
1072+
buf: FilePathOrBuffer[str],
1073+
columns: Sequence[str] | None = None,
1074+
col_space: int | None = None,
1075+
header: bool | Sequence[str] = True,
1076+
index: bool = True,
1077+
na_rep: str = "NaN",
1078+
formatters: fmt.FormattersType | None = None,
1079+
float_format: fmt.FloatFormatType | None = None,
1080+
sparsify: bool | None = None,
1081+
index_names: bool = True,
1082+
justify: str | None = None,
1083+
max_rows: int | None = None,
1084+
min_rows: int | None = None,
1085+
max_cols: int | None = None,
1086+
show_dimensions: bool = False,
1087+
decimal: str = ".",
1088+
line_width: int | None = None,
1089+
max_colwidth: int | None = None,
1090+
encoding: str | None = None,
1091+
) -> None:
1092+
...
1093+
10461094
@Substitution(
10471095
header_type="bool or sequence",
10481096
header="Write out the column names. If a list of strings "

0 commit comments

Comments
 (0)