diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 8b78c6d16..76cd646f3 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -30,6 +30,7 @@ from matplotlib.axes import ( ) import numpy as np from pandas import ( + Index, Period, PeriodDtype, Timedelta, @@ -58,7 +59,6 @@ from pandas.core.indexes.accessors import ( TimedeltaProperties, TimestampProperties, ) -from pandas.core.indexes.base import Index from pandas.core.indexes.category import CategoricalIndex from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexes.interval import IntervalIndex @@ -652,7 +652,7 @@ class Series(IndexOpsMixin[S1], NDFrame): ) -> _str: ... def to_xarray(self) -> xr.DataArray: ... def items(self) -> Iterable[tuple[Hashable, S1]]: ... - def keys(self) -> list: ... + def keys(self) -> Index: ... @overload def to_dict(self, *, into: type[dict] = ...) -> dict[Any, S1]: ... @overload diff --git a/tests/test_series.py b/tests/test_series.py index f0dbe8019..e9fa5c8e6 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -3541,6 +3541,12 @@ def test_series_dict() -> None: ) +def test_series_keys_type() -> None: + # GH 1101 + s = pd.Series([1, 2, 3]) + check(assert_type(s.keys(), pd.Index), pd.Index) + + def test_series_int_float() -> None: # pyright infers mixtures of int and float in a list as list[int | float] check(assert_type(pd.Series([1, 2, 3]), "pd.Series[int]"), pd.Series, np.integer)