Skip to content

Commit d34e0a8

Browse files
mutricylLaurent Mutricy
andauthored
adding str to read_excel index_col, resolves #809 (#914)
Co-authored-by: Laurent Mutricy <[email protected]>
1 parent 78f835c commit d34e0a8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

pandas-stubs/io/excel/_base.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def read_excel(
4949
*,
5050
header: int | Sequence[int] | None = ...,
5151
names: ListLikeHashable | None = ...,
52-
index_col: int | Sequence[int] | None = ...,
52+
index_col: int | Sequence[int] | str | None = ...,
5353
usecols: str | UsecolsArgType = ...,
5454
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
5555
engine: ExcelReadEngine | None = ...,
@@ -91,7 +91,7 @@ def read_excel(
9191
*,
9292
header: int | Sequence[int] | None = ...,
9393
names: ListLikeHashable | None = ...,
94-
index_col: int | Sequence[int] | None = ...,
94+
index_col: int | Sequence[int] | str | None = ...,
9595
usecols: str | UsecolsArgType = ...,
9696
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
9797
engine: ExcelReadEngine | None = ...,
@@ -134,7 +134,7 @@ def read_excel( # type: ignore[misc]
134134
*,
135135
header: int | Sequence[int] | None = ...,
136136
names: ListLikeHashable | None = ...,
137-
index_col: int | Sequence[int] | None = ...,
137+
index_col: int | Sequence[int] | str | None = ...,
138138
usecols: str | UsecolsArgType = ...,
139139
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
140140
engine: ExcelReadEngine | None = ...,
@@ -176,7 +176,7 @@ def read_excel(
176176
*,
177177
header: int | Sequence[int] | None = ...,
178178
names: ListLikeHashable | None = ...,
179-
index_col: int | Sequence[int] | None = ...,
179+
index_col: int | Sequence[int] | str | None = ...,
180180
usecols: str | UsecolsArgType = ...,
181181
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
182182
engine: ExcelReadEngine | None = ...,

tests/test_io.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,3 +1558,21 @@ def test_added_date_format() -> None:
15581558
),
15591559
pd.DataFrame,
15601560
)
1561+
1562+
1563+
def test_read_excel_index_col() -> None:
1564+
with ensure_clean(".xlsx") as path:
1565+
pd.DataFrame(
1566+
data={
1567+
"foo": [1, 3],
1568+
"bar": [2, 4],
1569+
}
1570+
).to_excel(path)
1571+
1572+
check(
1573+
assert_type(
1574+
pd.read_excel(path, index_col="bar"),
1575+
pd.DataFrame,
1576+
),
1577+
pd.DataFrame,
1578+
)

0 commit comments

Comments
 (0)