Skip to content

Commit

Permalink
TYP: misc typing from pandas-stubs in io and plotting (pandas-dev#51473)
Browse files Browse the repository at this point in the history
* TYP: misc typing from pandas-stubs in io and plotting

* fix enum

* go with TypedDict

* avoid mypy error

* fix some annotations
  • Loading branch information
twoertwein authored Mar 9, 2023
1 parent f4f2d89 commit dd39140
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 119 deletions.
13 changes: 8 additions & 5 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
TimestampConvertibleTypes,
ValueKeyFunc,
WriteBuffer,
WriteExcelBuffer,
npt,
)
from pandas.compat._optional import import_optional_dependency
Expand Down Expand Up @@ -188,12 +189,14 @@
if TYPE_CHECKING:
from pandas._libs.tslibs import BaseOffset

from pandas.core.frame import DataFrame
from pandas import (
DataFrame,
ExcelWriter,
HDFStore,
Series,
)
from pandas.core.indexers.objects import BaseIndexer
from pandas.core.resample import Resampler
from pandas.core.series import Series

from pandas.io.pytables import HDFStore


# goal is to be able to define the docs close to function, while still being
Expand Down Expand Up @@ -2091,7 +2094,7 @@ def _repr_data_resource_(self):
)
def to_excel(
self,
excel_writer,
excel_writer: FilePath | WriteExcelBuffer | ExcelWriter,
sheet_name: str = "Sheet1",
na_rep: str = "",
float_format: str | None = None,
Expand Down
6 changes: 5 additions & 1 deletion pandas/io/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@

if TYPE_CHECKING:
from pandas._typing import (
FilePath,
IndexLabel,
StorageOptions,
WriteExcelBuffer,
)

from pandas import ExcelWriter


class ExcelCell:
__fields__ = ("row", "col", "val", "style", "mergestart", "mergeend")
Expand Down Expand Up @@ -890,7 +894,7 @@ def get_formatted_cells(self) -> Iterable[ExcelCell]:
@doc(storage_options=_shared_docs["storage_options"])
def write(
self,
writer,
writer: FilePath | WriteExcelBuffer | ExcelWriter,
sheet_name: str = "Sheet1",
startrow: int = 0,
startcol: int = 0,
Expand Down
18 changes: 12 additions & 6 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@
Scalar,
StorageOptions,
WriteBuffer,
WriteExcelBuffer,
)

from pandas import ExcelWriter

try:
import matplotlib as mpl
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -494,7 +497,7 @@ def set_tooltips(
)
def to_excel(
self,
excel_writer,
excel_writer: FilePath | WriteExcelBuffer | ExcelWriter,
sheet_name: str = "Sheet1",
na_rep: str = "",
float_format: str | None = None,
Expand Down Expand Up @@ -1327,7 +1330,7 @@ def to_string(
self,
buf: FilePath | WriteBuffer[str],
*,
encoding=...,
encoding: str | None = ...,
sparse_index: bool | None = ...,
sparse_columns: bool | None = ...,
max_rows: int | None = ...,
Expand All @@ -1341,7 +1344,7 @@ def to_string(
self,
buf: None = ...,
*,
encoding=...,
encoding: str | None = ...,
sparse_index: bool | None = ...,
sparse_columns: bool | None = ...,
max_rows: int | None = ...,
Expand All @@ -1355,7 +1358,7 @@ def to_string(
self,
buf: FilePath | WriteBuffer[str] | None = None,
*,
encoding=None,
encoding: str | None = None,
sparse_index: bool | None = None,
sparse_columns: bool | None = None,
max_rows: int | None = None,
Expand Down Expand Up @@ -3385,8 +3388,11 @@ def highlight_quantile(

@classmethod
def from_custom_template(
cls, searchpath, html_table: str | None = None, html_style: str | None = None
):
cls,
searchpath: Sequence[str],
html_table: str | None = None,
html_style: str | None = None,
) -> type[Styler]:
"""
Factory function for creating a subclass of ``Styler``.
Expand Down
12 changes: 6 additions & 6 deletions pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def read_json(
orient: str | None = ...,
typ: Literal["frame"] = ...,
dtype: DtypeArg | None = ...,
convert_axes=...,
convert_axes: bool | None = ...,
convert_dates: bool | list[str] = ...,
keep_default_dates: bool = ...,
precise_float: bool = ...,
Expand All @@ -420,7 +420,7 @@ def read_json(
orient: str | None = ...,
typ: Literal["series"],
dtype: DtypeArg | None = ...,
convert_axes=...,
convert_axes: bool | None = ...,
convert_dates: bool | list[str] = ...,
keep_default_dates: bool = ...,
precise_float: bool = ...,
Expand All @@ -445,7 +445,7 @@ def read_json(
orient: str | None = ...,
typ: Literal["series"],
dtype: DtypeArg | None = ...,
convert_axes=...,
convert_axes: bool | None = ...,
convert_dates: bool | list[str] = ...,
keep_default_dates: bool = ...,
precise_float: bool = ...,
Expand All @@ -470,7 +470,7 @@ def read_json(
orient: str | None = ...,
typ: Literal["frame"] = ...,
dtype: DtypeArg | None = ...,
convert_axes=...,
convert_axes: bool | None = ...,
convert_dates: bool | list[str] = ...,
keep_default_dates: bool = ...,
precise_float: bool = ...,
Expand Down Expand Up @@ -498,7 +498,7 @@ def read_json(
orient: str | None = None,
typ: Literal["frame", "series"] = "frame",
dtype: DtypeArg | None = None,
convert_axes=None,
convert_axes: bool | None = None,
convert_dates: bool | list[str] = True,
keep_default_dates: bool = True,
precise_float: bool = False,
Expand Down Expand Up @@ -814,7 +814,7 @@ def __init__(
orient,
typ: FrameSeriesStrT,
dtype,
convert_axes,
convert_axes: bool | None,
convert_dates,
keep_default_dates: bool,
precise_float: bool,
Expand Down
Loading

0 comments on commit dd39140

Please sign in to comment.