@@ -75,14 +75,7 @@ def masked_arith_op(x: np.ndarray, y, op):
7575 result = np .empty (x .size , dtype = dtype )
7676
7777 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 )
8679 else :
8780 ymask = notna (y )
8881
@@ -211,51 +204,6 @@ def arithmetic_op(left: ArrayLike, right: Any, op, str_rep: str):
211204 return res_values
212205
213206
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-
259207def comparison_op (
260208 left : ArrayLike , right : Any , op , str_rep : Optional [str ] = None ,
261209) -> ArrayLike :
@@ -287,8 +235,6 @@ def comparison_op(
287235 # We are not catching all listlikes here (e.g. frozenset, tuple)
288236 # The ambiguous case is object-dtype. See GH#27803
289237 if len (lvalues ) != len (rvalues ):
290- if _can_broadcast (lvalues , rvalues ):
291- return _broadcast_comparison_op (lvalues , rvalues , op )
292238 raise ValueError (
293239 "Lengths must match to compare" , lvalues .shape , rvalues .shape
294240 )
0 commit comments