Skip to content

Commit a3cc1fb

Browse files
committed
fix: fix Series construction with data as an iterator
1 parent 2f63354 commit a3cc1fb

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

pandas-stubs/core/series.pyi

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
294294
@overload
295295
def __new__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
296296
cls,
297-
data: Sequence[Never],
297+
data: Iterator[Never],
298298
index: AxesData | None = ...,
299299
dtype: Dtype = ...,
300300
name: Hashable = ...,
@@ -303,7 +303,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
303303
@overload
304304
def __new__(
305305
cls,
306-
data: Sequence[list[_str]],
306+
data: Iterator[list[_str]],
307307
index: AxesData | None = ...,
308308
dtype: Dtype = ...,
309309
name: Hashable = ...,
@@ -312,7 +312,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
312312
@overload
313313
def __new__(
314314
cls,
315-
data: Sequence[_str],
315+
data: Iterator[_str],
316316
index: AxesData | None = ...,
317317
dtype: Dtype = ...,
318318
name: Hashable = ...,
@@ -323,7 +323,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
323323
cls,
324324
data: (
325325
DatetimeIndex
326-
| Sequence[np.datetime64 | datetime | date]
326+
| Iterator[np.datetime64 | datetime | date]
327327
| dict[HashableT1, np.datetime64 | datetime | date]
328328
| np.datetime64
329329
| datetime
@@ -337,7 +337,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
337337
@overload
338338
def __new__(
339339
cls,
340-
data: _ListLike,
340+
data: _ListLike | Iterator[S1],
341341
index: AxesData | None = ...,
342342
*,
343343
dtype: TimestampDtypeArg,
@@ -347,7 +347,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
347347
@overload
348348
def __new__(
349349
cls,
350-
data: PeriodIndex | Sequence[Period],
350+
data: PeriodIndex | Iterator[Period],
351351
index: AxesData | None = ...,
352352
dtype: PeriodDtype = ...,
353353
name: Hashable = ...,
@@ -358,7 +358,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
358358
cls,
359359
data: (
360360
TimedeltaIndex
361-
| Sequence[np.timedelta64 | timedelta]
361+
| Iterator[np.timedelta64 | timedelta]
362362
| dict[HashableT1, np.timedelta64 | timedelta]
363363
| np.timedelta64
364364
| timedelta
@@ -374,7 +374,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
374374
data: (
375375
IntervalIndex[Interval[_OrderableT]]
376376
| Interval[_OrderableT]
377-
| Sequence[Interval[_OrderableT]]
377+
| Iterator[Interval[_OrderableT]]
378378
| dict[HashableT1, Interval[_OrderableT]]
379379
),
380380
index: AxesData | None = ...,
@@ -385,7 +385,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
385385
@overload
386386
def __new__( # type: ignore[overload-overlap]
387387
cls,
388-
data: Scalar | _ListLike | dict[HashableT1, Any] | None,
388+
data: Scalar | _ListLike | Iterator[S1] | dict[HashableT1, Any] | None,
389389
index: AxesData | None = ...,
390390
*,
391391
dtype: type[S1],
@@ -395,7 +395,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
395395
@overload
396396
def __new__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
397397
cls,
398-
data: Sequence[bool],
398+
data: Iterator[bool],
399399
index: AxesData | None = ...,
400400
dtype: Dtype = ...,
401401
name: Hashable = ...,
@@ -404,7 +404,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
404404
@overload
405405
def __new__( # type: ignore[overload-overlap]
406406
cls,
407-
data: Sequence[int],
407+
data: Iterator[int],
408408
index: AxesData | None = ...,
409409
dtype: Dtype = ...,
410410
name: Hashable = ...,
@@ -413,7 +413,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
413413
@overload
414414
def __new__(
415415
cls,
416-
data: Sequence[float],
416+
data: Iterator[float],
417417
index: AxesData | None = ...,
418418
dtype: Dtype = ...,
419419
name: Hashable = ...,
@@ -422,7 +422,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
422422
@overload
423423
def __new__( # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
424424
cls,
425-
data: Sequence[int | float],
425+
data: Iterator[int | float],
426426
index: AxesData | None = ...,
427427
dtype: Dtype = ...,
428428
name: Hashable = ...,
@@ -445,6 +445,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
445445
data: (
446446
Scalar
447447
| _ListLike
448+
| Iterator[S1]
448449
| Mapping[HashableT1, Any]
449450
| BaseGroupBy
450451
| NaTType

tests/series/test_series.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
def test_types_init() -> None:
123123
pd.Series(1)
124124
pd.Series((1, 2, 3))
125+
pd.Series(iter((1, 2, 3)))
125126
pd.Series(np.array([1, 2, 3]))
126127
pd.Series(pd.NaT)
127128
pd.Series(pd.NA)
@@ -155,6 +156,11 @@ def test_types_init() -> None:
155156
pd.Series,
156157
float,
157158
)
159+
check(
160+
assert_type(pd.Series(iter([1.0])), "pd.Series[float]"),
161+
pd.Series,
162+
float,
163+
)
158164

159165

160166
def test_types_any() -> None:

0 commit comments

Comments
 (0)