BUG: Groupby.last accepts min_count but implementation raises (original) (raw)


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

df = DataFrame({"a": [1, 2, 3, 4, 5, 6]}) df.groupby(level=0).last(min_count=1)

Problem description

This raises

Traceback (most recent call last):
  File "/home/developer/.config/JetBrains/PyCharm2020.2/scratches/scratch_4.py", line 97, in <module>
    print(df.groupby(level=0).last(min_count=1))
  File "/home/developer/PycharmProjects/pandas/pandas/core/groupby/groupby.py", line 1710, in last
    return self._agg_general(
  File "/home/developer/PycharmProjects/pandas/pandas/core/groupby/groupby.py", line 1032, in _agg_general
    result = self._cython_agg_general(
  File "/home/developer/PycharmProjects/pandas/pandas/core/groupby/generic.py", line 1018, in _cython_agg_general
    agg_mgr = self._cython_agg_blocks(
  File "/home/developer/PycharmProjects/pandas/pandas/core/groupby/generic.py", line 1116, in _cython_agg_blocks
    new_mgr = data.apply(blk_func, ignore_failures=True)
  File "/home/developer/PycharmProjects/pandas/pandas/core/internals/managers.py", line 425, in apply
    applied = b.apply(f, **kwargs)
  File "/home/developer/PycharmProjects/pandas/pandas/core/internals/blocks.py", line 368, in apply
    result = func(self.values, **kwargs)
  File "/home/developer/PycharmProjects/pandas/pandas/core/groupby/generic.py", line 1067, in blk_func
    result, _ = self.grouper.aggregate(
  File "/home/developer/PycharmProjects/pandas/pandas/core/groupby/ops.py", line 594, in aggregate
    return self._cython_operation(
  File "/home/developer/PycharmProjects/pandas/pandas/core/groupby/ops.py", line 547, in _cython_operation
    result = self._aggregate(result, counts, values, codes, func, min_count)
  File "/home/developer/PycharmProjects/pandas/pandas/core/groupby/ops.py", line 608, in _aggregate
    agg_func(result, counts, values, comp_ids, min_count)
  File "pandas/_libs/groupby.pyx", line 906, in pandas._libs.groupby.group_last
AssertionError: 'min_count' only used in add and prod

Process finished with exit code 1

Expected Output

I would expect, that this function does not accept min_count as input (similar to Resample.last) and raises the same error as described in #37768
Additonally the docs need adjustments, because min_count is documented. This probably holds true for most of the functions mentioned in #37768 (comment) too.

Output of pd.show_versions()

Details

master