Categorical fillna
with custom objects raises TypeError · Issue #21097 · pandas-dev/pandas (original) (raw)
This behavior appears new in 0.23.0.
Setup copied from #21002:
from pandas.core.base import StringMixin
class County(StringMixin):
name = u'San Sebastián'
state = u'PR'
def __unicode__(self):
return self.name + u', ' + self.state
cat = pd.Categorical([County() for n in range(61)])
>>> cat.fillna(cat[0])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/pandas/util/_decorators.py", line 177, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pandas/core/arrays/categorical.py", line 1769, in fillna
'"{0}"'.format(type(value).__name__))
TypeError: "value" parameter must be a scalar, dict or Series, but you passed a "County"
I don't see any reason why passing one of the categories to fillna
should be disallowed, so it looks like the issue is with being too strict about what qualifies as a scalar.