@@ -179,51 +179,6 @@ def _get_frame_op_default_axis(name):
179
179
return "columns"
180
180
181
181
182
- def _get_opstr (op ):
183
- """
184
- Find the operation string, if any, to pass to numexpr for this
185
- operation.
186
-
187
- Parameters
188
- ----------
189
- op : binary operator
190
-
191
- Returns
192
- -------
193
- op_str : string or None
194
- """
195
- return {
196
- operator .add : "+" ,
197
- radd : "+" ,
198
- operator .mul : "*" ,
199
- rmul : "*" ,
200
- operator .sub : "-" ,
201
- rsub : "-" ,
202
- operator .truediv : "/" ,
203
- rtruediv : "/" ,
204
- operator .floordiv : "//" ,
205
- rfloordiv : "//" ,
206
- operator .mod : "%" ,
207
- rmod : "%" ,
208
- operator .pow : "**" ,
209
- rpow : "**" ,
210
- operator .eq : "==" ,
211
- operator .ne : "!=" ,
212
- operator .le : "<=" ,
213
- operator .lt : "<" ,
214
- operator .ge : ">=" ,
215
- operator .gt : ">" ,
216
- operator .and_ : "&" ,
217
- rand_ : "&" ,
218
- operator .or_ : "|" ,
219
- ror_ : "|" ,
220
- operator .xor : "^" ,
221
- rxor : "^" ,
222
- divmod : None ,
223
- rdivmod : None ,
224
- }[op ]
225
-
226
-
227
182
def _get_op_name (op , special : bool ) -> str :
228
183
"""
229
184
Find the name to attach to this method according to conventions
@@ -293,7 +248,7 @@ def fill_binop(left, right, fill_value):
293
248
# Dispatch logic
294
249
295
250
296
- def dispatch_to_series (left , right , func , str_rep = None , axis = None ):
251
+ def dispatch_to_series (left , right , func , axis = None ):
297
252
"""
298
253
Evaluate the frame operation func(left, right) by evaluating
299
254
column-by-column, dispatching to the Series implementation.
@@ -303,7 +258,6 @@ def dispatch_to_series(left, right, func, str_rep=None, axis=None):
303
258
left : DataFrame
304
259
right : scalar or DataFrame
305
260
func : arithmetic or comparison operator
306
- str_rep : str or None, default None
307
261
axis : {None, 0, 1, "index", "columns"}
308
262
309
263
Returns
@@ -318,14 +272,14 @@ def dispatch_to_series(left, right, func, str_rep=None, axis=None):
318
272
if lib .is_scalar (right ) or np .ndim (right ) == 0 :
319
273
320
274
# Get the appropriate array-op to apply to each block's values.
321
- array_op = get_array_op (func , str_rep = str_rep )
275
+ array_op = get_array_op (func )
322
276
bm = left ._mgr .apply (array_op , right = right )
323
277
return type (left )(bm )
324
278
325
279
elif isinstance (right , ABCDataFrame ):
326
280
assert right ._indexed_same (left )
327
281
328
- array_op = get_array_op (func , str_rep = str_rep )
282
+ array_op = get_array_op (func )
329
283
bm = left ._mgr .operate_blockwise (right ._mgr , array_op )
330
284
return type (left )(bm )
331
285
@@ -358,7 +312,7 @@ def column_op(a, b):
358
312
# Remaining cases have less-obvious dispatch rules
359
313
raise NotImplementedError (right )
360
314
361
- new_data = expressions .evaluate (column_op , str_rep , left , right )
315
+ new_data = expressions .evaluate (column_op , left , right )
362
316
return new_data
363
317
364
318
@@ -391,7 +345,6 @@ def _arith_method_SERIES(cls, op, special):
391
345
Wrapper function for Series arithmetic operations, to avoid
392
346
code duplication.
393
347
"""
394
- str_rep = _get_opstr (op )
395
348
op_name = _get_op_name (op , special )
396
349
397
350
@unpack_zerodim_and_defer (op_name )
@@ -402,7 +355,7 @@ def wrapper(left, right):
402
355
403
356
lvalues = extract_array (left , extract_numpy = True )
404
357
rvalues = extract_array (right , extract_numpy = True )
405
- result = arithmetic_op (lvalues , rvalues , op , str_rep )
358
+ result = arithmetic_op (lvalues , rvalues , op )
406
359
407
360
return left ._construct_result (result , name = res_name )
408
361
@@ -415,7 +368,6 @@ def _comp_method_SERIES(cls, op, special):
415
368
Wrapper function for Series arithmetic operations, to avoid
416
369
code duplication.
417
370
"""
418
- str_rep = _get_opstr (op )
419
371
op_name = _get_op_name (op , special )
420
372
421
373
@unpack_zerodim_and_defer (op_name )
@@ -429,7 +381,7 @@ def wrapper(self, other):
429
381
lvalues = extract_array (self , extract_numpy = True )
430
382
rvalues = extract_array (other , extract_numpy = True )
431
383
432
- res_values = comparison_op (lvalues , rvalues , op , str_rep )
384
+ res_values = comparison_op (lvalues , rvalues , op )
433
385
434
386
return self ._construct_result (res_values , name = res_name )
435
387
@@ -490,7 +442,7 @@ def flex_wrapper(self, other, level=None, fill_value=None, axis=0):
490
442
# DataFrame
491
443
492
444
493
- def _combine_series_frame (left , right , func , axis : int , str_rep : str ):
445
+ def _combine_series_frame (left , right , func , axis : int ):
494
446
"""
495
447
Apply binary operator `func` to self, other using alignment and fill
496
448
conventions determined by the axis argument.
@@ -501,7 +453,6 @@ def _combine_series_frame(left, right, func, axis: int, str_rep: str):
501
453
right : Series
502
454
func : binary operator
503
455
axis : {0, 1}
504
- str_rep : str
505
456
506
457
Returns
507
458
-------
@@ -520,7 +471,7 @@ def _combine_series_frame(left, right, func, axis: int, str_rep: str):
520
471
521
472
rvalues = np .broadcast_to (rvalues , left .shape )
522
473
523
- array_op = get_array_op (func , str_rep = str_rep )
474
+ array_op = get_array_op (func )
524
475
bm = left ._mgr .apply (array_op , right = rvalues .T , align_keys = ["right" ])
525
476
return type (left )(bm )
526
477
@@ -679,12 +630,11 @@ def _frame_arith_method_with_reindex(
679
630
680
631
681
632
def _arith_method_FRAME (cls , op , special ):
682
- str_rep = _get_opstr (op )
683
633
op_name = _get_op_name (op , special )
684
634
default_axis = _get_frame_op_default_axis (op_name )
685
635
686
- na_op = define_na_arithmetic_op (op , str_rep )
687
- is_logical = str_rep in ["& " , "| " , "^ " ]
636
+ na_op = define_na_arithmetic_op (op )
637
+ is_logical = op . __name__ . strip ( "_" ). lstrip ( "_" ) in ["and " , "or " , "xor " ]
688
638
689
639
if op_name in _op_descriptions :
690
640
# i.e. include "add" but not "__add__"
@@ -719,15 +669,13 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
719
669
raise NotImplementedError (f"fill_value { fill_value } not supported." )
720
670
721
671
axis = self ._get_axis_number (axis ) if axis is not None else 1
722
- new_data = _combine_series_frame (
723
- self , other , pass_op , axis = axis , str_rep = str_rep
724
- )
672
+ new_data = _combine_series_frame (self , other , pass_op , axis = axis )
725
673
else :
726
674
# in this case we always have `np.ndim(other) == 0`
727
675
if fill_value is not None :
728
676
self = self .fillna (fill_value )
729
677
730
- new_data = dispatch_to_series (self , other , op , str_rep )
678
+ new_data = dispatch_to_series (self , other , op )
731
679
732
680
return self ._construct_result (new_data )
733
681
@@ -737,7 +685,6 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
737
685
738
686
739
687
def _flex_comp_method_FRAME (cls , op , special ):
740
- str_rep = _get_opstr (op )
741
688
op_name = _get_op_name (op , special )
742
689
default_axis = _get_frame_op_default_axis (op_name )
743
690
@@ -752,16 +699,14 @@ def f(self, other, axis=default_axis, level=None):
752
699
753
700
if isinstance (other , ABCDataFrame ):
754
701
# Another DataFrame
755
- new_data = dispatch_to_series (self , other , op , str_rep )
702
+ new_data = dispatch_to_series (self , other , op )
756
703
757
704
elif isinstance (other , ABCSeries ):
758
705
axis = self ._get_axis_number (axis ) if axis is not None else 1
759
- new_data = _combine_series_frame (
760
- self , other , op , axis = axis , str_rep = str_rep
761
- )
706
+ new_data = _combine_series_frame (self , other , op , axis = axis )
762
707
else :
763
708
# in this case we always have `np.ndim(other) == 0`
764
- new_data = dispatch_to_series (self , other , op , str_rep )
709
+ new_data = dispatch_to_series (self , other , op )
765
710
766
711
return self ._construct_result (new_data )
767
712
@@ -771,7 +716,6 @@ def f(self, other, axis=default_axis, level=None):
771
716
772
717
773
718
def _comp_method_FRAME (cls , op , special ):
774
- str_rep = _get_opstr (op )
775
719
op_name = _get_op_name (op , special )
776
720
777
721
@Appender (f"Wrapper for comparison method { op_name } " )
@@ -783,7 +727,7 @@ def f(self, other):
783
727
784
728
axis = "columns" # only relevant for Series other case
785
729
# See GH#4537 for discussion of scalar op behavior
786
- new_data = dispatch_to_series (self , other , op , str_rep , axis = axis )
730
+ new_data = dispatch_to_series (self , other , op , axis = axis )
787
731
return self ._construct_result (new_data )
788
732
789
733
f .__name__ = op_name
0 commit comments