Skip to content

Commit fb97790

Browse files
committed
fix(nightly): pytest
1 parent 6443fbf commit fb97790

File tree

7 files changed

+208
-81
lines changed

7 files changed

+208
-81
lines changed

pandas-stubs/core/indexes/base.pyi

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,12 +784,18 @@ class Index(IndexOpsMixin[S1]):
784784
@overload
785785
def __mul__(
786786
self: Index[_str],
787-
other: np_ndarray_float | np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
787+
other: (
788+
np_ndarray_bool
789+
| np_ndarray_float
790+
| np_ndarray_complex
791+
| np_ndarray_dt
792+
| np_ndarray_td
793+
),
788794
) -> Never: ...
789795
@overload
790796
def __mul__(
791797
self: Index[_str],
792-
other: int | Sequence[int] | np_ndarray_bool | np_ndarray_anyint | Index[T_INT],
798+
other: Just[int] | Sequence[Just[int]] | np_ndarray_anyint | Index[int],
793799
) -> Index[_str]: ...
794800
@overload
795801
def __mul__(self: Index[T_INT], other: bool | Sequence[bool]) -> Index[T_INT]: ...
@@ -868,12 +874,18 @@ class Index(IndexOpsMixin[S1]):
868874
@overload
869875
def __rmul__(
870876
self: Index[_str],
871-
other: np_ndarray_float | np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
877+
other: (
878+
np_ndarray_bool
879+
| np_ndarray_float
880+
| np_ndarray_complex
881+
| np_ndarray_dt
882+
| np_ndarray_td
883+
),
872884
) -> Never: ...
873885
@overload
874886
def __rmul__(
875887
self: Index[_str],
876-
other: int | Sequence[int] | np_ndarray_bool | np_ndarray_anyint | Index[T_INT],
888+
other: Just[int] | Sequence[Just[int]] | np_ndarray_anyint | Index[int],
877889
) -> Index[_str]: ...
878890
@overload
879891
def __rmul__(self: Index[T_INT], other: bool | Sequence[bool]) -> Index[T_INT]: ...

pandas-stubs/core/series.pyi

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,18 +2585,23 @@ class Series(IndexOpsMixin[S1], NDFrame):
25852585
@overload
25862586
def __mul__(
25872587
self: Series[_str],
2588-
other: np_ndarray_float | np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
2588+
other: (
2589+
np_ndarray_bool
2590+
| np_ndarray_float
2591+
| np_ndarray_complex
2592+
| np_ndarray_dt
2593+
| np_ndarray_td
2594+
),
25892595
) -> Never: ...
25902596
@overload
25912597
def __mul__(
25922598
self: Series[_str],
25932599
other: (
2594-
int
2595-
| Sequence[int]
2596-
| np_ndarray_bool
2600+
Just[int]
2601+
| Sequence[Just[int]]
25972602
| np_ndarray_anyint
2598-
| Index[T_INT]
2599-
| Series[T_INT]
2603+
| Index[int]
2604+
| Series[int]
26002605
),
26012606
) -> Series[_str]: ...
26022607
@overload
@@ -2695,12 +2700,11 @@ class Series(IndexOpsMixin[S1], NDFrame):
26952700
def mul(
26962701
self: Series[_str],
26972702
other: (
2698-
int
2699-
| Sequence[int]
2700-
| np_ndarray_bool
2703+
Just[int]
2704+
| Sequence[Just[int]]
27012705
| np_ndarray_anyint
2702-
| Index[T_INT]
2703-
| Series[T_INT]
2706+
| Index[int]
2707+
| Series[int]
27042708
),
27052709
level: Level | None = None,
27062710
fill_value: float | None = None,
@@ -2834,18 +2838,23 @@ class Series(IndexOpsMixin[S1], NDFrame):
28342838
@overload
28352839
def __rmul__(
28362840
self: Series[_str],
2837-
other: np_ndarray_float | np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
2841+
other: (
2842+
np_ndarray_bool
2843+
| np_ndarray_float
2844+
| np_ndarray_complex
2845+
| np_ndarray_dt
2846+
| np_ndarray_td
2847+
),
28382848
) -> Never: ...
28392849
@overload
28402850
def __rmul__(
28412851
self: Series[_str],
28422852
other: (
2843-
int
2844-
| Sequence[int]
2845-
| np_ndarray_bool
2853+
Just[int]
2854+
| Sequence[Just[int]]
28462855
| np_ndarray_anyint
2847-
| Index[T_INT]
2848-
| Series[T_INT]
2856+
| Index[int]
2857+
| Series[int]
28492858
),
28502859
) -> Series[_str]: ...
28512860
@overload
@@ -2946,12 +2955,11 @@ class Series(IndexOpsMixin[S1], NDFrame):
29462955
def rmul(
29472956
self: Series[_str],
29482957
other: (
2949-
int
2950-
| Sequence[int]
2951-
| np_ndarray_bool
2958+
Just[int]
2959+
| Sequence[Just[int]]
29522960
| np_ndarray_anyint
2953-
| Index[T_INT]
2954-
| Series[T_INT]
2961+
| Index[int]
2962+
| Series[int]
29552963
),
29562964
level: Level | None = None,
29572965
fill_value: float | None = None,

tests/indexes/arithmetic/bool/test_mul.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515

1616
from tests import (
17+
PD_LTE_23,
1718
TYPE_CHECKING_INVALID_USAGE,
1819
check,
1920
)
@@ -86,7 +87,10 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None:
8687
check(assert_type(left * c, "pd.Index[complex]"), pd.Index, np.complexfloating)
8788
if TYPE_CHECKING_INVALID_USAGE:
8889
assert_type(left * s, Never)
89-
check(assert_type(left * d, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta)
90+
if PD_LTE_23:
91+
# pandas-dev/pandas#62316: both timedelta * bool
92+
# and np.timedelta64 * bool works, so pandas probably also should work
93+
check(assert_type(left * d, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta)
9094

9195
# `numpy` typing gives the corresponding `ndarray`s in the static type
9296
# checking, where our `__rmul__` cannot override. At runtime, they return
@@ -101,11 +105,14 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None:
101105
)
102106
if TYPE_CHECKING_INVALID_USAGE:
103107
assert_type(s * left, Any)
104-
check(
105-
assert_type(d * left, "npt.NDArray[np.timedelta64]"),
106-
pd.TimedeltaIndex,
107-
pd.Timedelta,
108-
)
108+
if PD_LTE_23:
109+
# pandas-dev/pandas#62316: both timedelta * bool
110+
# and np.timedelta64 * bool works, so pandas probably also should work
111+
check(
112+
assert_type(d * left, "npt.NDArray[np.timedelta64]"),
113+
pd.TimedeltaIndex,
114+
pd.Timedelta,
115+
)
109116

110117

111118
def test_mul_pd_index(left: "pd.Index[bool]") -> None:
@@ -123,12 +130,18 @@ def test_mul_pd_index(left: "pd.Index[bool]") -> None:
123130
check(assert_type(left * c, "pd.Index[complex]"), pd.Index, np.complexfloating)
124131
if TYPE_CHECKING_INVALID_USAGE:
125132
_05 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
126-
check(assert_type(left * d, pd.TimedeltaIndex), pd.Index, timedelta)
133+
if PD_LTE_23:
134+
# pandas-dev/pandas#62316: both timedelta * bool
135+
# and np.timedelta64 * bool works, so pandas probably also should work
136+
check(assert_type(left * d, pd.TimedeltaIndex), pd.Index, timedelta)
127137

128138
check(assert_type(b * left, "pd.Index[bool]"), pd.Index, np.bool_)
129139
check(assert_type(i * left, "pd.Index[int]"), pd.Index, np.integer)
130140
check(assert_type(f * left, "pd.Index[float]"), pd.Index, np.floating)
131141
check(assert_type(c * left, "pd.Index[complex]"), pd.Index, np.complexfloating)
132142
if TYPE_CHECKING_INVALID_USAGE:
133143
_15 = s * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
134-
check(assert_type(d * left, pd.TimedeltaIndex), pd.Index, timedelta)
144+
if PD_LTE_23:
145+
# pandas-dev/pandas#62316: both timedelta * bool
146+
# and np.timedelta64 * bool works, so pandas probably also should work
147+
check(assert_type(d * left, pd.TimedeltaIndex), pd.Index, timedelta)

tests/indexes/arithmetic/str/test_mul.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ def test_mul_py_scalar(left: "pd.Index[str]") -> None:
3131
b, i, f, c = True, 1, 1.0, 1j
3232
s, d = datetime(2025, 9, 27), timedelta(seconds=1)
3333

34-
check(assert_type(left * b, "pd.Index[str]"), pd.Index, str)
34+
if TYPE_CHECKING_INVALID_USAGE:
35+
_00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3536
check(assert_type(left * i, "pd.Index[str]"), pd.Index, str)
3637
if TYPE_CHECKING_INVALID_USAGE:
3738
_03 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3839
_04 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
3940
_05 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
4041
_06 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
4142

42-
check(assert_type(b * left, "pd.Index[str]"), pd.Index, str)
43+
if TYPE_CHECKING_INVALID_USAGE:
44+
_10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
4345
check(assert_type(i * left, "pd.Index[str]"), pd.Index, str)
4446
if TYPE_CHECKING_INVALID_USAGE:
4547
_13 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
@@ -54,15 +56,17 @@ def test_mul_py_sequence(left: "pd.Index[str]") -> None:
5456
s = [datetime(2025, 9, d) for d in (27, 28, 29)]
5557
d = [timedelta(seconds=s + 1) for s in range(3)]
5658

57-
check(assert_type(left * b, "pd.Index[str]"), pd.Index, str)
59+
if TYPE_CHECKING_INVALID_USAGE:
60+
_00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
5861
check(assert_type(left * i, "pd.Index[str]"), pd.Index, str)
5962
if TYPE_CHECKING_INVALID_USAGE:
6063
_03 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
6164
_04 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
6265
_05 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
6366
_06 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
6467

65-
check(assert_type(b * left, "pd.Index[str]"), pd.Index, str)
68+
if TYPE_CHECKING_INVALID_USAGE:
69+
_10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
6670
check(assert_type(i * left, "pd.Index[str]"), pd.Index, str)
6771
if TYPE_CHECKING_INVALID_USAGE:
6872
_13 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
@@ -80,7 +84,8 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None:
8084
s = np.array([np.datetime64(f"2025-09-{d}") for d in (27, 28, 29)], np.datetime64)
8185
d = np.array([np.timedelta64(s + 1, "s") for s in range(3)], np.timedelta64)
8286

83-
check(assert_type(left * b, "pd.Index[str]"), pd.Index, str)
87+
if TYPE_CHECKING_INVALID_USAGE:
88+
assert_type(left * b, Never)
8489
check(assert_type(left * i, "pd.Index[str]"), pd.Index, str)
8590
if TYPE_CHECKING_INVALID_USAGE:
8691
assert_type(left * f, Never)
@@ -91,7 +96,8 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None:
9196
# `numpy` typing gives the corresponding `ndarray`s in the static type
9297
# checking, where our `__rmul__` cannot override. At runtime, they return
9398
# `Index` with the correct element type.
94-
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, str)
99+
if TYPE_CHECKING_INVALID_USAGE:
100+
assert_type(b * left, "npt.NDArray[np.bool_]")
95101
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, str)
96102
if TYPE_CHECKING_INVALID_USAGE:
97103
assert_type(f * left, "npt.NDArray[np.float64]")
@@ -109,15 +115,17 @@ def test_mul_pd_index(left: "pd.Index[str]") -> None:
109115
s = pd.Index([datetime(2025, 9, d) for d in (27, 28, 29)])
110116
d = pd.Index([timedelta(seconds=s + 1) for s in range(3)])
111117

112-
check(assert_type(left * b, "pd.Index[str]"), pd.Index, str)
118+
if TYPE_CHECKING_INVALID_USAGE:
119+
_00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
113120
check(assert_type(left * i, "pd.Index[str]"), pd.Index, str)
114121
if TYPE_CHECKING_INVALID_USAGE:
115122
_03 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
116123
_04 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
117124
_05 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
118125
_06 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
119126

120-
check(assert_type(b * left, "pd.Index[str]"), pd.Index, str)
127+
if TYPE_CHECKING_INVALID_USAGE:
128+
_10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
121129
check(assert_type(i * left, "pd.Index[str]"), pd.Index, str)
122130
if TYPE_CHECKING_INVALID_USAGE:
123131
_13 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

0 commit comments

Comments
 (0)