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

Pipe joining #214

Open
Hugovdberg opened this issue Jul 28, 2024 · 0 comments
Open

Pipe joining #214

Hugovdberg opened this issue Jul 28, 2024 · 0 comments

Comments

@Hugovdberg
Copy link

Is your feature request related to a problem? Please describe.
Every once in a while I encounter a method that is not curried, which I would like to use in a expression.pipe, more often than not methods on pandas.DataFrame's. There currently is a way to curry the method inline:

res = expression.pipe(
    df,
    expression.curry_flip(1)(pd.DataFrame.merge)(df2)
)

However, all the parentheses become quite ugly and unreadable.

Describe the solution you'd like
We can of course make this a little better with a helper function that does the curry_flip of the first argument:

join = expression.curry_flip(1)
res = expression.pipe(
    df,
    join(pd.DataFrame.merge)(df2)
)

This is a little better, but the double pair of parentheses still feels off. Therefore, I propose to include a function to do this natively:

_a = TypeVar("_a")
_b = TypeVar("_b")
_P = ParamSpec("_P")


def join(
    func: Callable[Concatenate[_a, _P], _b], *args: _P.args, **kwargs: _P.kwargs
) -> Callable[[_a], _b]:
    return expression.curry_flip(1)(func)(*args, **kwargs)

res = expression.pipe(
    df,
    join(pd.DataFrame.merge, df2)
)

Describe alternatives you've considered
The name might be something to discuss, but conceptually join makes the most sense to me as you are joining segments in a pipeline. However, the generic name might make it a little confusing, so perhaps this should be made clear from the namespace.

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

No branches or pull requests

1 participant