Skip to content

REF: avoid getattr pattern in libgroupby rank functions #29166

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

Merged
merged 2 commits into from
Oct 22, 2019

Conversation

jbrockmendel
Copy link
Member

cc @WillAyd do we need to do anything special w/r/t the comment on L1220 re #19560?

@gfyoung gfyoung added Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code labels Oct 22, 2019
# Note: we do not have a group_rank_object because that would require a
# not-nogil implementation, see GH#19560


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these just unused?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at get_cython_function in groupby.ops, you'll see we do a thing with checking for libgroupby func_name and then libgroupby.func_name_dtype. This pattern was put in place back before we started using fused types for libgroupby, and now cython effectively choose the correct func_name_dtype for us when we just use func_name

@WillAyd
Copy link
Member

WillAyd commented Oct 22, 2019

cc @WillAyd do we need to do anything special w/r/t the comment on L1220 re #19560?

Is this changing behavior when trying to rank objects? I think on master raises an error

>>> pd.DataFrame([[1]], dtype=object).groupby([1]).rank()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/williamayd/clones/pandas/pandas/core/groupby/groupby.py", line 2144, in rank
    axis=axis,
  File "/Users/williamayd/clones/pandas/pandas/core/groupby/groupby.py", line 867, in _cython_transform
    result, _ = self.grouper.transform(obj.values, how, **kwargs)
  File "/Users/williamayd/clones/pandas/pandas/core/groupby/ops.py", line 621, in transform
    return self._cython_operation("transform", values, how, axis, **kwargs)
  File "/Users/williamayd/clones/pandas/pandas/core/groupby/ops.py", line 583, in _cython_operation
    result, values, labels, func, is_numeric, is_datetimelike, **kwargs
  File "/Users/williamayd/clones/pandas/pandas/core/groupby/ops.py", line 658, in _transform
    transform_func(result, values, comp_ids, ngroups, is_datetimelike, **kwargs)
  File "/Users/williamayd/clones/pandas/pandas/core/groupby/ops.py", line 441, in wrapper
    return f(afunc, *args, **kwargs)
  File "/Users/williamayd/clones/pandas/pandas/core/groupby/ops.py", line 393, in <lambda>
    kwargs.get("na_option", "keep"),
TypeError: 'NoneType' object is not callable

Though not sure how well tested that is. Ideally would be explicitly disallowed but looks like that PR is still open, so might want to be careful when changing this

@jbrockmendel
Copy link
Member Author

Is this changing behavior when trying to rank objects? I think on master raises an error

The same example now raises pandas.core.base.DataError: No numeric types to aggregate

@jreback jreback added this to the 1.0 milestone Oct 22, 2019
@jreback jreback merged commit 33c1b21 into pandas-dev:master Oct 22, 2019
@jreback
Copy link
Contributor

jreback commented Oct 22, 2019

thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the cypattern branch October 22, 2019 20:21
HawkinsBA pushed a commit to HawkinsBA/pandas that referenced this pull request Oct 29, 2019
Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
bongolegend pushed a commit to bongolegend/pandas that referenced this pull request Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants