Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
BUG: Series.fillna() crashes on Categorical series if value is a series #17033
import pandas as pd, numpy as np s_str = pd.Series(['hello',np.NaN]) print s_str.fillna(s_str) # This works s_cat = s_str.astype('category') print s_cat.fillna(s_str) # This crashes
Pandas.Series.fillna can take a scalar, dict, Series or DataFrame as value. The fillna() method for categorical only takes scalars as value, but it doesn't provide a clear error message when an unsupported input type, such as Series, is provided.
Calling Categorical.fillna() with value=series crashes with a cryptic error message:
If Series cannot be supported as input, the function should check for input type and provide a proper ValueError message (e.g. "value must be a scalar").
The ideal solution, however, would be to have Categorical.fillna() support the same value types as other fillna() methods.
@capelastegui : I agree that at the very least the error message can be improved. I also don't see why we shouldn't support
Thus, a PR to improve the error message is welcome! However, feel free to also dive into how we could support those two classes as inputs and submit a PR to add that functionality.