ENH: Consistent NA handling in unique()
, and nunique()
#61209
Labels
Algos
Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff
Enhancement
Needs Discussion
Requires discussion from core team before further action
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Currently
Series.nunique
has a default parameterdropna=True
.However
Series.unique
does not accept thedropna
the parameter.This can cause the unexpected behaviour when:
s.nunique()
is not nessesarly equal tolen(s.unique())
.See example below:
I believe it should be addressed to avoid implicit behaviour.
Feature Description
Simplest way to addess it would be to change the default parameter of
Series.nunique
todropna=False
.Analogously the same default parameter for
DataFrame.nunique
.This would be consistent with current summary of the method:
"Can ignore NaN values.", hints that should be optional parameter not enabled by default.
Alternative Solutions
Another approach to force consistent NaN handling by default would be to addapt
Series.unique
to acceptdropna
and set it toTrue
by default.Although possible, this is more laborious and more impactful change on Pandas API.
Additional Context
No response
EDIT: Typos
The text was updated successfully, but these errors were encountered: