Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import defaultdict
from collections.abc import Generator
import csv
from functools import partial
import io
import os.path
import pathlib
Expand Down Expand Up @@ -1792,3 +1793,14 @@ def test_read_json_engine() -> None:
pd.read_json(dd, lines=False, engine="pyarrow") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue]
pd.read_json(io.StringIO(data), engine="pyarrow") # type: ignore[call-overload] # pyright: ignore[reportArgumentType]
pd.read_json(io.StringIO(data), lines=True, engine="pyarrow") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue]


def test_converters_partial() -> None:
df = pd.DataFrame({"field_1": ["2020-01-01", "not a date"]})
partial_func = partial(pd.to_datetime, errors="coerce")

with ensure_clean(".xlsx") as path:
check(assert_type(df.to_excel(path, index=False), None), type(None))

result = pd.read_excel(path, converters={"field_1": partial_func})
check(assert_type(result, pd.DataFrame), pd.DataFrame)
Loading