Skip to content

Commit ea9942b

Browse files
authored
CLN: remove unused kwargs from BlockManager.downcast (#32691)
1 parent d8f60c3 commit ea9942b

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

pandas/core/internals/blocks.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@ def _split_op_result(self, result) -> List["Block"]:
403403

404404
return [result]
405405

406-
def fillna(self, value, limit=None, inplace: bool = False, downcast=None):
406+
def fillna(
407+
self, value, limit=None, inplace: bool = False, downcast=None
408+
) -> List["Block"]:
407409
"""
408410
fillna on the block with the value. If we fail, then convert to
409411
ObjectBlock and try again
@@ -417,9 +419,9 @@ def fillna(self, value, limit=None, inplace: bool = False, downcast=None):
417419

418420
if not self._can_hold_na:
419421
if inplace:
420-
return self
422+
return [self]
421423
else:
422-
return self.copy()
424+
return [self.copy()]
423425

424426
if self._can_hold_element(value):
425427
# equivalent: _try_coerce_args(value) would not raise
@@ -428,7 +430,7 @@ def fillna(self, value, limit=None, inplace: bool = False, downcast=None):
428430

429431
# we can't process the value, but nothing to do
430432
if not mask.any():
431-
return self if inplace else self.copy()
433+
return [self] if inplace else [self.copy()]
432434

433435
# operate column-by-column
434436
def f(mask, val, idx):
@@ -442,7 +444,7 @@ def f(mask, val, idx):
442444

443445
return self.split_and_operate(None, f, inplace)
444446

445-
def split_and_operate(self, mask, f, inplace: bool):
447+
def split_and_operate(self, mask, f, inplace: bool) -> List["Block"]:
446448
"""
447449
split the block per-column, and apply the callable f
448450
per-column, return a new block for each. Handle
@@ -1191,7 +1193,7 @@ def _interpolate_with_fill(
11911193
fill_value=None,
11921194
coerce=False,
11931195
downcast=None,
1194-
):
1196+
) -> List["Block"]:
11951197
""" fillna but using the interpolate machinery """
11961198
inplace = validate_bool_kwarg(inplace, "inplace")
11971199

@@ -1233,15 +1235,15 @@ def _interpolate(
12331235
inplace=False,
12341236
downcast=None,
12351237
**kwargs,
1236-
):
1238+
) -> List["Block"]:
12371239
""" interpolate using scipy wrappers """
12381240
inplace = validate_bool_kwarg(inplace, "inplace")
12391241
data = self.values if inplace else self.values.copy()
12401242

12411243
# only deal with floats
12421244
if not self.is_float:
12431245
if not self.is_integer:
1244-
return self
1246+
return [self]
12451247
data = data.astype(np.float64)
12461248

12471249
if fill_value is None:

pandas/core/internals/managers.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ def isna(self, func) -> "BlockManager":
565565
def where(self, **kwargs) -> "BlockManager":
566566
return self.apply("where", **kwargs)
567567

568-
def setitem(self, **kwargs) -> "BlockManager":
569-
return self.apply("setitem", **kwargs)
568+
def setitem(self, indexer, value) -> "BlockManager":
569+
return self.apply("setitem", indexer=indexer, value=value)
570570

571571
def putmask(self, **kwargs):
572572
return self.apply("putmask", **kwargs)
@@ -583,16 +583,30 @@ def shift(self, **kwargs) -> "BlockManager":
583583
def fillna(self, **kwargs) -> "BlockManager":
584584
return self.apply("fillna", **kwargs)
585585

586-
def downcast(self, **kwargs) -> "BlockManager":
587-
return self.apply("downcast", **kwargs)
586+
def downcast(self) -> "BlockManager":
587+
return self.apply("downcast")
588588

589589
def astype(
590590
self, dtype, copy: bool = False, errors: str = "raise"
591591
) -> "BlockManager":
592592
return self.apply("astype", dtype=dtype, copy=copy, errors=errors)
593593

594-
def convert(self, **kwargs) -> "BlockManager":
595-
return self.apply("convert", **kwargs)
594+
def convert(
595+
self,
596+
copy: bool = True,
597+
datetime: bool = True,
598+
numeric: bool = True,
599+
timedelta: bool = True,
600+
coerce: bool = False,
601+
) -> "BlockManager":
602+
return self.apply(
603+
"convert",
604+
copy=copy,
605+
datetime=datetime,
606+
numeric=numeric,
607+
timedelta=timedelta,
608+
coerce=coerce,
609+
)
596610

597611
def replace(self, value, **kwargs) -> "BlockManager":
598612
assert np.ndim(value) == 0, value

pandas/tests/generic/test_generic.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -159,27 +159,14 @@ def test_downcast(self):
159159

160160
o = self._construct(shape=4, value=9, dtype=np.int64)
161161
result = o.copy()
162-
result._data = o._data.downcast(dtypes="infer")
162+
result._data = o._data.downcast()
163163
self._compare(result, o)
164164

165-
o = self._construct(shape=4, value=9.0)
166-
expected = o.astype(np.int64)
167-
result = o.copy()
168-
result._data = o._data.downcast(dtypes="infer")
169-
self._compare(result, expected)
170-
171165
o = self._construct(shape=4, value=9.5)
172166
result = o.copy()
173-
result._data = o._data.downcast(dtypes="infer")
167+
result._data = o._data.downcast()
174168
self._compare(result, o)
175169

176-
# are close
177-
o = self._construct(shape=4, value=9.000000000005)
178-
result = o.copy()
179-
result._data = o._data.downcast(dtypes="infer")
180-
expected = o.astype(np.int64)
181-
self._compare(result, expected)
182-
183170
def test_constructor_compound_dtypes(self):
184171
# see gh-5191
185172
# Compound dtypes should raise NotImplementedError.

0 commit comments

Comments
 (0)