From 90597782bf5065d5b53ae6b6ab2910b1842ab602 Mon Sep 17 00:00:00 2001 From: arw2019 Date: Tue, 10 Nov 2020 19:48:59 +0000 Subject: [PATCH 1/3] CLN: don't hard code min_count in call to _libs.groupby.group_nth --- pandas/core/groupby/ops.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 438030008bb4d..d5050b4f6c895 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -603,8 +603,7 @@ def _aggregate( ): if agg_func is libgroupby.group_nth: # different signature from the others - # TODO: should we be using min_count instead of hard-coding it? - agg_func(result, counts, values, comp_ids, rank=1, min_count=-1) + agg_func(result, counts, values, comp_ids, rank=1, min_count=min_count) else: agg_func(result, counts, values, comp_ids, min_count) From 7517480166b1fb5ab2faca10720fca205880cbee Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Wed, 11 Nov 2020 06:37:52 +0000 Subject: [PATCH 2/3] REF/CLN (feedback): remove min_count arg from libgroupby.group_nth --- pandas/_libs/groupby.pyx | 5 +++-- pandas/core/groupby/ops.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index 5a958d5e0bd3c..5825fabce505b 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -986,8 +986,8 @@ def group_last(rank_t[:, :] out, def group_nth(rank_t[:, :] out, int64_t[:] counts, ndarray[rank_t, ndim=2] values, - const int64_t[:] labels, int64_t rank=1, - Py_ssize_t min_count=-1): + const int64_t[:] labels, int64_t rank=1 + ): """ Only aggregates on axis=0 """ @@ -997,6 +997,7 @@ def group_nth(rank_t[:, :] out, ndarray[rank_t, ndim=2] resx ndarray[int64_t, ndim=2] nobs bint runtime_error = False + Py_ssize_t min_count = -1 assert min_count == -1, "'min_count' only used in add and prod" diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index d5050b4f6c895..fc80852f00c95 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -603,7 +603,7 @@ def _aggregate( ): if agg_func is libgroupby.group_nth: # different signature from the others - agg_func(result, counts, values, comp_ids, rank=1, min_count=min_count) + agg_func(result, counts, values, comp_ids, rank=1) else: agg_func(result, counts, values, comp_ids, min_count) From e5cacfb961224036dcaf8ed297dd348a04269481 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Wed, 11 Nov 2020 07:04:49 +0000 Subject: [PATCH 3/3] CLN: remove references to min_count in libgroupby.group_nth --- pandas/_libs/groupby.pyx | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index 5825fabce505b..438d9fa625737 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -997,9 +997,6 @@ def group_nth(rank_t[:, :] out, ndarray[rank_t, ndim=2] resx ndarray[int64_t, ndim=2] nobs bint runtime_error = False - Py_ssize_t min_count = -1 - - assert min_count == -1, "'min_count' only used in add and prod" # TODO(cython 3.0): # Instead of `labels.shape[0]` use `len(labels)`