-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
# Note: we do not have a group_rank_object because that would require a | ||
# not-nogil implementation, see GH#19560 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these just unused?
There was a problem hiding this comment.
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
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 |
The same example now raises |
thanks @jbrockmendel |
cc @WillAyd do we need to do anything special w/r/t the comment on L1220 re #19560?