Skip to content

kwarg for Categorical.fillna should be value instead of fill_value #10012

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 1 commit into from
Apr 29, 2015
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: 9 additions & 9 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pandas.core.algorithms import factorize
from pandas.core.base import PandasObject, PandasDelegate
import pandas.core.common as com
from pandas.util.decorators import cache_readonly
from pandas.util.decorators import cache_readonly, deprecate_kwarg

from pandas.core.common import (CategoricalDtype, ABCSeries, ABCIndexClass, ABCPeriodIndex, ABCCategoricalIndex,
isnull, notnull, is_dtype_equal,
Expand Down Expand Up @@ -1168,7 +1168,8 @@ def to_dense(self):
"""
return np.asarray(self)

def fillna(self, fill_value=None, method=None, limit=None):
@deprecate_kwarg(old_arg_name='fill_value', new_arg_name='value')
def fillna(self, value=None, method=None, limit=None):
""" Fill NA/NaN values using the specified method.

Parameters
Expand All @@ -1187,8 +1188,8 @@ def fillna(self, fill_value=None, method=None, limit=None):
filled : Categorical with NA/NaN filled
"""

if fill_value is None:
fill_value = np.nan
if value is None:
value = np.nan
if limit is not None:
raise NotImplementedError("specifying a limit for fillna has not "
"been implemented yet")
Expand All @@ -1203,24 +1204,23 @@ def fillna(self, fill_value=None, method=None, limit=None):
# we only have one NA in categories
values[values == nan_pos] = -1


# pad / bfill
if method is not None:

values = self.to_dense().reshape(-1,len(self))
values = self.to_dense().reshape(-1, len(self))
values = com.interpolate_2d(
values, method, 0, None, fill_value).astype(self.categories.dtype)[0]
values, method, 0, None, value).astype(self.categories.dtype)[0]
values = _get_codes_for_values(values, self.categories)

else:

if not isnull(fill_value) and fill_value not in self.categories:
if not isnull(value) and value not in self.categories:
raise ValueError("fill value must be in categories")

mask = values==-1
if mask.any():
values = values.copy()
values[mask] = self.categories.get_loc(fill_value)
values[mask] = self.categories.get_loc(value)

return Categorical(values, categories=self.categories, ordered=self.ordered,
name=self.name, fastpath=True)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None):
"not been implemented yet")

values = self.values if inplace else self.values.copy()
return [self.make_block_same_class(values=values.fillna(fill_value=value,
return [self.make_block_same_class(values=values.fillna(value=value,
limit=limit),
placement=self.mgr_locs)]

Expand Down