Skip to content

Commit ef1cac3

Browse files
authored
REF: make kwargs explicit in BlockManager methods (#33295)
1 parent 74ef178 commit ef1cac3

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ def diff(self, n: int, axis: int = 1) -> List["Block"]:
12821282
new_values = _block_shape(new_values, ndim=self.ndim)
12831283
return [self.make_block(values=new_values)]
12841284

1285-
def shift(self, periods, axis: int = 0, fill_value=None):
1285+
def shift(self, periods: int, axis: int = 0, fill_value=None):
12861286
""" shift the block by periods, possibly upcast """
12871287
# convert integer to float if necessary. need to do a lot more than
12881288
# that, handle boolean etc also

pandas/core/internals/managers.py

+21-11
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,24 @@ def get_axe(block, qs, axes):
545545
def isna(self, func) -> "BlockManager":
546546
return self.apply("apply", func=func)
547547

548-
def where(self, **kwargs) -> "BlockManager":
549-
if kwargs.pop("align", True):
548+
def where(
549+
self, other, cond, align: bool, errors: str, try_cast: bool, axis: int
550+
) -> "BlockManager":
551+
if align:
550552
align_keys = ["other", "cond"]
551553
else:
552554
align_keys = ["cond"]
553-
kwargs["other"] = extract_array(kwargs["other"], extract_numpy=True)
555+
other = extract_array(other, extract_numpy=True)
554556

555-
return self.apply("where", align_keys=align_keys, **kwargs)
557+
return self.apply(
558+
"where",
559+
align_keys=align_keys,
560+
other=other,
561+
cond=cond,
562+
errors=errors,
563+
try_cast=try_cast,
564+
axis=axis,
565+
)
556566

557567
def setitem(self, indexer, value) -> "BlockManager":
558568
return self.apply("setitem", indexer=indexer, value=value)
@@ -584,11 +594,13 @@ def diff(self, n: int, axis: int) -> "BlockManager":
584594
def interpolate(self, **kwargs) -> "BlockManager":
585595
return self.apply("interpolate", **kwargs)
586596

587-
def shift(self, **kwargs) -> "BlockManager":
588-
return self.apply("shift", **kwargs)
597+
def shift(self, periods: int, axis: int, fill_value) -> "BlockManager":
598+
return self.apply("shift", periods=periods, axis=axis, fill_value=fill_value)
589599

590-
def fillna(self, **kwargs) -> "BlockManager":
591-
return self.apply("fillna", **kwargs)
600+
def fillna(self, value, limit, inplace: bool, downcast) -> "BlockManager":
601+
return self.apply(
602+
"fillna", value=value, limit=limit, inplace=inplace, downcast=downcast
603+
)
592604

593605
def downcast(self) -> "BlockManager":
594606
return self.apply("downcast")
@@ -753,9 +765,7 @@ def _combine(self, blocks: List[Block], copy: bool = True) -> "BlockManager":
753765
new_blocks = []
754766
for b in blocks:
755767
b = b.copy(deep=copy)
756-
b.mgr_locs = algos.take_1d(
757-
inv_indexer, b.mgr_locs.as_array, axis=0, allow_fill=False
758-
)
768+
b.mgr_locs = inv_indexer[b.mgr_locs.indexer]
759769
new_blocks.append(b)
760770

761771
axes = list(self.axes)

0 commit comments

Comments
 (0)