feat: add rank for Lazy backends#2310
Conversation
|
Hey @raisadz thanks for the PR. I didn't have the time to look at this, I just wanted to drop a comment and ping @marvinl803 who also took a look at |
MarcoGorelli
left a comment
There was a problem hiding this comment.
thanks for working on this 🙌 !
it's occurred to me that we class rank as ExprKind.WINDOW and that, after narwhals.stable.v1, it won't be supported to use rank if not followed by over(order_by=...)
Here it works because the import is import narwhals.stable.v1 as nw, but would raise for import narwhals as nw
🤔 gonna have to think about a solution here, not super-sure
maybe, just maybe, we may want to introduce nw.rank instead of Expr.rank, because then that would compose more naturally with over. And for eager backends, nw.col('a').rank() does the same thing as nw.rank().over('a')
🤔 i'm not totally sure, will do a bit more thinking on this one, but i think we can come up with something
|
Having slept on this, I'd suggest: An alternative could be The only solution I can currently think of is: |
|
@MarcoGorelli I haven't looked into this more than your two comments, so apologies in advance if this seems too simplified of a view. IMO, the current I'm not sure how likely this would be, but another concern might be - what if |
|
agree, i'm also not keen on implementation contraints determining the api, ideally it should be the opposite... will think about this more, but maybe we could get to: ✅ allowed:
❌ disallowed:
Then there's also:
that requires a decision This involves more refactors, but...it's probably worth it |
|
@MarcoGorelli that seems consistent with the I don't know if this already plays a factor in the |
|
Yeah i think it's good to aim for as much expressivity as Polars offers, with the restriction that for LazyFrame we only allow relational expressions - so, |
There was a problem hiding this comment.
thanks @raisadz - I think we can ship this, we'll sort out .over behaviour later, just left a minor comment
| sql = ( | ||
| f"CASE WHEN {_input} IS NULL THEN NULL " | ||
| f"ELSE {func_name}() OVER ({order_by_sql}) END" | ||
| ) |
There was a problem hiding this comment.
can we flip this round (case when not-null), like you did for the spark-like case?
|
i'll address #2310 (comment) now, gonna start by getting this in though |
* feat(typing): Add `FromNative` protocol * chore(typing): Add `FromNative` to `CompliantSeries` - Adding `._is_native` made `TypeVar` invariant - Realistically, it always was, but underspecified * feat: Implement for `(Arrow|PandasLike)Series` * feat: Implement for `PolarsSeries` + get some coverage * chore: `ArrowSeries` coverage * chore: `PandasLikeSeries` partial coverage * ignore coverage for now ... * feat(typing): Add `CompliantDataFrame.from_native` * feat: Implement for `ArrowDataFrame` Also coverage for `ArrowSeries` * feat: Implement for `PandasLikeDataFrame` Loads of coverage for both `PandasLike` * feat: Implement for `PolarsDataFrame` * refactor: Found one more * chore(typing): Fix missing `SQLExpression` ignore Was missed in (#2310) * feat: Implement `EagerNamespace.from_native` - `Polars*` will also need to handle `LazyFrame` - `Lazy*` has other constraints * feat: Add `Polars(Namespace|LazyFrame).from_native` Probably need to add a `LazyNamespace` protocol for `LazyOnly` * chore: Ignore coverage `PandasLikeDataFrame._is_native` Nowhere to use it yet, current stuff uses the more precise `self.native.__class__` * feat: Add all `CompliantLazyFrame.from_native` * feat: Add `LazyNamespace.from_native` * refactor: Get some lazy coverage https://github.com/narwhals-dev/narwhals/actions/runs/14157697512/job/39659084059?pr=2315 * refactor: More `polars` coverage https://github.com/narwhals-dev/narwhals/actions/runs/14158424987/job/39660662342?pr=2315 * refactor: reuse `is_spark_like_dataframe` * Update narwhals/_compliant/namespace.py Co-authored-by: Dan Redding <125183946+dangotbanned@users.noreply.github.com> --------- Co-authored-by: Marco Edward Gorelli <marcogorelli@protonmail.com>

What type of PR is this? (check all applicable)
Related issues
Checklist
If you have comments or can explain your changes, please do so below
Only
minanddensemethods are implemented for DuckDB and PySpark without.over().