Skip to content

CLN: remove unused axis kwarg from Block.putmask #39238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8935,9 +8935,7 @@ def _where(
# reconstruct the block manager

self._check_inplace_setting(other)
new_data = self._mgr.putmask(
mask=cond, new=other, align=align, axis=block_axis
)
new_data = self._mgr.putmask(mask=cond, new=other, align=align)
result = self._constructor(new_data)
return self._update_inplace(result)

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def where(self, other, cond, align: bool, errors: str, axis: int) -> ArrayManage
# def setitem(self, indexer, value) -> ArrayManager:
# return self.apply_with_block("setitem", indexer=indexer, value=value)

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

if align:
align_keys = ["new", "mask"]
Expand All @@ -356,7 +356,6 @@ def putmask(self, mask, new, align: bool = True, axis: int = 0):
align_keys=align_keys,
mask=mask,
new=new,
axis=axis,
)

def diff(self, n: int, axis: int) -> ArrayManager:
Expand Down
18 changes: 8 additions & 10 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def setitem(self, indexer, value):
block = self.make_block(values)
return block

def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
def putmask(self, mask, new) -> List["Block"]:
"""
putmask the data to the block; it is possible that we may create a
new dtype of block
Expand All @@ -1009,7 +1009,6 @@ def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
----------
mask : np.ndarray[bool], SparseArray[bool], or BooleanArray
new : a ndarray/object
axis : int

Returns
-------
Expand All @@ -1026,8 +1025,6 @@ def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
new = self.fill_value

if self._can_hold_element(new):
# We only get here for non-Extension Blocks, so _try_coerce_args
# is only relevant for DatetimeBlock and TimedeltaBlock
if self.dtype.kind in ["m", "M"]:
arr = self.array_values()
arr = cast("NDArrayBackedExtensionArray", arr)
Expand All @@ -1040,14 +1037,17 @@ def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
new_values = new_values.T

putmask_without_repeat(new_values, mask, new)
return [self]

elif not mask.any():
return [self]

# maybe upcast me
elif mask.any():
else:
# may need to upcast
if transpose:
mask = mask.T
if isinstance(new, np.ndarray):
new = new.T
axis = new_values.ndim - axis - 1

# operate column-by-column
def f(mask, val, idx):
Expand All @@ -1074,8 +1074,6 @@ def f(mask, val, idx):
new_blocks = self.split_and_operate(mask, f, True)
return new_blocks

return [self]

def coerce_to_target_dtype(self, other):
"""
coerce the current block to a dtype compat for other
Expand Down Expand Up @@ -1577,7 +1575,7 @@ def set_inplace(self, locs, values):
assert locs.tolist() == [0]
self.values = values

def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
def putmask(self, mask, new) -> List["Block"]:
"""
See Block.putmask.__doc__
"""
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def where(self, other, cond, align: bool, errors: str, axis: int) -> BlockManage
def setitem(self, indexer, value) -> BlockManager:
return self.apply("setitem", indexer=indexer, value=value)

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

if align:
align_keys = ["new", "mask"]
Expand All @@ -577,7 +577,6 @@ def putmask(self, mask, new, align: bool = True, axis: int = 0):
align_keys=align_keys,
mask=mask,
new=new,
axis=axis,
)

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