From 7313bb340bcb65d399ea036b0ec627d3c2ea3331 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 30 Aug 2021 13:28:10 -0700 Subject: [PATCH] PERF: GroupBy.cumsum --- pandas/core/internals/managers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index d1dc2aa7bd43f..2c73fe5a8b5bc 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -526,7 +526,13 @@ def get_numeric_data(self: T, copy: bool = False) -> T: copy : bool, default False Whether to copy the blocks """ - return self._combine([b for b in self.blocks if b.is_numeric], copy) + numeric_blocks = [blk for blk in self.blocks if blk.is_numeric] + if len(numeric_blocks) == len(self.blocks): + # Avoid somewhat expensive _combine + if copy: + return self.copy(deep=True) + return self + return self._combine(numeric_blocks, copy) def _combine( self: T, blocks: list[Block], copy: bool = True, index: Index | None = None