Skip to content
Open
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
27 changes: 14 additions & 13 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
cls,
data: Sequence[Never],
data: Iterator[Never],
index: AxesData | None = ...,
dtype: Dtype = ...,
name: Hashable = ...,
Expand All @@ -303,7 +303,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: Sequence[list[_str]],
data: Iterator[list[_str]],
index: AxesData | None = ...,
dtype: Dtype = ...,
name: Hashable = ...,
Expand All @@ -312,7 +312,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: Sequence[_str],
data: Iterator[_str],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterator[_str] can be ambiguous, because _str is an Iterable in its own right. However, I don't have more insights how to improve this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Iterator[SequenceNotStr[_str]]

index: AxesData | None = ...,
dtype: Dtype = ...,
name: Hashable = ...,
Expand All @@ -323,7 +323,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
cls,
data: (
DatetimeIndex
| Sequence[np.datetime64 | datetime | date]
| Iterator[np.datetime64 | datetime | date]
| dict[HashableT1, np.datetime64 | datetime | date]
| np.datetime64
| datetime
Expand All @@ -337,7 +337,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: _ListLike,
data: _ListLike | Iterator[S1],
index: AxesData | None = ...,
*,
dtype: TimestampDtypeArg,
Expand All @@ -347,7 +347,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: PeriodIndex | Sequence[Period],
data: PeriodIndex | Iterator[Period],
index: AxesData | None = ...,
dtype: PeriodDtype = ...,
name: Hashable = ...,
Expand All @@ -358,7 +358,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
cls,
data: (
TimedeltaIndex
| Sequence[np.timedelta64 | timedelta]
| Iterator[np.timedelta64 | timedelta]
| dict[HashableT1, np.timedelta64 | timedelta]
| np.timedelta64
| timedelta
Expand All @@ -374,7 +374,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
data: (
IntervalIndex[Interval[_OrderableT]]
| Interval[_OrderableT]
| Sequence[Interval[_OrderableT]]
| Iterator[Interval[_OrderableT]]
| dict[HashableT1, Interval[_OrderableT]]
),
index: AxesData | None = ...,
Expand All @@ -385,7 +385,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__( # type: ignore[overload-overlap]
cls,
data: Scalar | _ListLike | dict[HashableT1, Any] | None,
data: Scalar | _ListLike | Iterator[S1] | dict[HashableT1, Any] | None,
index: AxesData | None = ...,
*,
dtype: type[S1],
Expand All @@ -395,7 +395,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
cls,
data: Sequence[bool],
data: Iterator[bool],
index: AxesData | None = ...,
dtype: Dtype = ...,
name: Hashable = ...,
Expand All @@ -404,7 +404,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__( # type: ignore[overload-overlap]
cls,
data: Sequence[int],
data: Iterator[int],
index: AxesData | None = ...,
dtype: Dtype = ...,
name: Hashable = ...,
Expand All @@ -413,7 +413,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__(
cls,
data: Sequence[float],
data: Iterator[float],
index: AxesData | None = ...,
dtype: Dtype = ...,
name: Hashable = ...,
Expand All @@ -422,7 +422,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __new__( # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
cls,
data: Sequence[int | float],
data: Iterator[int | float],
index: AxesData | None = ...,
dtype: Dtype = ...,
name: Hashable = ...,
Expand All @@ -445,6 +445,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
data: (
Scalar
| _ListLike
| Iterator[S1]
| Mapping[HashableT1, Any]
| BaseGroupBy
| NaTType
Expand Down
6 changes: 6 additions & 0 deletions tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
def test_types_init() -> None:
pd.Series(1)
pd.Series((1, 2, 3))
pd.Series(iter((1, 2, 3)))
pd.Series(np.array([1, 2, 3]))
pd.Series(pd.NaT)
pd.Series(pd.NA)
Expand Down Expand Up @@ -155,6 +156,11 @@ def test_types_init() -> None:
pd.Series,
float,
)
check(
assert_type(pd.Series(iter([1.0])), "pd.Series[float]"),
pd.Series,
float,
)
Comment on lines +159 to +163
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several __new__'s have been retyped, but only one test has been added. Please complete the new tests. Alternatively, you can split the old test function into two.



def test_types_any() -> None:
Expand Down