Skip to content

CLN: Assorted cleanups #52318

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

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2832,18 +2832,17 @@ def blk_func(values: ArrayLike) -> ArrayLike:
else:
# We broadcast algorithms.take_nd analogous to
# np.take_along_axis

# Note: we only get here with backfill/pad,
# so if we have a dtype that cannot hold NAs,
# then there will be no -1s in indexer, so we can use
# the original dtype (no need to ensure_dtype_can_hold_na)
if isinstance(values, np.ndarray):
dtype = values.dtype
if self.grouper.has_dropped_na:
# dropped null groups give rise to nan in the result
dtype = ensure_dtype_can_hold_na(values.dtype)
out = np.empty(values.shape, dtype=dtype)
else:
# Note: we only get here with backfill/pad,
# so if we have a dtype that cannot hold NAs,
# then there will be no -1s in indexer, so we can use
# the original dtype (no need to ensure_dtype_can_hold_na)
out = type(values)._empty(values.shape, dtype=values.dtype)

for i, value_element in enumerate(values):
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/groupby/test_api_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import inspect

import pytest

from pandas import (
DataFrame,
Series,
Expand All @@ -17,8 +19,8 @@
def test_frame_consistency(groupby_func):
# GH#48028
if groupby_func in ("first", "last"):
# first and last are entirely different between frame and groupby
return
msg = "first and last are entirely different between frame and groupby"
pytest.skip(reason=msg)

if groupby_func in ("cumcount", "ngroup"):
assert not hasattr(DataFrame, groupby_func)
Expand Down