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
38 changes: 16 additions & 22 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -784,21 +784,18 @@ class Index(IndexOpsMixin[S1]):
@overload
def __mul__(
self: Index[_str],
other: np_ndarray_float | np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
other: (
np_ndarray_bool
| np_ndarray_float
| np_ndarray_complex
| np_ndarray_dt
| np_ndarray_td
),
) -> Never: ...
# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
@overload
def __mul__(
self: Index[_str],
other: (
int
| Sequence[int]
| np_ndarray_bool
| np_ndarray_anyint
| Index[bool]
| Index[int]
),
other: Just[int] | Sequence[Just[int]] | np_ndarray_anyint | Index[int],
) -> Index[_str]: ...
@overload
def __mul__(self: Index[T_INT], other: bool | Sequence[bool]) -> Index[T_INT]: ...
Expand Down Expand Up @@ -877,21 +874,18 @@ class Index(IndexOpsMixin[S1]):
@overload
def __rmul__(
self: Index[_str],
other: np_ndarray_float | np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
other: (
np_ndarray_bool
| np_ndarray_float
| np_ndarray_complex
| np_ndarray_dt
| np_ndarray_td
),
) -> Never: ...
# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
@overload
def __rmul__(
self: Index[_str],
other: (
int
| Sequence[int]
| np_ndarray_bool
| np_ndarray_anyint
| Index[bool]
| Index[int]
),
other: Just[int] | Sequence[Just[int]] | np_ndarray_anyint | Index[int],
) -> Index[_str]: ...
@overload
def __rmul__(self: Index[T_INT], other: bool | Sequence[bool]) -> Index[T_INT]: ...
Expand Down
52 changes: 22 additions & 30 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2586,21 +2586,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __mul__(
self: Series[_str],
other: np_ndarray_float | np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
other: (
np_ndarray_bool
| np_ndarray_float
| np_ndarray_complex
| np_ndarray_dt
| np_ndarray_td
),
) -> Never: ...
# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
@overload
def __mul__(
self: Series[_str],
other: (
int
| Sequence[int]
| np_ndarray_bool
Just[int]
| Sequence[Just[int]]
| np_ndarray_anyint
| Index[bool]
| Index[int]
| Series[bool]
| Series[int]
),
) -> Series[_str]: ...
Expand Down Expand Up @@ -2696,19 +2697,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
fill_value: float | None = None,
axis: AxisIndex | None = 0,
) -> Series[Timedelta]: ...
# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
@overload
def mul(
self: Series[_str],
other: (
int
| Sequence[int]
| np_ndarray_bool
Just[int]
| Sequence[Just[int]]
| np_ndarray_anyint
| Index[bool]
| Index[int]
| Series[bool]
| Series[int]
),
level: Level | None = None,
Expand Down Expand Up @@ -2843,21 +2839,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __rmul__(
self: Series[_str],
other: np_ndarray_float | np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
other: (
np_ndarray_bool
| np_ndarray_float
| np_ndarray_complex
| np_ndarray_dt
| np_ndarray_td
),
) -> Never: ...
# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
@overload
def __rmul__(
self: Series[_str],
other: (
int
| Sequence[int]
| np_ndarray_bool
Just[int]
| Sequence[Just[int]]
| np_ndarray_anyint
| Index[bool]
| Index[int]
| Series[bool]
| Series[int]
),
) -> Series[_str]: ...
Expand Down Expand Up @@ -2955,19 +2952,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
fill_value: float | None = None,
axis: AxisIndex | None = 0,
) -> Series[Timedelta]: ...
# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
@overload
def rmul(
self: Series[_str],
other: (
int
| Sequence[int]
| np_ndarray_bool
Just[int]
| Sequence[Just[int]]
| np_ndarray_anyint
| Index[bool]
| Index[int]
| Series[bool]
| Series[int]
),
level: Level | None = None,
Expand Down
41 changes: 16 additions & 25 deletions tests/indexes/arithmetic/str/test_mul.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
)

from tests import (
PD_LTE_23,
TYPE_CHECKING_INVALID_USAGE,
check,
)
Expand All @@ -32,19 +31,17 @@ def test_mul_py_scalar(left: "pd.Index[str]") -> None:
b, i, f, c = True, 1, 1.0, 1j
s, d = datetime(2025, 9, 27), timedelta(seconds=1)

# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
if PD_LTE_23:
check(assert_type(left * b, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
check(assert_type(left * i, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_02 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_04 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_05 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

if PD_LTE_23:
check(assert_type(b * left, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
check(assert_type(i * left, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_12 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
Expand All @@ -59,19 +56,17 @@ def test_mul_py_sequence(left: "pd.Index[str]") -> None:
s = [datetime(2025, 9, d) for d in (27, 28, 29)]
d = [timedelta(seconds=s + 1) for s in range(3)]

# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
if PD_LTE_23:
check(assert_type(left * b, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
check(assert_type(left * i, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_02 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_04 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_05 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

if PD_LTE_23:
check(assert_type(b * left, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
check(assert_type(i * left, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_12 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
Expand All @@ -89,10 +84,8 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None:
s = np.array([np.datetime64(f"2025-09-{d}") for d in (27, 28, 29)], np.datetime64)
d = np.array([np.timedelta64(s + 1, "s") for s in range(3)], np.timedelta64)

# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
if PD_LTE_23:
check(assert_type(left * b, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(left * b, Never)
check(assert_type(left * i, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(left * f, Never)
Expand All @@ -103,8 +96,8 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None:
# `numpy` typing gives the corresponding `ndarray`s in the static type
# checking, where our `__rmul__` cannot override. At runtime, they return
# `Index` with the correct element type.
if PD_LTE_23:
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(b * left, "npt.NDArray[np.bool_]")
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
assert_type(f * left, "npt.NDArray[np.float64]")
Expand All @@ -122,19 +115,17 @@ def test_mul_pd_index(left: "pd.Index[str]") -> None:
s = pd.Index([datetime(2025, 9, d) for d in (27, 28, 29)])
d = pd.Index([timedelta(seconds=s + 1) for s in range(3)])

# pandas-dev/pandas#62595: we may want to support Series[str] * bool
# also in 3.x
if PD_LTE_23:
check(assert_type(left * b, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
check(assert_type(left * i, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_02 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_04 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_05 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

if PD_LTE_23:
check(assert_type(b * left, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
check(assert_type(i * left, "pd.Index[str]"), pd.Index, str)
if TYPE_CHECKING_INVALID_USAGE:
_12 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
Expand Down
Loading