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
2 changes: 1 addition & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
# just failed to generate these so I couldn't match
# them up.
@overload
def __add__(self: Series[Never], other: complex | ListLike) -> Series: ...
def __add__(self: Series[Never], other: _str | complex | ListLike) -> Series: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you create an overload that says if other: _str, the result is Series[str] ?

@overload
def __add__(self, other: Index[Never] | Series[Never]) -> Series: ...
@overload
Expand Down
8 changes: 8 additions & 0 deletions tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4080,3 +4080,11 @@ def test_series_index_setter() -> None:
check(assert_type(sr.index, pd.Index), pd.Index)
sr.index = [2, 3]
check(assert_type(sr.index, pd.Index), pd.Index)


def test_series_add_str() -> None:
"""Test Series.__add__ with Series[Any]."""
df = pd.DataFrame({0: ["a", "b"]})
sr = df[0]

check(assert_type(sr + "c1", pd.Series), pd.Series, str)
Comment on lines +4083 to +4090
Copy link
Contributor

Choose a reason for hiding this comment

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

Plesae move the new test to tests\series\arithmetic\test_add.py and make use of left_str.

Probably we need to make the same valid tests in tests\series\arithmetic\str\test_add.py (excluding the TYPE_CHECKING_INVALID_USAGE ones) work for Series[Any].

For consistency, we probably also need to make Index[Any] + str etc. work