BUG: NDFrame.replace wrong exception type, wrong return when size==0 … · pandas-dev/pandas@73c1d32 (original) (raw)
`@@ -6179,8 +6179,8 @@ def replace(
`
6179
6179
`self,
`
6180
6180
`to_replace=None,
`
6181
6181
`value=None,
`
6182
``
`-
inplace=False,
`
6183
``
`-
limit=None,
`
``
6182
`+
inplace: bool_t = False,
`
``
6183
`+
limit: Optional[int] = None,
`
6184
6184
`regex=False,
`
6185
6185
`method="pad",
`
6186
6186
` ):
`
`@@ -6256,7 +6256,7 @@ def replace(
`
6256
6256
` If True, in place. Note: this will modify any
`
6257
6257
` other views on this object (e.g. a column from a DataFrame).
`
6258
6258
` Returns the caller if this is True.
`
6259
``
`-
limit : int, default None
`
``
6259
`+
limit : int or None, default None
`
6260
6260
` Maximum size gap to forward or backward fill.
`
6261
6261
`` regex : bool or same types as to_replace
, default False
``
6262
6262
`` Whether to interpret to_replace
and/or value
as regular
``
`@@ -6490,7 +6490,7 @@ def replace(
`
6490
6490
``
6491
6491
`inplace = validate_bool_kwarg(inplace, "inplace")
`
6492
6492
`if not is_bool(regex) and to_replace is not None:
`
6493
``
`-
raise AssertionError("'to_replace' must be 'None' if 'regex' is not a bool")
`
``
6493
`+
raise ValueError("'to_replace' must be 'None' if 'regex' is not a bool")
`
6494
6494
``
6495
6495
`if value is None:
`
6496
6496
`# passing a single value that is scalar like
`
`@@ -6550,12 +6550,14 @@ def replace(
`
6550
6550
``
6551
6551
`# need a non-zero len on all axes
`
6552
6552
`if not self.size:
`
6553
``
`-
return self
`
``
6553
`+
if inplace:
`
``
6554
`+
return
`
``
6555
`+
return self.copy()
`
6554
6556
``
6555
6557
`if is_dict_like(to_replace):
`
6556
6558
`if is_dict_like(value): # {'A' : NA} -> {'A' : 0}
`
6557
6559
`` # Note: Checking below for in foo.keys()
instead of
``
6558
``
`` -
in foo
is needed for when we have a Series and not dict
``
``
6560
`` +
in foo
is needed for when we have a Series and not dict
``
6559
6561
`mapping = {
`
6560
6562
`col: (to_replace[col], value[col])
`
6561
6563
`for col in to_replace.keys()
`