Skip to content
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
42 changes: 41 additions & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
copy: bool = ...,
) -> IntervalSeries[_OrderableT]: ...
@overload
def __new__(
def __new__( # type: ignore[overload-overlap]
cls,
data: Scalar | _ListLike | dict[HashableT1, Any] | None,
index: Axes | None = ...,
Expand All @@ -353,6 +353,46 @@ class Series(IndexOpsMixin[S1], NDFrame):
copy: bool = ...,
) -> Self: ...
@overload
def __new__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
cls,
data: Sequence[bool],
index: Axes | None = ...,
*,
dtype: Dtype = ...,
name: Hashable = ...,
copy: bool = ...,
) -> Series[bool]: ...
@overload
def __new__( # type: ignore[overload-overlap]
cls,
data: Sequence[int],
index: Axes | None = ...,
*,
dtype: Dtype = ...,
name: Hashable = ...,
copy: bool = ...,
) -> Series[int]: ...
@overload
def __new__(
cls,
data: Sequence[float],
index: Axes | None = ...,
*,
dtype: Dtype = ...,
name: Hashable = ...,
copy: bool = ...,
) -> Series[float]: ...
@overload
def __new__( # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
cls,
data: Sequence[int | float],
index: Axes | None = ...,
*,
dtype: Dtype = ...,
name: Hashable = ...,
copy: bool = ...,
) -> Series[float]: ...
@overload
def __new__(
cls,
data: S1 | _ListLike[S1] | dict[HashableT1, S1] | dict_keys[S1, Any],
Expand Down
13 changes: 13 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3539,3 +3539,16 @@ def test_series_dict() -> None:
pd.Series,
str,
)


def test_series_int_float() -> None:
# pyright infers mixtures of int and float in a list as list[int | float]
check(assert_type(pd.Series([1, 2, 3]), "pd.Series[int]"), pd.Series, np.integer)
check(
assert_type(pd.Series([1.0, 2.0, 3.0]), "pd.Series[float]"),
pd.Series,
np.float64,
)
check(
assert_type(pd.Series([1, 2.0, 3]), "pd.Series[float]"), pd.Series, np.float64
)
Loading