From 5293bd7f730edc84e715ca2b023ef56db88db0b3 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Tue, 6 Jul 2021 10:38:54 -0400 Subject: [PATCH 1/2] REF: Skip all empty groups in _transform_general --- pandas/core/groupby/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 49a90470be803..c00ed24287cd8 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1309,6 +1309,8 @@ def _transform_general(self, func, *args, **kwargs): fast_path, slow_path = self._define_paths(func, *args, **kwargs) for name, group in gen: + if not np.prod(group.shape): + continue object.__setattr__(group, "name", name) # Try slow path and fast path. @@ -1325,9 +1327,7 @@ def _transform_general(self, func, *args, **kwargs): # we need to broadcast across the # other dimension; this will preserve dtypes # GH14457 - if not np.prod(group.shape): - continue - elif res.index.is_(obj.index): + if res.index.is_(obj.index): r = concat([res] * len(group.columns), axis=1) r.columns = group.columns r.index = group.index From c14720a20d95ea5444e11bfe9655b9ba92cab94b Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Tue, 6 Jul 2021 13:43:19 -0400 Subject: [PATCH 2/2] Use size --- pandas/core/groupby/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index c00ed24287cd8..382cd0e178e15 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1309,7 +1309,7 @@ def _transform_general(self, func, *args, **kwargs): fast_path, slow_path = self._define_paths(func, *args, **kwargs) for name, group in gen: - if not np.prod(group.shape): + if group.size == 0: continue object.__setattr__(group, "name", name)