6
6
from __future__ import annotations
7
7
8
8
import operator
9
- from typing import TYPE_CHECKING
9
+ from typing import (
10
+ TYPE_CHECKING ,
11
+ cast ,
12
+ )
10
13
11
14
import numpy as np
12
15
@@ -333,7 +336,7 @@ def to_series(right):
333
336
334
337
335
338
def should_reindex_frame_op (
336
- left : DataFrame , right , op , axis , default_axis , fill_value , level
339
+ left : DataFrame , right , op , axis : int , fill_value , level
337
340
) -> bool :
338
341
"""
339
342
Check if this is an operation between DataFrames that will need to reindex.
@@ -347,7 +350,7 @@ def should_reindex_frame_op(
347
350
if not isinstance (right , ABCDataFrame ):
348
351
return False
349
352
350
- if fill_value is None and level is None and axis is default_axis :
353
+ if fill_value is None and level is None and axis == 1 :
351
354
# TODO: any other cases we should handle here?
352
355
353
356
# Intersection is always unique so we have to check the unique columns
@@ -435,26 +438,23 @@ def _maybe_align_series_as_frame(frame: DataFrame, series: Series, axis: AxisInt
435
438
436
439
def flex_arith_method_FRAME (op ):
437
440
op_name = op .__name__ .strip ("_" )
438
- default_axis = "columns"
439
441
440
442
na_op = get_array_op (op )
441
443
doc = make_flex_doc (op_name , "dataframe" )
442
444
443
445
@Appender (doc )
444
- def f (self , other , axis = default_axis , level = None , fill_value = None ):
446
+ def f (self , other , axis : Axis = "columns" , level = None , fill_value = None ):
447
+ axis = self ._get_axis_number (axis ) if axis is not None else 1
448
+ axis = cast (int , axis )
445
449
446
- if should_reindex_frame_op (
447
- self , other , op , axis , default_axis , fill_value , level
448
- ):
450
+ if should_reindex_frame_op (self , other , op , axis , fill_value , level ):
449
451
return frame_arith_method_with_reindex (self , other , op )
450
452
451
453
if isinstance (other , ABCSeries ) and fill_value is not None :
452
454
# TODO: We could allow this in cases where we end up going
453
455
# through the DataFrame path
454
456
raise NotImplementedError (f"fill_value { fill_value } not supported." )
455
457
456
- axis = self ._get_axis_number (axis ) if axis is not None else 1
457
-
458
458
other = maybe_prepare_scalar_for_op (other , self .shape )
459
459
self , other = align_method_FRAME (self , other , axis , flex = True , level = level )
460
460
@@ -480,14 +480,13 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
480
480
481
481
def flex_comp_method_FRAME (op ):
482
482
op_name = op .__name__ .strip ("_" )
483
- default_axis = "columns" # because we are "flex"
484
483
485
484
doc = _flex_comp_doc_FRAME .format (
486
485
op_name = op_name , desc = _op_descriptions [op_name ]["desc" ]
487
486
)
488
487
489
488
@Appender (doc )
490
- def f (self , other , axis = default_axis , level = None ):
489
+ def f (self , other , axis : Axis = "columns" , level = None ):
491
490
axis = self ._get_axis_number (axis ) if axis is not None else 1
492
491
493
492
self , other = align_method_FRAME (self , other , axis , flex = True , level = level )
0 commit comments