Skip to content

Commit 4976e11

Browse files
janlodewijkDr-Irv
andauthored
TYP: Fix return type of Series.keys() fro list to Index (#1101) (#1106)
* Update series.pyi, tackling issue #1101 Imported Index from pandas and Changed keys method: def keys(self) -> Index: ... * Update test_series.py Add a test for issue # 1101 * Update tests/test_series.py Following the pandas pattern. Co-authored-by: Irv Lustig <[email protected]> * Fix import issue in series.pyi to resolve Ruff error * Delete test --------- Co-authored-by: Irv Lustig <[email protected]>
1 parent a516870 commit 4976e11

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pandas-stubs/core/series.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ from matplotlib.axes import (
3030
)
3131
import numpy as np
3232
from pandas import (
33+
Index,
3334
Period,
3435
PeriodDtype,
3536
Timedelta,
@@ -58,7 +59,6 @@ from pandas.core.indexes.accessors import (
5859
TimedeltaProperties,
5960
TimestampProperties,
6061
)
61-
from pandas.core.indexes.base import Index
6262
from pandas.core.indexes.category import CategoricalIndex
6363
from pandas.core.indexes.datetimes import DatetimeIndex
6464
from pandas.core.indexes.interval import IntervalIndex
@@ -653,7 +653,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
653653
) -> _str: ...
654654
def to_xarray(self) -> xr.DataArray: ...
655655
def items(self) -> Iterable[tuple[Hashable, S1]]: ...
656-
def keys(self) -> list: ...
656+
def keys(self) -> Index: ...
657657
@overload
658658
def to_dict(self, *, into: type[dict] = ...) -> dict[Any, S1]: ...
659659
@overload

tests/test_series.py

+6
Original file line numberDiff line numberDiff line change
@@ -3546,6 +3546,12 @@ def test_series_dict() -> None:
35463546
)
35473547

35483548

3549+
def test_series_keys_type() -> None:
3550+
# GH 1101
3551+
s = pd.Series([1, 2, 3])
3552+
check(assert_type(s.keys(), pd.Index), pd.Index)
3553+
3554+
35493555
def test_series_int_float() -> None:
35503556
# pyright infers mixtures of int and float in a list as list[int | float]
35513557
check(assert_type(pd.Series([1, 2, 3]), "pd.Series[int]"), pd.Series, np.integer)

0 commit comments

Comments
 (0)