From 0fc1cc57203e18fa67518a4cd51f59e9e41a2728 Mon Sep 17 00:00:00 2001 From: Yuchen Jin Date: Wed, 12 Feb 2025 15:40:28 -0600 Subject: [PATCH 1/2] Make `pd.ExcelFile` consistent with the run time. --- pandas-stubs/io/excel/_base.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas-stubs/io/excel/_base.pyi b/pandas-stubs/io/excel/_base.pyi index f03bdd08b..5b9d5a9c4 100644 --- a/pandas-stubs/io/excel/_base.pyi +++ b/pandas-stubs/io/excel/_base.pyi @@ -245,9 +245,10 @@ class ExcelFile: io: FilePath | ReadBuffer[bytes] | bytes = ... def __init__( self, - io: FilePath | ReadBuffer[bytes] | bytes, + path_or_buffer: FilePath | ReadBuffer[bytes] | bytes, engine: ExcelReadEngine | None = ..., storage_options: StorageOptions = ..., + engine_kwargs: dict[str, Any] | None = ..., ) -> None: ... def __fspath__(self): ... @overload From 0d0faa9d4d01b81bed5d748d4e6147e99ba849f7 Mon Sep 17 00:00:00 2001 From: Yuchen Jin Date: Wed, 12 Feb 2025 15:48:15 -0600 Subject: [PATCH 2/2] Add test for the signature of `pd.ExcelFile`. --- tests/test_io.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_io.py b/tests/test_io.py index 682798854..cca219c42 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -1116,6 +1116,14 @@ def test_excel_reader(): check(assert_type(ef, pd.ExcelFile), pd.ExcelFile) check(assert_type(pd.read_excel(ef), pd.DataFrame), pd.DataFrame) + with pd.ExcelFile( + path_or_buffer=path, + engine="openpyxl", + engine_kwargs={"data_only": True}, + ) as ef: + check(assert_type(ef, pd.ExcelFile), pd.ExcelFile) + check(assert_type(pd.read_excel(ef), pd.DataFrame), pd.DataFrame) + def test_excel_writer(): with ensure_clean(".xlsx") as path: