Skip to content

Fix series creation from dict views #1323

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
Aug 15, 2025
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
5 changes: 3 additions & 2 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ from builtins import (
bool as _bool,
str as _str,
)
from collections import dict_keys # type: ignore[attr-defined]
from collections.abc import (
Callable,
Hashable,
Iterable,
Iterator,
KeysView,
Mapping,
MutableMapping,
Sequence,
ValuesView,
)
from datetime import (
date,
Expand Down Expand Up @@ -406,7 +407,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: S1 | _ListLike[S1] | dict[HashableT1, S1] | dict_keys[S1, Any],
data: S1 | _ListLike[S1] | dict[HashableT1, S1] | KeysView[S1] | ValuesView[S1],
index: AxesData | None = ...,
dtype: Dtype = ...,
name: Hashable = ...,
Expand Down
10 changes: 4 additions & 6 deletions tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3801,13 +3801,11 @@ def test_series_bool_fails() -> None:
pass


def test_series_dict() -> None:
def test_series_from_dict_views() -> None:
# GH 812
check(
assert_type(pd.Series({"a": 1, "b": 2}.keys()), "pd.Series[str]"),
pd.Series,
str,
)
d = {"a": 1, "b": 2}
check(assert_type(pd.Series(d.keys()), "pd.Series[str]"), pd.Series, str)
check(assert_type(pd.Series(d.values()), "pd.Series[int]"), pd.Series, np.integer)


def test_series_keys_type() -> None:
Expand Down
Loading