Skip to content

Commit bb41036

Browse files
authored
Fix Series.to_string (#721)
* Fix Series.to_string * float_format
1 parent 630efce commit bb41036

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ from pandas._typing import (
7676
Dtype,
7777
FilePath,
7878
FillnaOptions,
79-
FloatFormatType,
8079
FormattersType,
8180
GroupByObjectNonScalar,
8281
HashableT,
@@ -2161,7 +2160,7 @@ class DataFrame(NDFrame, OpsMixin):
21612160
index: _bool = ...,
21622161
na_rep: _str = ...,
21632162
formatters: FormattersType | None = ...,
2164-
float_format: FloatFormatType | None = ...,
2163+
float_format: Callable[[float], str] | None = ...,
21652164
sparsify: _bool | None = ...,
21662165
index_names: _bool = ...,
21672166
justify: _str | None = ...,
@@ -2184,7 +2183,7 @@ class DataFrame(NDFrame, OpsMixin):
21842183
index: _bool = ...,
21852184
na_rep: _str = ...,
21862185
formatters: FormattersType | None = ...,
2187-
float_format: FloatFormatType | None = ...,
2186+
float_format: Callable[[float], str] | None = ...,
21882187
sparsify: _bool | None = ...,
21892188
index_names: _bool = ...,
21902189
justify: _str | None = ...,

pandas-stubs/core/series.pyi

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -453,38 +453,28 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
453453
self,
454454
buf: FilePath | WriteBuffer[str],
455455
na_rep: _str = ...,
456-
formatters=...,
457-
float_format=...,
458-
sparsify: _bool | None = ...,
459-
index_names: _bool = ...,
460-
justify: _str | None = ...,
456+
float_format: Callable[[float], str] = ...,
457+
header: _bool = ...,
458+
index: _bool = ...,
459+
length: _bool = ...,
460+
dtype: _bool = ...,
461+
name: _bool = ...,
461462
max_rows: int | None = ...,
462463
min_rows: int | None = ...,
463-
max_cols: int | None = ...,
464-
show_dimensions: _bool = ...,
465-
decimal: _str = ...,
466-
line_width: int | None = ...,
467-
max_colwidth: int | None = ...,
468-
encoding: _str | None = ...,
469464
) -> None: ...
470465
@overload
471466
def to_string(
472467
self,
473468
buf: None = ...,
474469
na_rep: _str = ...,
475-
formatters=...,
476-
float_format=...,
477-
sparsify: _bool | None = ...,
478-
index_names: _bool = ...,
479-
justify: _str | None = ...,
470+
float_format: Callable[[float], str] = ...,
471+
header: _bool = ...,
472+
index: _bool = ...,
473+
length: _bool = ...,
474+
dtype: _bool = ...,
475+
name: _bool = ...,
480476
max_rows: int | None = ...,
481477
min_rows: int | None = ...,
482-
max_cols: int | None = ...,
483-
show_dimensions: _bool = ...,
484-
decimal: _str = ...,
485-
line_width: int | None = ...,
486-
max_colwidth: int | None = ...,
487-
encoding: _str | None = ...,
488478
) -> _str: ...
489479
@overload
490480
def to_json(

tests/test_series.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,3 +1989,17 @@ def test_groupby_diff() -> None:
19891989
# GH 658
19901990
s = pd.Series([1, 2, 3, np.nan])
19911991
check(assert_type(s.groupby(level=0).diff(), pd.Series), pd.Series)
1992+
1993+
1994+
def test_to_string() -> None:
1995+
# GH 720
1996+
s = pd.Series([1])
1997+
check(
1998+
assert_type(
1999+
s.to_string(
2000+
index=False, header=False, length=False, dtype=False, name=False
2001+
),
2002+
str,
2003+
),
2004+
str,
2005+
)

0 commit comments

Comments
 (0)