Skip to content

BUG: Groupby.last accepts min_count but implementation raises #37821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
phofl opened this issue Nov 13, 2020 · 0 comments · Fixed by #37870
Closed
3 tasks done

BUG: Groupby.last accepts min_count but implementation raises #37821

phofl opened this issue Nov 13, 2020 · 0 comments · Fixed by #37870
Labels
Bug Docs Groupby Needs Triage Issue that has not been reviewed by a pandas team member
Milestone

Comments

@phofl
Copy link
Member

phofl commented Nov 13, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


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()

master

@phofl phofl added Bug Needs Triage Issue that has not been reviewed by a pandas team member Docs Groupby labels Nov 13, 2020
@jreback jreback added this to the 1.2 milestone Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Docs Groupby Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants