Skip to content

Commit eb17d3d

Browse files
authored
CLN: remove unused axis kwarg from Block.putmask (#39238)
1 parent 5bd8d62 commit eb17d3d

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

pandas/core/generic.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -8935,9 +8935,7 @@ def _where(
89358935
# reconstruct the block manager
89368936

89378937
self._check_inplace_setting(other)
8938-
new_data = self._mgr.putmask(
8939-
mask=cond, new=other, align=align, axis=block_axis
8940-
)
8938+
new_data = self._mgr.putmask(mask=cond, new=other, align=align)
89418939
result = self._constructor(new_data)
89428940
return self._update_inplace(result)
89438941

pandas/core/internals/array_manager.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def where(self, other, cond, align: bool, errors: str, axis: int) -> ArrayManage
343343
# def setitem(self, indexer, value) -> ArrayManager:
344344
# return self.apply_with_block("setitem", indexer=indexer, value=value)
345345

346-
def putmask(self, mask, new, align: bool = True, axis: int = 0):
346+
def putmask(self, mask, new, align: bool = True):
347347

348348
if align:
349349
align_keys = ["new", "mask"]
@@ -356,7 +356,6 @@ def putmask(self, mask, new, align: bool = True, axis: int = 0):
356356
align_keys=align_keys,
357357
mask=mask,
358358
new=new,
359-
axis=axis,
360359
)
361360

362361
def diff(self, n: int, axis: int) -> ArrayManager:

pandas/core/internals/blocks.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ def setitem(self, indexer, value):
996996
block = self.make_block(values)
997997
return block
998998

999-
def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
999+
def putmask(self, mask, new) -> List["Block"]:
10001000
"""
10011001
putmask the data to the block; it is possible that we may create a
10021002
new dtype of block
@@ -1007,7 +1007,6 @@ def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
10071007
----------
10081008
mask : np.ndarray[bool], SparseArray[bool], or BooleanArray
10091009
new : a ndarray/object
1010-
axis : int
10111010
10121011
Returns
10131012
-------
@@ -1024,8 +1023,6 @@ def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
10241023
new = self.fill_value
10251024

10261025
if self._can_hold_element(new):
1027-
# We only get here for non-Extension Blocks, so _try_coerce_args
1028-
# is only relevant for DatetimeBlock and TimedeltaBlock
10291026
if self.dtype.kind in ["m", "M"]:
10301027
arr = self.array_values()
10311028
arr = cast("NDArrayBackedExtensionArray", arr)
@@ -1038,14 +1035,17 @@ def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
10381035
new_values = new_values.T
10391036

10401037
putmask_without_repeat(new_values, mask, new)
1038+
return [self]
1039+
1040+
elif not mask.any():
1041+
return [self]
10411042

1042-
# maybe upcast me
1043-
elif mask.any():
1043+
else:
1044+
# may need to upcast
10441045
if transpose:
10451046
mask = mask.T
10461047
if isinstance(new, np.ndarray):
10471048
new = new.T
1048-
axis = new_values.ndim - axis - 1
10491049

10501050
# operate column-by-column
10511051
def f(mask, val, idx):
@@ -1072,8 +1072,6 @@ def f(mask, val, idx):
10721072
new_blocks = self.split_and_operate(mask, f, True)
10731073
return new_blocks
10741074

1075-
return [self]
1076-
10771075
def coerce_to_target_dtype(self, other):
10781076
"""
10791077
coerce the current block to a dtype compat for other
@@ -1575,7 +1573,7 @@ def set_inplace(self, locs, values):
15751573
assert locs.tolist() == [0]
15761574
self.values = values
15771575

1578-
def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
1576+
def putmask(self, mask, new) -> List["Block"]:
15791577
"""
15801578
See Block.putmask.__doc__
15811579
"""

pandas/core/internals/managers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def where(self, other, cond, align: bool, errors: str, axis: int) -> BlockManage
564564
def setitem(self, indexer, value) -> BlockManager:
565565
return self.apply("setitem", indexer=indexer, value=value)
566566

567-
def putmask(self, mask, new, align: bool = True, axis: int = 0):
567+
def putmask(self, mask, new, align: bool = True):
568568

569569
if align:
570570
align_keys = ["new", "mask"]
@@ -577,7 +577,6 @@ def putmask(self, mask, new, align: bool = True, axis: int = 0):
577577
align_keys=align_keys,
578578
mask=mask,
579579
new=new,
580-
axis=axis,
581580
)
582581

583582
def diff(self, n: int, axis: int) -> BlockManager:

0 commit comments

Comments
 (0)