14
14
)
15
15
16
16
from tests import (
17
+ PD_LTE_23 ,
17
18
TYPE_CHECKING_INVALID_USAGE ,
18
19
check ,
19
20
)
@@ -31,17 +32,19 @@ def test_mul_py_scalar(left: "pd.Index[str]") -> None:
31
32
b , i , f , c = True , 1 , 1.0 , 1j
32
33
s , d = datetime (2025 , 9 , 27 ), timedelta (seconds = 1 )
33
34
34
- if TYPE_CHECKING_INVALID_USAGE :
35
- _00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
35
+ # pandas-dev/pandas#62595: we may want to support Series[str] * bool
36
+ # also in 3.x
37
+ if PD_LTE_23 :
38
+ check (assert_type (left * b , "pd.Index[str]" ), pd .Index , str )
36
39
check (assert_type (left * i , "pd.Index[str]" ), pd .Index , str )
37
40
if TYPE_CHECKING_INVALID_USAGE :
38
41
_02 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
39
42
_03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
40
43
_04 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
41
44
_05 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
42
45
43
- if TYPE_CHECKING_INVALID_USAGE :
44
- _10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
46
+ if PD_LTE_23 :
47
+ check ( assert_type ( b * left , "pd.Index[str]" ), pd . Index , str )
45
48
check (assert_type (i * left , "pd.Index[str]" ), pd .Index , str )
46
49
if TYPE_CHECKING_INVALID_USAGE :
47
50
_12 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
@@ -56,17 +59,19 @@ def test_mul_py_sequence(left: "pd.Index[str]") -> None:
56
59
s = [datetime (2025 , 9 , d ) for d in (27 , 28 , 29 )]
57
60
d = [timedelta (seconds = s + 1 ) for s in range (3 )]
58
61
59
- if TYPE_CHECKING_INVALID_USAGE :
60
- _00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
62
+ # pandas-dev/pandas#62595: we may want to support Series[str] * bool
63
+ # also in 3.x
64
+ if PD_LTE_23 :
65
+ check (assert_type (left * b , "pd.Index[str]" ), pd .Index , str )
61
66
check (assert_type (left * i , "pd.Index[str]" ), pd .Index , str )
62
67
if TYPE_CHECKING_INVALID_USAGE :
63
68
_02 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
64
69
_03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
65
70
_04 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
66
71
_05 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
67
72
68
- if TYPE_CHECKING_INVALID_USAGE :
69
- _10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
73
+ if PD_LTE_23 :
74
+ check ( assert_type ( b * left , "pd.Index[str]" ), pd . Index , str )
70
75
check (assert_type (i * left , "pd.Index[str]" ), pd .Index , str )
71
76
if TYPE_CHECKING_INVALID_USAGE :
72
77
_12 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
@@ -84,8 +89,10 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None:
84
89
s = np .array ([np .datetime64 (f"2025-09-{ d } " ) for d in (27 , 28 , 29 )], np .datetime64 )
85
90
d = np .array ([np .timedelta64 (s + 1 , "s" ) for s in range (3 )], np .timedelta64 )
86
91
87
- if TYPE_CHECKING_INVALID_USAGE :
88
- assert_type (left * b , Never )
92
+ # pandas-dev/pandas#62595: we may want to support Series[str] * bool
93
+ # also in 3.x
94
+ if PD_LTE_23 :
95
+ check (assert_type (left * b , "pd.Index[str]" ), pd .Index , str )
89
96
check (assert_type (left * i , "pd.Index[str]" ), pd .Index , str )
90
97
if TYPE_CHECKING_INVALID_USAGE :
91
98
assert_type (left * f , Never )
@@ -96,8 +103,8 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None:
96
103
# `numpy` typing gives the corresponding `ndarray`s in the static type
97
104
# checking, where our `__rmul__` cannot override. At runtime, they return
98
105
# `Index` with the correct element type.
99
- if TYPE_CHECKING_INVALID_USAGE :
100
- assert_type (b * left , "npt.NDArray[np.bool_]" )
106
+ if PD_LTE_23 :
107
+ check ( assert_type (b * left , "npt.NDArray[np.bool_]" ), pd . Index , str )
101
108
check (assert_type (i * left , "npt.NDArray[np.int64]" ), pd .Index , str )
102
109
if TYPE_CHECKING_INVALID_USAGE :
103
110
assert_type (f * left , "npt.NDArray[np.float64]" )
@@ -115,17 +122,19 @@ def test_mul_pd_index(left: "pd.Index[str]") -> None:
115
122
s = pd .Index ([datetime (2025 , 9 , d ) for d in (27 , 28 , 29 )])
116
123
d = pd .Index ([timedelta (seconds = s + 1 ) for s in range (3 )])
117
124
118
- if TYPE_CHECKING_INVALID_USAGE :
119
- _00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
125
+ # pandas-dev/pandas#62595: we may want to support Series[str] * bool
126
+ # also in 3.x
127
+ if PD_LTE_23 :
128
+ check (assert_type (left * b , "pd.Index[str]" ), pd .Index , str )
120
129
check (assert_type (left * i , "pd.Index[str]" ), pd .Index , str )
121
130
if TYPE_CHECKING_INVALID_USAGE :
122
131
_02 = left * f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
123
132
_03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
124
133
_04 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
125
134
_05 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
126
135
127
- if TYPE_CHECKING_INVALID_USAGE :
128
- _10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
136
+ if PD_LTE_23 :
137
+ check ( assert_type ( b * left , "pd.Index[str]" ), pd . Index , str )
129
138
check (assert_type (i * left , "pd.Index[str]" ), pd .Index , str )
130
139
if TYPE_CHECKING_INVALID_USAGE :
131
140
_12 = f * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
0 commit comments