BUG: groupby with nans always places nans last #46584
Labels
Algos
Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff
Apply
Apply, Aggregate, Transform, Map
Bug
Groupby
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone
Marking as milestone 1.5 because this issue was introduced by #45953. While the output of the transform op below was also incorrect prior to this PR, we are reporting this kind of op as being fixed in the whatsnew.
When specifying
sort=False
anddropna=False
in groupby, any null groupers are moved to the end, even whensort=False
:gives
This is because nan is always given the largest code from factorize:
While only a minor issue for aggregations, transform depends on the code being properly ordered.
The text was updated successfully, but these errors were encountered: