Skip to content

Commit c5a7d9d

Browse files
committed
adding comments and fix docstring
1 parent db87ac8 commit c5a7d9d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pandas/core/categorical.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1623,8 +1623,12 @@ def fillna(self, value=None, method=None, limit=None):
16231623
Method to use for filling holes in reindexed Series
16241624
pad / ffill: propagate last valid observation forward to next valid
16251625
backfill / bfill: use NEXT valid observation to fill gap
1626-
value : scalar
1627-
Value to use to fill holes (e.g. 0)
1626+
value : scalar, dict, Series
1627+
If a scalar value is passed it is used to fill all missing values.
1628+
Alternatively, a Series or dict can be used to fill in different
1629+
values for each index. The value should not be a list. The
1630+
value(s) passed should either be in the categories or should be
1631+
NaN.
16281632
limit : int, default None
16291633
(Not implemented yet for Categorical!)
16301634
If method is specified, this is the maximum number of consecutive
@@ -1665,6 +1669,8 @@ def fillna(self, value=None, method=None, limit=None):
16651669

16661670
else:
16671671

1672+
# If value is a dict or a Series (a dict value has already
1673+
# been converted to a Series)
16681674
if isinstance(value, ABCSeries):
16691675
if not value[~value.isin(self.categories)].isna().all():
16701676
raise ValueError("fill value must be in categories")
@@ -1673,7 +1679,7 @@ def fillna(self, value=None, method=None, limit=None):
16731679
indexer = np.where(values_codes != -1)
16741680
values[indexer] = values_codes[values_codes != -1]
16751681

1676-
# Scalar value
1682+
# If value is not a dict or Series it should be a scalar
16771683
else:
16781684
if not isna(value) and value not in self.categories:
16791685
raise ValueError("fill value must be in categories")

0 commit comments

Comments
 (0)