Skip to content

BUG FIX: groupby.last() no longer changes np arrays with pd.NA to dtype Int64 #46787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
6 changes: 3 additions & 3 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ Performance improvements
.. _whatsnew_150.bug_fixes:

Bug fixes
~~~~~~~~~
- Bug in :func:`_call_cython_op` that caused numpy arrays ordered with last with pd.NA to have dytype:Int64 type rather than dtype:Bool (:issue:`46409`)

Categorical
^^^^^^^^^^^
Expand All @@ -477,12 +477,12 @@ Datetimelike

Timedelta
^^^^^^^^^
- Bug in :func:`astype_nansafe` astype("timedelta64[ns]") fails when np.nan is included (:issue:`45798`)
- Bug FIXED in :func:`astype_nansafe` astype("timedelta64[ns]") fails when np.nan is included (:issue:`45798`)
-

Time Zones
^^^^^^^^^^
-
-

Numeric
^^^^^^^
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ def _call_cython_op(
**kwargs,
)

if self.how == 'last' and dtype == bool:
for val in result:
if val > 1 or val < 0:
result = values

if self.kind == "aggregate":
# i.e. counts is defined. Locations where count<min_count
# need to have the result set to np.nan, which may require casting,
Expand Down
Loading