-
Notifications
You must be signed in to change notification settings - Fork 209
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Support for Ibis expressions #659
Comments
After perusing the repo, it looks like ibis might be able to implement a |
After adding a |
I have had discussions (cc @machow) on internals that are agnostic about the type of dataframe by using some kind of adapter API and |
Hey @cpcloud, were you able to get the ibis lazy expressions to evaluate inside It seems like a pretty nice feature, and I'm happy to help dig around (especially since selfishly it'd be useful to chuck in lazy expressions from siuba 馃槄) |
The expressions will not work. |
It seems like--since both libraries are able to translate expressions into pandas code--plotnine exposing some kind of generic function (that they could import, or register to via an entrypoint?) might let them put their transformations in? For example, in siuba... # generic to_transform function, with siuba implementation ----
from functools import singledispatch
from siuba.siu import Call, Symbolic, strip_symbolic
# define generic
@singledispatch
def to_transform(expr):
raise NotImplementedError(f"Unsupported type: {type(expr)}")
# register siuba implementation
@to_transform.register(Symbolic)
@to_transform.register(Call)
def _to_transform_siuba(expr: "Symbolic | Call") -> Call:
return strip_symbolic(expr)
# Apply a siuba symbolic (lazy expression) to a pandas DataFrame ----
from plotnine.data import mtcars
from siuba import _
f_transform = to_transform(_.mpg - _.mpg.mean())
f_transform(mtcars) In the same way, ibis could translate its expression using its pandas backend and return a callable. It seems like this approach would be similar to allowing lambdas in aes... from plotnine import *
from plotnine.data import mtcars
# note the x argument is a lambda
ggplot(mtcars, aes(x=lambda d: d["cyl"], y="mpg")) Which I think doesn't work, since plotnine needs to know an extra piece?:
|
The main issue is that, past some point plotnine only wants to deal with straight up pandas frames, and that point comes before the evaluations and cannot be pushed after them.
The solution has to be more comprehensive. |
If I understand correctly, both libraries should be able to supply DataFrames (e.g. via |
Yes the expression have to match. I think it may be doable. e.g. If the expressions know how to convert themselves e.g. expr: Symbolic = _.mpg - _.mpg.mean()
expr_str: str = expr.to_p9_aes_expr() Then plotnine can simply check for |
Hi! 馃憢馃徎
I'm the lead developer of the Ibis project.
I recently did a write up of some analysis of Ibis's CI data using Ibis and
plotnine
.I think plotnine is just the bee's knees, and I think ibis and plotnine could be even better together than they are right now.
What would it take to support ibis expressions? I am happy to take this all the way through myself, PR-ing to this repo as well as make any fixes to ibis that might be needed, but I want to check in to make sure this work would have a chance at getting in!
Here's an example from the above notebook where it would be great if I could pass in my ibis objects without having to first turn them into pandas DataFrames:
Instead, I'd like to write the following:
The text was updated successfully, but these errors were encountered: