Skip to content

feat(series): add and truediv for bools #1314

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

Merged
merged 10 commits into from
Aug 13, 2025
179 changes: 134 additions & 45 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ from pandas.core.dtypes.dtypes import CategoricalDtype

from pandas.plotting import PlotAccessor

_T_NUM_NON_BOOL = TypeVar("_T_NUM_NON_BOOL", int, float, complex)
_T_INT = TypeVar("_T_INT", bound=int)
_T_COMPLEX = TypeVar("_T_COMPLEX", bound=complex)

Expand Down Expand Up @@ -2097,27 +2098,56 @@ class Series(IndexOpsMixin[S1], NDFrame):
def __sub__(self, other: num | _ListLike | Series) -> Series: ...
@overload
def __truediv__(
self: Series[Never], other: Scalar | _ListLike | Series
self: Series[Never], other: complex | _ListLike | Series
) -> Series: ...
@overload
def __truediv__(self, other: Series[Never]) -> Series: ...
@overload
def __truediv__(self: Series[bool], other: bool | np_ndarray_bool) -> Never: ...
@overload
def __truediv__( # pyright: ignore[reportOverlappingOverload]
self: Series[bool],
other: (
float
| Sequence[float]
| np_ndarray_anyint
| np_ndarray_float
| Series[int]
| Series[float]
),
) -> Series[float]: ...
@overload
def __truediv__(
self: Series[bool], other: complex | Sequence[complex] | Series[complex]
) -> Series[complex]: ...
@overload
def __truediv__(
self: Series[int],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
other: (
_T_INT
| Sequence[_T_INT]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Series[_T_INT]
),
) -> Series[float]: ...
@overload
def __truediv__(
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX]
self: Series[int],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
) -> Series[_T_COMPLEX]: ...
@overload
def __truediv__(
self: Series[int], other: np_ndarray_complex
) -> Series[complex]: ...
@overload
def __truediv__(
self: Series[float],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
other: (
_T_INT
| Sequence[_T_INT]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Series[_T_INT]
),
) -> Series[float]: ...
@overload
def __truediv__(
Expand All @@ -2126,17 +2156,17 @@ class Series(IndexOpsMixin[S1], NDFrame):
) -> Series[_T_COMPLEX]: ...
@overload
def __truediv__(
self: Series[float], other: np_ndarray_complex
self: Series[_T_COMPLEX], other: np_ndarray_complex
) -> Series[complex]: ...
@overload
def __truediv__(
self: Series[complex],
other: (
_T_COMPLEX
| Sequence[_T_COMPLEX]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| Series[_T_COMPLEX]
),
) -> Series[complex]: ...
Expand All @@ -2145,13 +2175,13 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def truediv(
self: Series[Never],
other: Scalar | _ListLike | Series,
other: complex | _ListLike | Series,
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series: ...
@overload
def truediv(
def truediv( # type: ignore[overload-overlap]
self,
other: Series[Never],
level: Level | None = None,
Expand All @@ -2160,28 +2190,51 @@ class Series(IndexOpsMixin[S1], NDFrame):
) -> Series: ...
@overload
def truediv(
self: Series[int],
self: Series[bool],
other: bool | np_ndarray_bool | Series[bool],
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Never: ...
@overload
def truediv(
self: Series[bool],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[float]: ...
@overload
def truediv( # type: ignore[overload-overlap]
self: Series[bool],
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[_T_NUM_NON_BOOL]: ...
@overload
def truediv(
self: Series[int],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
other: (
_T_INT
| Sequence[_T_INT]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Series[_T_INT]
),
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[_T_COMPLEX]: ...
) -> Series[float]: ...
@overload
def truediv(
self: Series[int],
other: np_ndarray_complex,
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[complex]: ...
) -> Series[_T_COMPLEX]: ...
@overload
def truediv(
self: Series[float],
Expand All @@ -2200,7 +2253,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
) -> Series[_T_COMPLEX]: ...
@overload
def truediv(
self: Series[float],
self: Series[_T_COMPLEX],
other: np_ndarray_complex,
level: Level | None = None,
fill_value: float | None = None,
Expand All @@ -2212,9 +2265,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
other: (
_T_COMPLEX
| Sequence[_T_COMPLEX]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| Series[_T_COMPLEX]
),
level: Level | None = None,
Expand All @@ -2231,20 +2284,33 @@ class Series(IndexOpsMixin[S1], NDFrame):
) -> Series: ...
div = truediv
@overload
def __rtruediv__(self: Series[Never], other: Scalar | _ListLike) -> Series: ...
def __rtruediv__(self: Series[Never], other: complex | _ListLike) -> Series: ...
@overload
def __rtruediv__(self: Series[bool], other: bool | np_ndarray_bool) -> Never: ...
@overload
def __rtruediv__(
self: Series[int],
self: Series[bool],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float,
) -> Series[float]: ...
@overload
def __rtruediv__( # type: ignore[overload-overlap]
self: Series[bool], other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL]
) -> Series[_T_NUM_NON_BOOL]: ...
@overload
def __rtruediv__(
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX]
) -> Series[_T_COMPLEX]: ...
self: Series[int],
other: (
_T_INT
| Sequence[_T_INT]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
),
) -> Series[float]: ...
@overload
def __rtruediv__(
self: Series[int], other: np_ndarray_complex
) -> Series[complex]: ...
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX]
) -> Series[_T_COMPLEX]: ...
@overload
def __rtruediv__(
self: Series[float],
Expand All @@ -2255,54 +2321,77 @@ class Series(IndexOpsMixin[S1], NDFrame):
self: Series[float], other: _T_COMPLEX | Sequence[_T_COMPLEX]
Copy link
Collaborator

Choose a reason for hiding this comment

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

rtruediv() has Series[_T_COMPLEX] for other - please reconcile

) -> Series[_T_COMPLEX]: ...
@overload
def __rtruediv__(
self: Series[float], other: np_ndarray_complex
) -> Series[complex]: ...
@overload
def __rtruediv__(
self: Series[complex],
other: (
_T_COMPLEX
| Sequence[_T_COMPLEX]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
),
) -> Series[complex]: ...
@overload
def __rtruediv__(
self: Series[_T_COMPLEX], other: np_ndarray_complex
) -> Series[complex]: ...
@overload
def __rtruediv__(self, other: Path) -> Series: ...
@overload
def rtruediv(
self: Series[Never],
other: Scalar | _ListLike | Series,
other: complex | _ListLike | Series,
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series: ...
@overload
def rtruediv(
self: Series[int],
self: Series[bool],
other: bool | np_ndarray_bool | Series[bool],
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Never: ...
@overload
def rtruediv(
self: Series[bool],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[float]: ...
@overload
def rtruediv( # type: ignore[overload-overlap]
self: Series[bool],
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[_T_NUM_NON_BOOL]: ...
@overload
def rtruediv(
self: Series[int],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
other: (
_T_INT
| Sequence[_T_INT]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Series[_T_INT]
),
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[_T_COMPLEX]: ...
) -> Series[float]: ...
@overload
def rtruediv(
self: Series[int],
other: np_ndarray_complex,
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[complex]: ...
) -> Series[_T_COMPLEX]: ...
@overload
def rtruediv(
self: Series[float],
Expand All @@ -2320,29 +2409,29 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex = 0,
) -> Series[_T_COMPLEX]: ...
@overload
def rtruediv(
self: Series[float],
other: np_ndarray_complex,
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[complex]: ...
@overload
def rtruediv(
self: Series[complex],
other: (
_T_COMPLEX
| Sequence[_T_COMPLEX]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| Series[_T_COMPLEX]
),
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[complex]: ...
@overload
def rtruediv(
self: Series[_T_COMPLEX],
other: np_ndarray_complex,
level: Level | None = None,
fill_value: float | None = None,
axis: AxisIndex = 0,
) -> Series[complex]: ...
@overload
def rtruediv(
self,
other: Path,
Expand Down
Loading
Loading