Skip to content
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

Support for user-defined grouped pandas operations #146

Closed
machow opened this issue Oct 27, 2019 · 0 comments
Closed

Support for user-defined grouped pandas operations #146

machow opened this issue Oct 27, 2019 · 0 comments

Comments

@machow
Copy link
Owner

machow commented Oct 27, 2019

E.g. take the n function...

@symbolic_dispatch
def n(x):
    """Return the total number of elements in the array (or rows in a DataFrame).

    Example:
        >>> ser = pd.Series([1,2,3])
        >>> n(ser)
        3

        >>> df = pd.DataFrame({'x': ser})
        >>> n(df)
        3

    """
    if isinstance(x, pd.DataFrame):
        return x.shape[0]

    return len(x)

Could add a singledispatch for a SeriesGroupBy...

from siuba.experimental.pd_groups.groups import GroupByAgg

@n.register(SeriesGroupBy)
def _n_gser(x):
    return GroupByAgg.from_result(.x.size(), x)

This is a pretty cumbersome example, and it doesn't follow the dependency inversion principal, but could if vector functions were abstracted from their pandas implementations, similar to #141.

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

No branches or pull requests

1 participant