Skip to content
Prev Previous commit
Next Next commit
fix(typing): truediv path
  • Loading branch information
cmp0xff committed Aug 1, 2025
commit 6a281458fcdd9dc6aae66aacd8cdd3305c35fd18
32 changes: 24 additions & 8 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1745,9 +1745,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
def __ror__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ...
def __rsub__(self, other: num | _ListLike | Series[S1]) -> Series: ...
@overload
def __rtruediv__(
self: Series[Never], other: Path | Scalar | _ListLike
) -> Series: ...
def __rtruediv__(self: Series[Never], other: Scalar | _ListLike) -> Series: ...
@overload
def __rtruediv__(
self: Series[int],
Expand Down Expand Up @@ -1812,7 +1810,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
def __sub__(self, other: num | _ListLike | Series) -> Series: ...
@overload
def __truediv__(
self: Series[Never], other: Path | Scalar | _ListLike | Series
self: Series[Never], other: Scalar | _ListLike | Series
) -> Series: ...
@overload
def __truediv__(self, other: Series[Never]) -> Series: ...
Expand Down Expand Up @@ -1855,6 +1853,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
| Series[_T_COMPLEX]
),
) -> Series[complex]: ...
@overload
def __truediv__(self, other: Path) -> Series: ...
# ignore needed for mypy as we want different results based on the arguments
@overload # type: ignore[override]
def __xor__( # pyright: ignore[reportOverlappingOverload]
Expand Down Expand Up @@ -2362,7 +2362,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def rtruediv(
self: Series[Never],
other: Path | Scalar | _ListLike | Series,
other: Scalar | _ListLike | Series,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
Expand Down Expand Up @@ -2441,7 +2441,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def rdiv(
self: Series[Never],
other: Path | Scalar | _ListLike | Series,
other: Scalar | _ListLike | Series,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
Expand Down Expand Up @@ -2603,7 +2603,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def truediv(
self: Series[Never],
other: Path | Scalar | _ListLike | Series,
other: Scalar | _ListLike | Series,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
Expand Down Expand Up @@ -2680,9 +2680,17 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex = ...,
) -> Series[complex]: ...
@overload
def truediv(
self,
other: Path,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
) -> Series: ...
@overload
def div(
self: Series[Never],
other: Path | Scalar | _ListLike | Series,
other: Scalar | _ListLike | Series,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
Expand Down Expand Up @@ -2758,6 +2766,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
fill_value: float | None = ...,
axis: AxisIndex = ...,
) -> Series[complex]: ...
@overload
def div(
self,
other: Path,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
) -> Series: ...
def var(
self,
axis: AxisIndex | None = ...,
Expand Down
15 changes: 15 additions & 0 deletions tests/series/arithmetic/test_truediv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

import numpy as np
from numpy import typing as npt # noqa: F401
import pandas as pd
from typing_extensions import assert_type

Expand Down Expand Up @@ -137,3 +138,17 @@ def test_truediv_pd_series() -> None:
check(assert_type(left.rdiv(i), pd.Series), pd.Series)
check(assert_type(left.rdiv(f), pd.Series), pd.Series)
check(assert_type(left.rdiv(c), pd.Series), pd.Series)


def test_truediv_path() -> None:
"""Test pd.Series / path object"""
left, p = pd.Series(["pat", "ath", "path"]), Path()

check(assert_type(left / p, pd.Series), pd.Series, Path)
check(assert_type(p / left, pd.Series), pd.Series, Path)

check(assert_type(left.truediv(p), pd.Series), pd.Series, Path)
check(assert_type(left.div(p), pd.Series), pd.Series, Path)

check(assert_type(left.rtruediv(p), pd.Series), pd.Series, Path)
check(assert_type(left.rdiv(p), pd.Series), pd.Series, Path)
Loading