Skip to content

Commit 8fd8b1f

Browse files
committed
Add overloads
1 parent 3e5407f commit 8fd8b1f

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

pandas/_typing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
DatetimeLikeScalar = Union["Period", "Timestamp", "Timedelta"]
8585
PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"]
8686
Scalar = Union[PythonScalar, PandasScalar]
87+
IntStrT = TypeVar("IntStrT", int, str)
8788

8889

8990
# timestamp and timedelta convertible types

pandas/io/excel/_base.py

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Sequence,
1818
Union,
1919
cast,
20+
overload,
2021
)
2122
import warnings
2223
import zipfile
@@ -27,6 +28,7 @@
2728
from pandas._typing import (
2829
DtypeArg,
2930
FilePath,
31+
IntStrT,
3032
ReadBuffer,
3133
StorageOptions,
3234
WriteExcelBuffer,
@@ -349,11 +351,77 @@
349351
)
350352

351353

354+
@overload
355+
def read_excel(
356+
io,
357+
sheet_name: str | int,
358+
header: int | Sequence[int] | None = ...,
359+
names=...,
360+
index_col: int | Sequence[int] | None = ...,
361+
usecols=...,
362+
squeeze: bool | None = ...,
363+
dtype: DtypeArg | None = ...,
364+
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ...,
365+
converters=...,
366+
true_values: Iterable[Hashable] | None = ...,
367+
false_values: Iterable[Hashable] | None = ...,
368+
skiprows: Sequence[int] | int | Callable[[int], object] | None = ...,
369+
nrows: int | None = ...,
370+
na_values=...,
371+
keep_default_na: bool = ...,
372+
na_filter: bool = ...,
373+
verbose: bool = ...,
374+
parse_dates=...,
375+
date_parser=...,
376+
thousands: str | None = ...,
377+
decimal: str = ...,
378+
comment: str | None = ...,
379+
skipfooter: int = ...,
380+
convert_float: bool | None = ...,
381+
mangle_dupe_cols: bool = ...,
382+
storage_options: StorageOptions = ...,
383+
) -> DataFrame:
384+
...
385+
386+
387+
@overload
388+
def read_excel(
389+
io,
390+
sheet_name: list[IntStrT] | None,
391+
header: int | Sequence[int] | None = ...,
392+
names=...,
393+
index_col: int | Sequence[int] | None = ...,
394+
usecols=...,
395+
squeeze: bool | None = ...,
396+
dtype: DtypeArg | None = ...,
397+
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ...,
398+
converters=...,
399+
true_values: Iterable[Hashable] | None = ...,
400+
false_values: Iterable[Hashable] | None = ...,
401+
skiprows: Sequence[int] | int | Callable[[int], object] | None = ...,
402+
nrows: int | None = ...,
403+
na_values=...,
404+
keep_default_na: bool = ...,
405+
na_filter: bool = ...,
406+
verbose: bool = ...,
407+
parse_dates=...,
408+
date_parser=...,
409+
thousands: str | None = ...,
410+
decimal: str = ...,
411+
comment: str | None = ...,
412+
skipfooter: int = ...,
413+
convert_float: bool | None = ...,
414+
mangle_dupe_cols: bool = ...,
415+
storage_options: StorageOptions = ...,
416+
) -> dict[IntStrT, DataFrame]:
417+
...
418+
419+
352420
@deprecate_nonkeyword_arguments(allowed_args=["io", "sheet_name"], version="2.0")
353421
@Appender(_read_excel_doc)
354422
def read_excel(
355423
io,
356-
sheet_name: str | int | list[int] | list[str] | None = 0,
424+
sheet_name: str | int | list[IntStrT] | None = 0,
357425
header: int | Sequence[int] | None = 0,
358426
names=None,
359427
index_col: int | Sequence[int] | None = None,
@@ -379,7 +447,7 @@ def read_excel(
379447
convert_float: bool | None = None,
380448
mangle_dupe_cols: bool = True,
381449
storage_options: StorageOptions = None,
382-
) -> DataFrame | dict[str, DataFrame] | dict[int, DataFrame]:
450+
) -> DataFrame | dict[IntStrT, DataFrame]:
383451

384452
should_close = False
385453
if not isinstance(io, ExcelFile):

0 commit comments

Comments
 (0)