Skip to content

TYP: misc typing from pandas-stubs in io and plotting #51473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -189,12 +190,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 @@ -2089,7 +2092,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
8 changes: 7 additions & 1 deletion pandas/io/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import itertools
import re
from typing import (
TYPE_CHECKING,
Any,
Callable,
Hashable,
Expand All @@ -24,8 +25,10 @@

from pandas._libs.lib import is_list_like
from pandas._typing import (
FilePath,
IndexLabel,
StorageOptions,
WriteExcelBuffer,
)
from pandas.util._decorators import doc
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -53,6 +56,9 @@
from pandas.io.formats.format import get_level_lengths
from pandas.io.formats.printing import pprint_thing

if TYPE_CHECKING:
from pandas import ExcelWriter


class ExcelCell:
__fields__ = ("row", "col", "val", "style", "mergestart", "mergeend")
Expand Down Expand Up @@ -887,7 +893,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 @@ -31,6 +31,7 @@
Scalar,
StorageOptions,
WriteBuffer,
WriteExcelBuffer,
)
from pandas.compat._optional import import_optional_dependency
from pandas.util._decorators import (
Expand Down Expand Up @@ -71,6 +72,8 @@
if TYPE_CHECKING:
from matplotlib.colors import Colormap

from pandas import ExcelWriter

try:
import matplotlib as mpl
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -493,7 +496,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 @@ -1326,7 +1329,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 @@ -1340,7 +1343,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 @@ -1354,7 +1357,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 @@ -3384,8 +3387,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],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also accepts strings based on the stubs

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 @@ -392,7 +392,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 @@ -417,7 +417,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 @@ -442,7 +442,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 @@ -467,7 +467,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 @@ -495,7 +495,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 @@ -811,7 +811,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