@@ -75,14 +75,7 @@ def masked_arith_op(x: np.ndarray, y, op):
75
75
result = np .empty (x .size , dtype = dtype )
76
76
77
77
if len (x ) != len (y ):
78
- if not _can_broadcast (x , y ):
79
- raise ValueError (x .shape , y .shape )
80
-
81
- # Call notna on pre-broadcasted y for performance
82
- ymask = notna (y )
83
- y = np .broadcast_to (y , x .shape )
84
- ymask = np .broadcast_to (ymask , x .shape )
85
-
78
+ raise ValueError (x .shape , y .shape )
86
79
else :
87
80
ymask = notna (y )
88
81
@@ -211,51 +204,6 @@ def arithmetic_op(left: ArrayLike, right: Any, op, str_rep: str):
211
204
return res_values
212
205
213
206
214
- def _broadcast_comparison_op (lvalues , rvalues , op ) -> np .ndarray :
215
- """
216
- Broadcast a comparison operation between two 2D arrays.
217
-
218
- Parameters
219
- ----------
220
- lvalues : np.ndarray or ExtensionArray
221
- rvalues : np.ndarray or ExtensionArray
222
-
223
- Returns
224
- -------
225
- np.ndarray[bool]
226
- """
227
- if isinstance (rvalues , np .ndarray ):
228
- rvalues = np .broadcast_to (rvalues , lvalues .shape )
229
- result = comparison_op (lvalues , rvalues , op )
230
- else :
231
- result = np .empty (lvalues .shape , dtype = bool )
232
- for i in range (len (lvalues )):
233
- result [i , :] = comparison_op (lvalues [i ], rvalues [:, 0 ], op )
234
- return result
235
-
236
-
237
- def _can_broadcast (lvalues , rvalues ) -> bool :
238
- """
239
- Check if we can broadcast rvalues to match the shape of lvalues.
240
-
241
- Parameters
242
- ----------
243
- lvalues : np.ndarray or ExtensionArray
244
- rvalues : np.ndarray or ExtensionArray
245
-
246
- Returns
247
- -------
248
- bool
249
- """
250
- # We assume that lengths dont match
251
- if lvalues .ndim == rvalues .ndim == 2 :
252
- # See if we can broadcast unambiguously
253
- if lvalues .shape [1 ] == rvalues .shape [- 1 ]:
254
- if rvalues .shape [0 ] == 1 :
255
- return True
256
- return False
257
-
258
-
259
207
def comparison_op (
260
208
left : ArrayLike , right : Any , op , str_rep : Optional [str ] = None ,
261
209
) -> ArrayLike :
@@ -287,8 +235,6 @@ def comparison_op(
287
235
# We are not catching all listlikes here (e.g. frozenset, tuple)
288
236
# The ambiguous case is object-dtype. See GH#27803
289
237
if len (lvalues ) != len (rvalues ):
290
- if _can_broadcast (lvalues , rvalues ):
291
- return _broadcast_comparison_op (lvalues , rvalues , op )
292
238
raise ValueError (
293
239
"Lengths must match to compare" , lvalues .shape , rvalues .shape
294
240
)
0 commit comments