30
30
_as_bool_type ,
31
31
_as_categorical_type ,
32
32
_as_other_type ,
33
+ _sanitize_list_like ,
33
34
)
34
35
from pyspark .pandas .spark import functions as SF
35
36
from pyspark .pandas .typedef .typehints import as_spark_type , extension_dtypes , pandas_on_spark_type
@@ -48,6 +49,7 @@ def pretty_name(self) -> str:
48
49
return "bools"
49
50
50
51
def add (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
52
+ _sanitize_list_like (right )
51
53
if not is_valid_operand_for_numeric_arithmetic (right ):
52
54
raise TypeError (
53
55
"Addition can not be applied to %s and the given type." % self .pretty_name
@@ -67,6 +69,7 @@ def add(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
67
69
return left + right
68
70
69
71
def sub (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
72
+ _sanitize_list_like (right )
70
73
if not is_valid_operand_for_numeric_arithmetic (right , allow_bool = False ):
71
74
raise TypeError (
72
75
"Subtraction can not be applied to %s and the given type." % self .pretty_name
@@ -80,6 +83,7 @@ def sub(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
80
83
return left - right
81
84
82
85
def mul (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
86
+ _sanitize_list_like (right )
83
87
if not is_valid_operand_for_numeric_arithmetic (right ):
84
88
raise TypeError (
85
89
"Multiplication can not be applied to %s and the given type." % self .pretty_name
@@ -98,6 +102,7 @@ def mul(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
98
102
return left * right
99
103
100
104
def truediv (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
105
+ _sanitize_list_like (right )
101
106
if not is_valid_operand_for_numeric_arithmetic (right , allow_bool = False ):
102
107
raise TypeError (
103
108
"True division can not be applied to %s and the given type." % self .pretty_name
@@ -111,6 +116,7 @@ def truediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
111
116
return left / right
112
117
113
118
def floordiv (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
119
+ _sanitize_list_like (right )
114
120
if not is_valid_operand_for_numeric_arithmetic (right , allow_bool = False ):
115
121
raise TypeError (
116
122
"Floor division can not be applied to %s and the given type." % self .pretty_name
@@ -124,6 +130,7 @@ def floordiv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
124
130
return left // right
125
131
126
132
def mod (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
133
+ _sanitize_list_like (right )
127
134
if not is_valid_operand_for_numeric_arithmetic (right , allow_bool = False ):
128
135
raise TypeError (
129
136
"Modulo can not be applied to %s and the given type." % self .pretty_name
@@ -137,6 +144,7 @@ def mod(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
137
144
return left % right
138
145
139
146
def pow (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
147
+ _sanitize_list_like (right )
140
148
if not is_valid_operand_for_numeric_arithmetic (right , allow_bool = False ):
141
149
raise TypeError (
142
150
"Exponentiation can not be applied to %s and the given type." % self .pretty_name
@@ -150,6 +158,7 @@ def pow(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
150
158
return left ** right
151
159
152
160
def radd (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
161
+ _sanitize_list_like (right )
153
162
if isinstance (right , bool ):
154
163
return left .__or__ (right )
155
164
elif isinstance (right , numbers .Number ):
@@ -161,6 +170,7 @@ def radd(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
161
170
)
162
171
163
172
def rsub (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
173
+ _sanitize_list_like (right )
164
174
if isinstance (right , numbers .Number ) and not isinstance (right , bool ):
165
175
left = transform_boolean_operand_to_numeric (left , spark_type = as_spark_type (type (right )))
166
176
return right - left
@@ -170,6 +180,7 @@ def rsub(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
170
180
)
171
181
172
182
def rmul (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
183
+ _sanitize_list_like (right )
173
184
if isinstance (right , bool ):
174
185
return left .__and__ (right )
175
186
elif isinstance (right , numbers .Number ):
@@ -181,6 +192,7 @@ def rmul(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
181
192
)
182
193
183
194
def rtruediv (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
195
+ _sanitize_list_like (right )
184
196
if isinstance (right , numbers .Number ) and not isinstance (right , bool ):
185
197
left = transform_boolean_operand_to_numeric (left , spark_type = as_spark_type (type (right )))
186
198
return right / left
@@ -190,6 +202,7 @@ def rtruediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
190
202
)
191
203
192
204
def rfloordiv (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
205
+ _sanitize_list_like (right )
193
206
if isinstance (right , numbers .Number ) and not isinstance (right , bool ):
194
207
left = transform_boolean_operand_to_numeric (left , spark_type = as_spark_type (type (right )))
195
208
return right // left
@@ -199,6 +212,7 @@ def rfloordiv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
199
212
)
200
213
201
214
def rpow (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
215
+ _sanitize_list_like (right )
202
216
if isinstance (right , numbers .Number ) and not isinstance (right , bool ):
203
217
left = transform_boolean_operand_to_numeric (left , spark_type = as_spark_type (type (right )))
204
218
return right ** left
@@ -208,6 +222,7 @@ def rpow(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
208
222
)
209
223
210
224
def rmod (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
225
+ _sanitize_list_like (right )
211
226
if isinstance (right , numbers .Number ) and not isinstance (right , bool ):
212
227
left = transform_boolean_operand_to_numeric (left , spark_type = as_spark_type (type (right )))
213
228
return right % left
@@ -217,6 +232,7 @@ def rmod(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
217
232
)
218
233
219
234
def __and__ (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
235
+ _sanitize_list_like (right )
220
236
if isinstance (right , IndexOpsMixin ) and isinstance (right .dtype , extension_dtypes ):
221
237
return right .__and__ (left )
222
238
else :
@@ -233,6 +249,7 @@ def and_func(left: Column, right: Any) -> Column:
233
249
return column_op (and_func )(left , right )
234
250
235
251
def __or__ (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
252
+ _sanitize_list_like (right )
236
253
if isinstance (right , IndexOpsMixin ) and isinstance (right .dtype , extension_dtypes ):
237
254
return right .__or__ (left )
238
255
else :
@@ -281,15 +298,19 @@ def abs(self, operand: IndexOpsLike) -> IndexOpsLike:
281
298
return operand
282
299
283
300
def lt (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
301
+ _sanitize_list_like (right )
284
302
return column_op (Column .__lt__ )(left , right )
285
303
286
304
def le (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
305
+ _sanitize_list_like (right )
287
306
return column_op (Column .__le__ )(left , right )
288
307
289
308
def ge (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
309
+ _sanitize_list_like (right )
290
310
return column_op (Column .__ge__ )(left , right )
291
311
292
312
def gt (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
313
+ _sanitize_list_like (right )
293
314
return column_op (Column .__gt__ )(left , right )
294
315
295
316
def invert (self , operand : IndexOpsLike ) -> IndexOpsLike :
@@ -307,6 +328,8 @@ def pretty_name(self) -> str:
307
328
return "booleans"
308
329
309
330
def __and__ (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
331
+ _sanitize_list_like (right )
332
+
310
333
def and_func (left : Column , right : Any ) -> Column :
311
334
if not isinstance (right , Column ):
312
335
if pd .isna (right ):
@@ -318,6 +341,8 @@ def and_func(left: Column, right: Any) -> Column:
318
341
return column_op (and_func )(left , right )
319
342
320
343
def __or__ (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
344
+ _sanitize_list_like (right )
345
+
321
346
def or_func (left : Column , right : Any ) -> Column :
322
347
if not isinstance (right , Column ):
323
348
if pd .isna (right ):
0 commit comments