From 86c18e0306f9baeb6e35e594bd78737922f54d8d Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 2 May 2021 14:44:14 -0700 Subject: [PATCH 1/3] CLN: remove squeeze kwarg from extract_result --- pandas/_libs/reduction.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index c28db9b669a4b..ba5b05dff47e4 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -308,7 +308,7 @@ cpdef inline extract_result(object res): res = res._values if res.ndim == 1 and len(res) == 1: res = res[0] - if hasattr(res, 'values') and is_array(res.values): + if hasattr(res, "values") and is_array(res.values): res = res.values if is_array(res): if res.ndim == 0: From dbb3612907e78c3fd7abf3461a2216bf6755bcd2 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 17 May 2021 21:45:30 -0700 Subject: [PATCH 2/3] CLN: unnecessary bits of libreduction.extract_result --- pandas/_libs/reduction.pyx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index ba5b05dff47e4..71a3f44af577f 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -307,13 +307,11 @@ cpdef inline extract_result(object res): # Preserve EA res = res._values if res.ndim == 1 and len(res) == 1: + # see test_agg_lambda_with_timezone, test_resampler_grouper.py::test_apply res = res[0] - if hasattr(res, "values") and is_array(res.values): - res = res.values if is_array(res): - if res.ndim == 0: - res = res.item() - elif res.ndim == 1 and len(res) == 1: + if res.ndim == 1 and len(res) == 1: + # see test_resampler_grouper.py::test_apply res = res[0] return res @@ -386,7 +384,7 @@ def apply_frame_axis0(object frame, object f, object names, # Need to infer if low level index slider will cause segfaults require_slow_apply = i == 0 and piece is chunk try: - if not piece.index is chunk.index: + if piece.index is not chunk.index: mutated = True except AttributeError: # `piece` might not have an index, could be e.g. an int From ec55507004659460dd1680c9b7f43f9d79c3f026 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 18 May 2021 08:25:26 -0700 Subject: [PATCH 3/3] CLN: remove unnecessary copy --- pandas/_libs/reduction.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index 71a3f44af577f..d730084692dd4 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -1,4 +1,3 @@ -from copy import copy from libc.stdlib cimport ( free, @@ -395,7 +394,7 @@ def apply_frame_axis0(object frame, object f, object names, try: piece = piece.copy(deep="all") except (TypeError, AttributeError): - piece = copy(piece) + pass results.append(piece)