Skip to content

Commit

Permalink
Series(Mapping) (#843)
Browse files Browse the repository at this point in the history
* Series(Mapping)

* Hashable keys

* empty

* incremental changes

* _str
  • Loading branch information
twoertwein committed Dec 26, 2023
1 parent 52384d3 commit 72b22b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
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

0 comments on commit 72b22b5

Please sign in to comment.