Skip to content

Commit 72b22b5

Browse files
authored
Series(Mapping) (#843)
* Series(Mapping) * Hashable keys * empty * incremental changes * _str
1 parent 52384d3 commit 72b22b5

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

pandas-stubs/core/series.pyi

+7-4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
228228
cls,
229229
data: DatetimeIndex
230230
| Sequence[np.datetime64 | datetime]
231+
| dict[HashableT1, np.datetime64 | datetime]
231232
| np.datetime64
232233
| datetime,
233234
index: Axes | None = ...,
@@ -261,6 +262,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
261262
cls,
262263
data: TimedeltaIndex
263264
| Sequence[np.timedelta64 | timedelta]
265+
| dict[HashableT1, np.timedelta64 | timedelta]
264266
| np.timedelta64
265267
| timedelta,
266268
index: Axes | None = ...,
@@ -274,7 +276,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
274276
cls,
275277
data: IntervalIndex[Interval[_OrderableT]]
276278
| Interval[_OrderableT]
277-
| Sequence[Interval[_OrderableT]],
279+
| Sequence[Interval[_OrderableT]]
280+
| dict[HashableT1, Interval[_OrderableT]],
278281
index: Axes | None = ...,
279282
*,
280283
dtype: Literal["Interval"] = ...,
@@ -284,7 +287,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
284287
@overload
285288
def __new__(
286289
cls,
287-
data: Scalar | _ListLike | dict[int, Any] | dict[_str, Any] | None,
290+
data: Scalar | _ListLike | dict[HashableT1, Any] | None,
288291
index: Axes | None = ...,
289292
*,
290293
dtype: type[S1],
@@ -294,7 +297,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
294297
@overload
295298
def __new__(
296299
cls,
297-
data: S1 | _ListLike[S1] | dict[int, S1] | dict[_str, S1],
300+
data: S1 | _ListLike[S1] | dict[HashableT1, S1],
298301
index: Axes | None = ...,
299302
*,
300303
dtype: Dtype = ...,
@@ -304,7 +307,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
304307
@overload
305308
def __new__(
306309
cls,
307-
data: Scalar | _ListLike | dict[int, Any] | dict[_str, Any] | None = ...,
310+
data: Scalar | _ListLike | dict[HashableT1, Any] | None = ...,
308311
index: Axes | None = ...,
309312
*,
310313
dtype: Dtype = ...,

tests/test_series.py

+29
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,35 @@ def test_series_new_empty() -> None:
28632863
check(assert_type(pd.Series(), "pd.Series[Any]"), pd.Series)
28642864

28652865

2866+
def test_series_mapping() -> None:
2867+
# GH 831
2868+
check(
2869+
assert_type(
2870+
pd.Series(
2871+
{
2872+
pd.Timestamp(2023, 1, 2): "b",
2873+
}
2874+
),
2875+
"pd.Series[str]",
2876+
),
2877+
pd.Series,
2878+
str,
2879+
)
2880+
2881+
check(
2882+
assert_type(
2883+
pd.Series(
2884+
{
2885+
("a", "b"): "c",
2886+
}
2887+
),
2888+
"pd.Series[str]",
2889+
),
2890+
pd.Series,
2891+
str,
2892+
)
2893+
2894+
28662895
def test_timedeltaseries_operators() -> None:
28672896
series = pd.Series([pd.Timedelta(days=1)])
28682897
check(

0 commit comments

Comments
 (0)