diff --git a/pandas-stubs/io/excel/_base.pyi b/pandas-stubs/io/excel/_base.pyi index a3368d2e3..5937fa5f8 100644 --- a/pandas-stubs/io/excel/_base.pyi +++ b/pandas-stubs/io/excel/_base.pyi @@ -49,7 +49,7 @@ def read_excel( *, header: int | Sequence[int] | None = ..., names: ListLikeHashable | None = ..., - index_col: int | Sequence[int] | None = ..., + index_col: int | Sequence[int] | str | None = ..., usecols: str | UsecolsArgType = ..., dtype: str | Dtype | Mapping[str, str | Dtype] | None = ..., engine: ExcelReadEngine | None = ..., @@ -91,7 +91,7 @@ def read_excel( *, header: int | Sequence[int] | None = ..., names: ListLikeHashable | None = ..., - index_col: int | Sequence[int] | None = ..., + index_col: int | Sequence[int] | str | None = ..., usecols: str | UsecolsArgType = ..., dtype: str | Dtype | Mapping[str, str | Dtype] | None = ..., engine: ExcelReadEngine | None = ..., @@ -134,7 +134,7 @@ def read_excel( # type: ignore[misc] *, header: int | Sequence[int] | None = ..., names: ListLikeHashable | None = ..., - index_col: int | Sequence[int] | None = ..., + index_col: int | Sequence[int] | str | None = ..., usecols: str | UsecolsArgType = ..., dtype: str | Dtype | Mapping[str, str | Dtype] | None = ..., engine: ExcelReadEngine | None = ..., @@ -176,7 +176,7 @@ def read_excel( *, header: int | Sequence[int] | None = ..., names: ListLikeHashable | None = ..., - index_col: int | Sequence[int] | None = ..., + index_col: int | Sequence[int] | str | None = ..., usecols: str | UsecolsArgType = ..., dtype: str | Dtype | Mapping[str, str | Dtype] | None = ..., engine: ExcelReadEngine | None = ..., diff --git a/tests/test_io.py b/tests/test_io.py index df2b84804..b03017187 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -1558,3 +1558,21 @@ def test_added_date_format() -> None: ), pd.DataFrame, ) + + +def test_read_excel_index_col() -> None: + with ensure_clean(".xlsx") as path: + pd.DataFrame( + data={ + "foo": [1, 3], + "bar": [2, 4], + } + ).to_excel(path) + + check( + assert_type( + pd.read_excel(path, index_col="bar"), + pd.DataFrame, + ), + pd.DataFrame, + )