-
Notifications
You must be signed in to change notification settings - Fork 86
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
docs: explain translation from narwhals api to native api #684
Conversation
19086cd
to
f3d39b8
Compare
thanks @amol- , amazing stuff here! I've just reworded it a bit, and will try to do a bit more tomorrow, but I think this is super-important to be documented, so thanks a tonne for having started it π |
@MarcoGorelli I think that in the rewording we lost a little bit the message that the last part tried to convey. I'm referring to this part: After a compliant object is returned, the user will keep using and perform For example ArrowExpr(depth=0, function_name=col, root_names=['b'], output_names=['b'] but invoking >>> nwexpr = nw.col("b")
>>> type(nwexpr)
<class 'narwhals.stable.v1.Expr'>
>>> nwr = nwdf.select(nw.col("b"))
>>> type(nwr)
<class 'narwhals.stable.v1.DataFrame'>
>>> arrowexpr = nw.col("b")._call(nwdf.__narwhals_namespace__())
>>> type(arrowexpr)
<class 'narwhals._arrow.expr.ArrowExpr'>
>>> nwr = nwdf.select(arrowexpr)
>>> type(nwr)
<class 'narwhals.stable.v1.DataFrame'> |
Thanks - I'll double check but I'm not sure it's intentional that that's supported |
In fact, I just applied the following diff, ran the test suite, and no test failed: diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py
index 644db7bc..07c567bd 100644
--- a/narwhals/dataframe.py
+++ b/narwhals/dataframe.py
@@ -123,6 +123,9 @@ class BaseFrame(Generic[FrameT]):
*exprs: IntoExpr | Iterable[IntoExpr],
**named_exprs: IntoExpr,
) -> Self:
+ from narwhals._pandas_like.expr import PandasLikeExpr
+ if any(isinstance(x, PandasLikeExpr) for x in exprs):
+ 1/0 Passing a compliant Expr to |
Ah good to know, I thought that the interoperability was by design. So every API always should invoke |
Yup! I think the type hints usually make that clear? Most methods return Anyway, thanks for your PR, let's ship this |
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.
thanks @amol- !
What type of PR is this? (check all applicable)
If you have comments or can explain your changes, please do so below.
The current documentation is unclear about the how objects move from narwhals api to polars compatible backend to native api. This adds a section that tries to make that more clear.