Skip to content

Fix #849: Update converters type in read_excel for better Pyright compatibility #1297

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
12 changes: 6 additions & 6 deletions pandas-stubs/io/excel/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def read_excel(
usecols: str | UsecolsArgType = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: ExcelReadEngine | None = ...,
converters: Mapping[int | str, Callable[[object], object]] | None = ...,
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
skiprows: int | Sequence[int] | Callable[[object], bool] | None = ...,
Expand Down Expand Up @@ -97,7 +97,7 @@ def read_excel(
usecols: str | UsecolsArgType = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: ExcelReadEngine | None = ...,
converters: Mapping[int | str, Callable[[object], object]] | None = ...,
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
skiprows: int | Sequence[int] | Callable[[object], bool] | None = ...,
Expand Down Expand Up @@ -141,7 +141,7 @@ def read_excel( # type: ignore[overload-cannot-match]
usecols: str | UsecolsArgType = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: ExcelReadEngine | None = ...,
converters: Mapping[int | str, Callable[[object], object]] | None = ...,
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
skiprows: int | Sequence[int] | Callable[[object], bool] | None = ...,
Expand Down Expand Up @@ -184,7 +184,7 @@ def read_excel(
usecols: str | UsecolsArgType = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: ExcelReadEngine | None = ...,
converters: Mapping[int | str, Callable[[object], object]] | None = ...,
converters: Mapping[int | str, Callable[[Any], Any]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
skiprows: int | Sequence[int] | Callable[[object], bool] | None = ...,
Expand Down Expand Up @@ -264,7 +264,7 @@ class ExcelFile:
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: str | UsecolsArgType = ...,
converters: dict[int | str, Callable[[object], object]] | None = ...,
converters: dict[int | str, Callable[[Any], Any]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
skiprows: int | Sequence[int] | Callable[[object], bool] | None = ...,
Expand Down Expand Up @@ -292,7 +292,7 @@ class ExcelFile:
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: str | UsecolsArgType = ...,
converters: dict[int | str, Callable[[object], object]] | None = ...,
converters: dict[int | str, Callable[[Any], Any]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
skiprows: int | Sequence[int] | Callable[[object], bool] | None = ...,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_excel_converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from functools import partial
import pandas as pd
from typing_extensions import assert_type

partial_func = partial(pd.to_datetime, errors="coerce")

df = pd.read_excel("foo.xlsx", converters={"field_1": partial_func})

assert_type(df, pd.DataFrame)