Skip to content

Commit 5872bfe

Browse files
authored
PERF: grouped_reduce (pandas-dev#43576)
1 parent 0914808 commit 5872bfe

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pandas/core/internals/managers.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ def grouped_reduce(self: T, func: Callable, ignore_failures: bool = False) -> T:
12481248
BlockManager
12491249
"""
12501250
result_blocks: list[Block] = []
1251+
dropped_any = False
12511252

12521253
for blk in self.blocks:
12531254
if blk.is_object:
@@ -1259,6 +1260,7 @@ def grouped_reduce(self: T, func: Callable, ignore_failures: bool = False) -> T:
12591260
except (TypeError, NotImplementedError):
12601261
if not ignore_failures:
12611262
raise
1263+
dropped_any = True
12621264
continue
12631265
result_blocks = extend_blocks(applied, result_blocks)
12641266
else:
@@ -1267,6 +1269,7 @@ def grouped_reduce(self: T, func: Callable, ignore_failures: bool = False) -> T:
12671269
except (TypeError, NotImplementedError):
12681270
if not ignore_failures:
12691271
raise
1272+
dropped_any = True
12701273
continue
12711274
result_blocks = extend_blocks(applied, result_blocks)
12721275

@@ -1275,7 +1278,8 @@ def grouped_reduce(self: T, func: Callable, ignore_failures: bool = False) -> T:
12751278
else:
12761279
index = Index(range(result_blocks[0].values.shape[-1]))
12771280

1278-
if ignore_failures:
1281+
if dropped_any:
1282+
# faster to skip _combine if we haven't dropped any blocks
12791283
return self._combine(result_blocks, copy=False, index=index)
12801284

12811285
return type(self).from_blocks(result_blocks, [self.axes[0], index])

0 commit comments

Comments
 (0)