Skip to content

Commit dd39140

Browse files
authored
TYP: misc typing from pandas-stubs in io and plotting (#51473)
* TYP: misc typing from pandas-stubs in io and plotting * fix enum * go with TypedDict * avoid mypy error * fix some annotations
1 parent f4f2d89 commit dd39140

File tree

8 files changed

+189
-119
lines changed

8 files changed

+189
-119
lines changed

pandas/core/generic.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
TimestampConvertibleTypes,
8181
ValueKeyFunc,
8282
WriteBuffer,
83+
WriteExcelBuffer,
8384
npt,
8485
)
8586
from pandas.compat._optional import import_optional_dependency
@@ -188,12 +189,14 @@
188189
if TYPE_CHECKING:
189190
from pandas._libs.tslibs import BaseOffset
190191

191-
from pandas.core.frame import DataFrame
192+
from pandas import (
193+
DataFrame,
194+
ExcelWriter,
195+
HDFStore,
196+
Series,
197+
)
192198
from pandas.core.indexers.objects import BaseIndexer
193199
from pandas.core.resample import Resampler
194-
from pandas.core.series import Series
195-
196-
from pandas.io.pytables import HDFStore
197200

198201

199202
# goal is to be able to define the docs close to function, while still being
@@ -2091,7 +2094,7 @@ def _repr_data_resource_(self):
20912094
)
20922095
def to_excel(
20932096
self,
2094-
excel_writer,
2097+
excel_writer: FilePath | WriteExcelBuffer | ExcelWriter,
20952098
sheet_name: str = "Sheet1",
20962099
na_rep: str = "",
20972100
float_format: str | None = None,

pandas/io/formats/excel.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@
5252

5353
if TYPE_CHECKING:
5454
from pandas._typing import (
55+
FilePath,
5556
IndexLabel,
5657
StorageOptions,
58+
WriteExcelBuffer,
5759
)
5860

61+
from pandas import ExcelWriter
62+
5963

6064
class ExcelCell:
6165
__fields__ = ("row", "col", "val", "style", "mergestart", "mergeend")
@@ -890,7 +894,7 @@ def get_formatted_cells(self) -> Iterable[ExcelCell]:
890894
@doc(storage_options=_shared_docs["storage_options"])
891895
def write(
892896
self,
893-
writer,
897+
writer: FilePath | WriteExcelBuffer | ExcelWriter,
894898
sheet_name: str = "Sheet1",
895899
startrow: int = 0,
896900
startcol: int = 0,

pandas/io/formats/style.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@
7070
Scalar,
7171
StorageOptions,
7272
WriteBuffer,
73+
WriteExcelBuffer,
7374
)
7475

76+
from pandas import ExcelWriter
77+
7578
try:
7679
import matplotlib as mpl
7780
import matplotlib.pyplot as plt
@@ -494,7 +497,7 @@ def set_tooltips(
494497
)
495498
def to_excel(
496499
self,
497-
excel_writer,
500+
excel_writer: FilePath | WriteExcelBuffer | ExcelWriter,
498501
sheet_name: str = "Sheet1",
499502
na_rep: str = "",
500503
float_format: str | None = None,
@@ -1327,7 +1330,7 @@ def to_string(
13271330
self,
13281331
buf: FilePath | WriteBuffer[str],
13291332
*,
1330-
encoding=...,
1333+
encoding: str | None = ...,
13311334
sparse_index: bool | None = ...,
13321335
sparse_columns: bool | None = ...,
13331336
max_rows: int | None = ...,
@@ -1341,7 +1344,7 @@ def to_string(
13411344
self,
13421345
buf: None = ...,
13431346
*,
1344-
encoding=...,
1347+
encoding: str | None = ...,
13451348
sparse_index: bool | None = ...,
13461349
sparse_columns: bool | None = ...,
13471350
max_rows: int | None = ...,
@@ -1355,7 +1358,7 @@ def to_string(
13551358
self,
13561359
buf: FilePath | WriteBuffer[str] | None = None,
13571360
*,
1358-
encoding=None,
1361+
encoding: str | None = None,
13591362
sparse_index: bool | None = None,
13601363
sparse_columns: bool | None = None,
13611364
max_rows: int | None = None,
@@ -3385,8 +3388,11 @@ def highlight_quantile(
33853388

33863389
@classmethod
33873390
def from_custom_template(
3388-
cls, searchpath, html_table: str | None = None, html_style: str | None = None
3389-
):
3391+
cls,
3392+
searchpath: Sequence[str],
3393+
html_table: str | None = None,
3394+
html_style: str | None = None,
3395+
) -> type[Styler]:
33903396
"""
33913397
Factory function for creating a subclass of ``Styler``.
33923398

pandas/io/json/_json.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def read_json(
395395
orient: str | None = ...,
396396
typ: Literal["frame"] = ...,
397397
dtype: DtypeArg | None = ...,
398-
convert_axes=...,
398+
convert_axes: bool | None = ...,
399399
convert_dates: bool | list[str] = ...,
400400
keep_default_dates: bool = ...,
401401
precise_float: bool = ...,
@@ -420,7 +420,7 @@ def read_json(
420420
orient: str | None = ...,
421421
typ: Literal["series"],
422422
dtype: DtypeArg | None = ...,
423-
convert_axes=...,
423+
convert_axes: bool | None = ...,
424424
convert_dates: bool | list[str] = ...,
425425
keep_default_dates: bool = ...,
426426
precise_float: bool = ...,
@@ -445,7 +445,7 @@ def read_json(
445445
orient: str | None = ...,
446446
typ: Literal["series"],
447447
dtype: DtypeArg | None = ...,
448-
convert_axes=...,
448+
convert_axes: bool | None = ...,
449449
convert_dates: bool | list[str] = ...,
450450
keep_default_dates: bool = ...,
451451
precise_float: bool = ...,
@@ -470,7 +470,7 @@ def read_json(
470470
orient: str | None = ...,
471471
typ: Literal["frame"] = ...,
472472
dtype: DtypeArg | None = ...,
473-
convert_axes=...,
473+
convert_axes: bool | None = ...,
474474
convert_dates: bool | list[str] = ...,
475475
keep_default_dates: bool = ...,
476476
precise_float: bool = ...,
@@ -498,7 +498,7 @@ def read_json(
498498
orient: str | None = None,
499499
typ: Literal["frame", "series"] = "frame",
500500
dtype: DtypeArg | None = None,
501-
convert_axes=None,
501+
convert_axes: bool | None = None,
502502
convert_dates: bool | list[str] = True,
503503
keep_default_dates: bool = True,
504504
precise_float: bool = False,
@@ -814,7 +814,7 @@ def __init__(
814814
orient,
815815
typ: FrameSeriesStrT,
816816
dtype,
817-
convert_axes,
817+
convert_axes: bool | None,
818818
convert_dates,
819819
keep_default_dates: bool,
820820
precise_float: bool,

0 commit comments

Comments
 (0)