Skip to content

Conversation

@MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Aug 15, 2019

@MarcoGorelli MarcoGorelli changed the title Ensure that :func: in :class: only replaces null values BUG: Ensure that fill_na in Categorical only replaces null values Aug 15, 2019
],
)
def test_fillna_categorical_with_new_categories(
self, new_categories, fill_value, expected_output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need new_categories at all? Can you not create the series with categories=['a', 'b', 'c', 'd', 'e']?

Can you add a test where the original series and the fill_value series have the same categories, but in different order?

s = pd.Series(pd.Categorical(['a', None, 'b'], categories=['b', 'c', 'a']))
s.fillna(pd.Series(pd.Categorical(['a', 'c', 'a'], categories=['c', 'a', 'b']))

…e fill value series values are in different order
@TomAugspurger
Copy link
Contributor

Can you add the test from #27932 (comment)?

We've had issues in the past with unordered categories where the categories / codes didn't line up.

@MarcoGorelli
Copy link
Member Author

Sure :) I've added a test where the fill value is a series with the same categories as the original series but in a different order, sorry for having missed this the first time

@jschendel jschendel added Bug Categorical Categorical Data Type Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Aug 15, 2019
@jschendel jschendel added this to the 0.25.1 milestone Aug 15, 2019
@TomAugspurger
Copy link
Contributor

Looks great @MarcoGorelli. Thanks!

@TomAugspurger TomAugspurger merged commit ca5198a into pandas-dev:master Aug 16, 2019
meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Aug 16, 2019
jreback pushed a commit that referenced this pull request Aug 16, 2019
@MarcoGorelli MarcoGorelli deleted the categorical-fillna branch August 22, 2019 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Categorical Categorical Data Type Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fillna using columns of dtype category also fills non-NaN values

4 participants