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
9 changes: 5 additions & 4 deletions pandas-stubs/io/excel/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from collections.abc import (
Callable,
Hashable,
Iterable,
Mapping,
Sequence,
)
from types import TracebackType
Expand Down Expand Up @@ -41,9 +42,9 @@ def read_excel(
names: list[str] | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: Sequence[int] | Sequence[str] | Callable[[str], bool] | None = ...,
dtype: str | Dtype | dict[str, str | Dtype] | None = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ...,
converters: dict[int | str, Callable[[object], object]] | None = ...,
converters: Mapping[int | str, Callable[[object], object]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
skiprows: int | Sequence[int] | Callable[[object], bool] | None = ...,
Expand Down Expand Up @@ -79,9 +80,9 @@ def read_excel(
names: list[str] | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: Sequence[int] | Sequence[str] | Callable[[str], bool] | None = ...,
dtype: str | Dtype | dict[str, str | Dtype] | None = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ...,
converters: dict[int | str, Callable[[object], object]] | None = ...,
converters: Mapping[int | str, Callable[[object], object]] | 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_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,15 @@ def test_read_excel_list():
)


def test_read_excel_dtypes():
# GH 440
df = pd.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"], "c": [10.0, 20.0, 30.3]})
with ensure_clean(".xlsx") as path:
check(assert_type(df.to_excel(path), None), type(None))
dtypes = {"a": np.int64, "b": str, "c": np.float64}
check(assert_type(read_excel(path, dtype=dtypes), pd.DataFrame), pd.DataFrame)


def test_excel_writer():
with ensure_clean(".xlsx") as path:
with pd.ExcelWriter(path) as ew:
Expand Down