Skip to content

Commit 7413f2a

Browse files
committed
Merge pull request #10012 from mortada/cat_fillna_fill_value
kwarg for Categorical.fillna should be value instead of fill_value
2 parents 845cec9 + 0a0c36e commit 7413f2a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pandas/core/categorical.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas.core.algorithms import factorize
1111
from pandas.core.base import PandasObject, PandasDelegate
1212
import pandas.core.common as com
13-
from pandas.util.decorators import cache_readonly
13+
from pandas.util.decorators import cache_readonly, deprecate_kwarg
1414

1515
from pandas.core.common import (CategoricalDtype, ABCSeries, ABCIndexClass, ABCPeriodIndex, ABCCategoricalIndex,
1616
isnull, notnull, is_dtype_equal,
@@ -1168,7 +1168,8 @@ def to_dense(self):
11681168
"""
11691169
return np.asarray(self)
11701170

1171-
def fillna(self, fill_value=None, method=None, limit=None):
1171+
@deprecate_kwarg(old_arg_name='fill_value', new_arg_name='value')
1172+
def fillna(self, value=None, method=None, limit=None):
11721173
""" Fill NA/NaN values using the specified method.
11731174
11741175
Parameters
@@ -1187,8 +1188,8 @@ def fillna(self, fill_value=None, method=None, limit=None):
11871188
filled : Categorical with NA/NaN filled
11881189
"""
11891190

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

1206-
12071207
# pad / bfill
12081208
if method is not None:
12091209

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

12151215
else:
12161216

1217-
if not isnull(fill_value) and fill_value not in self.categories:
1217+
if not isnull(value) and value not in self.categories:
12181218
raise ValueError("fill value must be in categories")
12191219

12201220
mask = values==-1
12211221
if mask.any():
12221222
values = values.copy()
1223-
values[mask] = self.categories.get_loc(fill_value)
1223+
values[mask] = self.categories.get_loc(value)
12241224

12251225
return Categorical(values, categories=self.categories, ordered=self.ordered,
12261226
name=self.name, fastpath=True)

pandas/core/internals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None):
16931693
"not been implemented yet")
16941694

16951695
values = self.values if inplace else self.values.copy()
1696-
return [self.make_block_same_class(values=values.fillna(fill_value=value,
1696+
return [self.make_block_same_class(values=values.fillna(value=value,
16971697
limit=limit),
16981698
placement=self.mgr_locs)]
16991699

0 commit comments

Comments
 (0)