Skip to content

adding str to read_excel index_col, resolves #809 #914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2024
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
8 changes: 4 additions & 4 deletions pandas-stubs/io/excel/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)