Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ def fillna(self, value=None, method=None, limit=None):

# TODO: dispatch when self.categories is EA-dtype
values = np.asarray(self).reshape(-1, len(self))
values = interpolate_2d(values, method, 0, None, value).astype(
values = interpolate_2d(values, method, 0, None).astype(
self.categories.dtype
)[0]
codes = _get_codes_for_values(values, self.categories)
Expand Down
11 changes: 4 additions & 7 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,12 +1181,15 @@ def interpolate(
m = None

if m is not None:
if fill_value is not None:
# similar to validate_fillna_kwargs
raise ValueError("Cannot pass both fill_value and method")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for codecov?


return self._interpolate_with_fill(
method=m,
axis=axis,
inplace=inplace,
limit=limit,
fill_value=fill_value,
coerce=coerce,
downcast=downcast,
)
Expand Down Expand Up @@ -1214,7 +1217,6 @@ def _interpolate_with_fill(
axis: int = 0,
inplace: bool = False,
limit: Optional[int] = None,
fill_value: Optional[Any] = None,
coerce: bool = False,
downcast: Optional[str] = None,
) -> List["Block"]:
Expand All @@ -1232,16 +1234,11 @@ def _interpolate_with_fill(

values = self.values if inplace else self.values.copy()

# We only get here for non-ExtensionBlock
fill_value = convert_scalar_for_putitemlike(fill_value, self.values.dtype)

values = missing.interpolate_2d(
values,
method=method,
axis=axis,
limit=limit,
fill_value=fill_value,
dtype=self.dtype,
)

blocks = [self.make_block_same_class(values, ndim=self.ndim)]
Expand Down
13 changes: 2 additions & 11 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,6 @@ def interpolate_2d(
method="pad",
axis=0,
limit=None,
fill_value=None,
dtype: Optional[DtypeObj] = None,
):
"""
Perform an actual interpolation of values, values will be make 2-d if
Expand All @@ -563,18 +561,11 @@ def interpolate_2d(
raise AssertionError("cannot interpolate on a ndim == 1 with axis != 0")
values = values.reshape(tuple((1,) + values.shape))

if fill_value is None:
mask = None
else: # todo create faster fill func without masking
mask = mask_missing(transf(values), fill_value)

method = clean_fill_method(method)
if method == "pad":
values = transf(pad_2d(transf(values), limit=limit, mask=mask, dtype=dtype))
values = transf(pad_2d(transf(values), limit=limit))
else:
values = transf(
backfill_2d(transf(values), limit=limit, mask=mask, dtype=dtype)
)
values = transf(backfill_2d(transf(values), limit=limit))

# reshape back
if ndim == 1:
Expand Down