Skip to content

BUG: Allow __name__less callables as groupby hows (GH7929) #7974

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 1 commit into from
Aug 10, 2014

Conversation

dsm054
Copy link
Contributor

@dsm054 dsm054 commented Aug 10, 2014

Allow functools.partial objects (and similar callables without __name__ attributes) to be used as groupby functions, which also adds support along the tree (e.g. resample, which is specifically tested.)

Closes #7929.

This does not address the potential enhancements allowing automatic naming of duplicate-named functions (relatively minor) and the use of a Series to specify names (more useful).

@jreback jreback added this to the 0.15.0 milestone Aug 10, 2014
return _get_callable_name(obj.func)
# fallback to class name
if hasattr(obj, '__call__'):
return obj.__class__.__name__
Copy link
Contributor

Choose a reason for hiding this comment

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

if this fails it returns None? (not sure what would hit that, but maybe make explicit)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it returns None, not the empty string (assert getname(1) is None), if it can't figure out what do to. You'd have to work pretty hard to have something callable which didn't have __call__.. I can add a comment/return None if you'd like, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep an explicty None return (and/or comment) is good. lmk after you push and green.

@jreback
Copy link
Contributor

jreback commented Aug 10, 2014

@dsm054 minor comment, otherwise looks good

@dsm054
Copy link
Contributor Author

dsm054 commented Aug 10, 2014

Explicit return None and justification for it added; all green.

jreback added a commit that referenced this pull request Aug 10, 2014
BUG: Allow __name__less callables as groupby hows (GH7929)
@jreback jreback merged commit 5d4ce99 into pandas-dev:master Aug 10, 2014
@jreback
Copy link
Contributor

jreback commented Aug 10, 2014

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: resample unexpectedly branching on type of how callable
2 participants