Skip to content

CLN: remove unused kwargs from BlockManager.downcast #32691

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 2 commits into from
Mar 14, 2020
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
18 changes: 10 additions & 8 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ def _split_op_result(self, result) -> List["Block"]:

return [result]

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

if not self._can_hold_na:
if inplace:
return self
return [self]
else:
return self.copy()
return [self.copy()]

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

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

# operate column-by-column
def f(mask, val, idx):
Expand All @@ -442,7 +444,7 @@ def f(mask, val, idx):

return self.split_and_operate(None, f, inplace)

def split_and_operate(self, mask, f, inplace: bool):
def split_and_operate(self, mask, f, inplace: bool) -> List["Block"]:
"""
split the block per-column, and apply the callable f
per-column, return a new block for each. Handle
Expand Down Expand Up @@ -1191,7 +1193,7 @@ def _interpolate_with_fill(
fill_value=None,
coerce=False,
downcast=None,
):
) -> List["Block"]:
""" fillna but using the interpolate machinery """
inplace = validate_bool_kwarg(inplace, "inplace")

Expand Down Expand Up @@ -1233,15 +1235,15 @@ def _interpolate(
inplace=False,
downcast=None,
**kwargs,
):
) -> List["Block"]:
""" interpolate using scipy wrappers """
inplace = validate_bool_kwarg(inplace, "inplace")
data = self.values if inplace else self.values.copy()

# only deal with floats
if not self.is_float:
if not self.is_integer:
return self
return [self]
data = data.astype(np.float64)

if fill_value is None:
Expand Down
26 changes: 20 additions & 6 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ def isna(self, func) -> "BlockManager":
def where(self, **kwargs) -> "BlockManager":
return self.apply("where", **kwargs)

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

def putmask(self, **kwargs):
return self.apply("putmask", **kwargs)
Expand All @@ -583,16 +583,30 @@ def shift(self, **kwargs) -> "BlockManager":
def fillna(self, **kwargs) -> "BlockManager":
return self.apply("fillna", **kwargs)

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

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

def convert(self, **kwargs) -> "BlockManager":
return self.apply("convert", **kwargs)
def convert(
self,
copy: bool = True,
datetime: bool = True,
numeric: bool = True,
timedelta: bool = True,
coerce: bool = False,
) -> "BlockManager":
return self.apply(
"convert",
copy=copy,
datetime=datetime,
numeric=numeric,
timedelta=timedelta,
coerce=coerce,
)

def replace(self, value, **kwargs) -> "BlockManager":
assert np.ndim(value) == 0, value
Expand Down
17 changes: 2 additions & 15 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,14 @@ def test_downcast(self):

o = self._construct(shape=4, value=9, dtype=np.int64)
result = o.copy()
result._data = o._data.downcast(dtypes="infer")
result._data = o._data.downcast()
self._compare(result, o)

o = self._construct(shape=4, value=9.0)
expected = o.astype(np.int64)
result = o.copy()
result._data = o._data.downcast(dtypes="infer")
self._compare(result, expected)

o = self._construct(shape=4, value=9.5)
result = o.copy()
result._data = o._data.downcast(dtypes="infer")
result._data = o._data.downcast()
self._compare(result, o)

# are close
o = self._construct(shape=4, value=9.000000000005)
result = o.copy()
result._data = o._data.downcast(dtypes="infer")
expected = o.astype(np.int64)
self._compare(result, expected)

def test_constructor_compound_dtypes(self):
# see gh-5191
# Compound dtypes should raise NotImplementedError.
Expand Down