Skip to content

feat(series): #1098 arithmetic addition #1275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
236 changes: 236 additions & 0 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ from typing import (
Generic,
Literal,
NoReturn,
TypeVar,
overload,
)

Expand Down Expand Up @@ -174,6 +175,8 @@ from pandas._typing import (
VoidDtypeArg,
WriteBuffer,
np_ndarray_anyint,
np_ndarray_complex,
np_ndarray_float,
npt,
num,
)
Expand All @@ -183,6 +186,8 @@ from pandas.core.dtypes.dtypes import CategoricalDtype

from pandas.plotting import PlotAccessor

_T_COMPLEX = TypeVar("_T_COMPLEX", bound=complex)

class _iLocIndexerSeries(_iLocIndexer, Generic[S1]):
# get item
@overload
Expand Down Expand Up @@ -1580,6 +1585,47 @@ class Series(IndexOpsMixin[S1], NDFrame):
# just failed to generate these so I couldn't match
# them up.
@overload
def __add__(
self: Series[Never],
other: num | _str | timedelta | Timedelta | _ListLike | Series | np.timedelta64,
) -> Series: ...
@overload
def __add__(self: Series, other: Series[Never]) -> Series: ...
@overload
def __add__(
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX]
) -> Series[_T_COMPLEX]: ...
@overload
def __add__(self: Series[int], other: np_ndarray_anyint) -> Series[int]: ...
@overload
def __add__(self: Series[int], other: np_ndarray_float) -> Series[float]: ...
@overload
def __add__(self: Series[int], other: np_ndarray_complex) -> Series[complex]: ...
@overload
def __add__(
self: Series[float],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
) -> Series[float]: ...
@overload
def __add__(
self: Series[float],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
) -> Series[_T_COMPLEX]: ...
@overload
def __add__(self: Series[float], other: np_ndarray_complex) -> Series[complex]: ...
@overload
def __add__(
self: Series[complex],
other: (
_T_COMPLEX
| Sequence[_T_COMPLEX]
| Series[_T_COMPLEX]
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
),
) -> Series[complex]: ...
@overload
def __add__(self, other: S1 | Self) -> Self: ...
@overload
def __add__(
Expand Down Expand Up @@ -1626,6 +1672,24 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __or__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ...
@overload
def __radd__(
self: Series[Never], other: num | _str | _ListLike | Series
) -> Series: ...
@overload
def __radd__(
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX]
) -> Series[_T_COMPLEX]: ...
@overload
def __radd__(self: Series[float], other: int | Sequence[int]) -> Series[float]: ...
@overload
def __radd__(
self: Series[float], other: _T_COMPLEX | Sequence[_T_COMPLEX]
) -> Series[_T_COMPLEX]: ...
@overload
def __radd__(
self: Series[complex], other: complex | Sequence[complex]
) -> Series[complex]: ...
@overload
def __radd__(self, other: S1 | Series[S1]) -> Self: ...
@overload
def __radd__(self, other: num | _str | _ListLike | Series) -> Series: ...
Expand Down Expand Up @@ -1703,6 +1767,92 @@ class Series(IndexOpsMixin[S1], NDFrame):
@property
def loc(self) -> _LocIndexerSeries[S1]: ...
# Methods
@overload
def add(
self: Series[Never],
other: (
Sequence
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| Series
| Scalar
),
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series: ...
@overload
def add(
self: Series[int],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[_T_COMPLEX]: ...
@overload
def add(
self: Series[int],
other: np_ndarray_anyint,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[int]: ...
@overload
def add(
self: Series[int],
other: np_ndarray_float,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[float]: ...
@overload
def add(
self: Series[int],
other: np_ndarray_complex,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[complex]: ...
@overload
def add(
self: Series[float],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[float]: ...
@overload
def add(
self: Series[float],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[_T_COMPLEX]: ...
@overload
def add(
self: Series[float],
other: np_ndarray_complex,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[complex]: ...
@overload
def add(
self: Series[complex],
other: (
Sequence[_T_COMPLEX]
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| Series[_T_COMPLEX]
),
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[complex]: ...
@overload
def add(
self,
other: Series[S1] | Scalar,
Expand Down Expand Up @@ -1945,6 +2095,92 @@ class Series(IndexOpsMixin[S1], NDFrame):
min_count: int = ...,
**kwargs: Any,
) -> Scalar: ...
@overload
def radd(
self: Series[Never],
other: (
Sequence
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| Series
| Scalar
),
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
) -> Series: ...
@overload
def radd(
self: Series[int],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[_T_COMPLEX]: ...
@overload
def radd(
self: Series[int],
other: np_ndarray_anyint,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[int]: ...
@overload
def radd(
self: Series[int],
other: np_ndarray_float,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[float]: ...
@overload
def radd(
self: Series[int],
other: np_ndarray_complex,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[complex]: ...
@overload
def radd(
self: Series[float],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[float]: ...
@overload
def radd(
self: Series[float],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[_T_COMPLEX]: ...
@overload
def radd(
self: Series[float],
other: np_ndarray_complex,
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[complex]: ...
@overload
def radd(
self: Series[complex],
other: (
Sequence[_T_COMPLEX]
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| Series[_T_COMPLEX]
),
level: Level | None = ...,
fill_value: float | None = ...,
axis: int = ...,
) -> Series[complex]: ...
@overload
def radd(
self,
other: Series[S1] | Scalar,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ types-pytz = ">= 2022.1.1"
numpy = ">= 1.23.5"

[tool.poetry.group.dev.dependencies]
mypy = "1.16.0"
mypy = ">=1.17.0"
pandas = "2.3.0"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = ">=1.1.400"
pyright = ">=1.1.403"
ty = "^0.0.1a8"
pyrefly = "^0.21.0"
poethepoet = ">=0.16.5"
Expand Down
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def check(
if not isinstance(actual, klass):
raise RuntimeError(f"Expected type '{klass}' but got '{type(actual)}'")
if dtype is None:
return actual # type: ignore[return-value]
return actual

if isinstance(actual, pd.Series):
value = actual.iloc[index_to_check_for_type]
Expand All @@ -82,7 +82,7 @@ def check(

if not isinstance(value, dtype):
raise RuntimeError(f"Expected type '{dtype}' but got '{type(value)}'")
return actual # type: ignore[return-value]
return actual


def pytest_warns_bounded(
Expand Down
Empty file added tests/series/__init__.py
Empty file.
Empty file.
Empty file.
Loading
Loading