Skip to content
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

TYP: Fix return type of Series.keys() fro list to Index (#1101) #1106

Merged
merged 6 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ from pandas import (
PeriodDtype,
Timedelta,
Timestamp,
Index,
)
from pandas.core.api import (
Int8Dtype as Int8Dtype,
Expand Down Expand Up @@ -652,7 +653,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
Expand Down
7 changes: 7 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3541,6 +3541,13 @@ def test_series_dict() -> None:
)


def test_series_keys_type() -> None:
# GH 1101
if TYPE_CHECKING:
s = pd.Series([1, 2, 3])
assert_type(s.keys(), 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)
Expand Down