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

Series(Mapping) #843

Merged
merged 6 commits into from
Dec 26, 2023
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
11 changes: 7 additions & 4 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
cls,
data: DatetimeIndex
| Sequence[np.datetime64 | datetime]
| dict[HashableT1, np.datetime64 | datetime]
| np.datetime64
| datetime,
index: Axes | None = ...,
Expand Down Expand Up @@ -261,6 +262,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
cls,
data: TimedeltaIndex
| Sequence[np.timedelta64 | timedelta]
| dict[HashableT1, np.timedelta64 | timedelta]
| np.timedelta64
| timedelta,
index: Axes | None = ...,
Expand All @@ -274,7 +276,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
cls,
data: IntervalIndex[Interval[_OrderableT]]
| Interval[_OrderableT]
| Sequence[Interval[_OrderableT]],
| Sequence[Interval[_OrderableT]]
| dict[HashableT1, Interval[_OrderableT]],
index: Axes | None = ...,
*,
dtype: Literal["Interval"] = ...,
Expand All @@ -284,7 +287,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: Scalar | _ListLike | dict[int, Any] | dict[_str, Any] | None,
data: Scalar | _ListLike | dict[HashableT1, Any] | None,
index: Axes | None = ...,
*,
dtype: type[S1],
Expand All @@ -294,7 +297,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: S1 | _ListLike[S1] | dict[int, S1] | dict[_str, S1],
data: S1 | _ListLike[S1] | dict[HashableT1, S1],
index: Axes | None = ...,
*,
dtype: Dtype = ...,
Expand All @@ -304,7 +307,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: Scalar | _ListLike | dict[int, Any] | dict[_str, Any] | None = ...,
data: Scalar | _ListLike | dict[HashableT1, Any] | None = ...,
index: Axes | None = ...,
*,
dtype: Dtype = ...,
Expand Down
29 changes: 29 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,35 @@ def test_series_new_empty() -> None:
check(assert_type(pd.Series(), "pd.Series[Any]"), pd.Series)


def test_series_mapping() -> None:
# GH 831
check(
assert_type(
pd.Series(
{
pd.Timestamp(2023, 1, 2): "b",
}
),
"pd.Series[str]",
),
pd.Series,
str,
)

check(
assert_type(
pd.Series(
{
("a", "b"): "c",
}
),
"pd.Series[str]",
),
pd.Series,
str,
)


def test_timedeltaseries_operators() -> None:
series = pd.Series([pd.Timedelta(days=1)])
check(
Expand Down