-
Notifications
You must be signed in to change notification settings - Fork 170
refactor: Enforce LazyExpr._from_elementwise_horizontal_op
#2718
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
Merged
+115
β91
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6de5a59
refactor: Enforce `LazyExpr.from_elementwise`
dangotbanned 08dfcbe
Merge branch 'main' into lazy-expr-from-elementwise
dangotbanned ea354cd
Merge branch 'main' into lazy-expr-from-elementwise
dangotbanned 79399c9
Merge branch 'main' into lazy-expr-from-elementwise
dangotbanned 8c333fd
Merge remote-tracking branch 'upstream/main' into lazy-expr-from-elemβ¦
MarcoGorelli ceb4e8d
rename to _from_elementwise_horizontal_op
MarcoGorelli ac88ddc
fix typing
MarcoGorelli 91e814d
actually fix typing
MarcoGorelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,11 +21,15 @@ | |
| narwhals_to_native_dtype, | ||
| when, | ||
| ) | ||
| from narwhals._expression_parsing import ExprKind | ||
| from narwhals._expression_parsing import ( | ||
| ExprKind, | ||
| combine_alias_output_names, | ||
| combine_evaluate_output_names, | ||
| ) | ||
| from narwhals._utils import Implementation, not_implemented, requires | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Sequence | ||
| from collections.abc import Iterable, Sequence | ||
|
|
||
| from duckdb import Expression | ||
| from typing_extensions import Self | ||
|
|
@@ -213,6 +217,32 @@ def func(df: DuckDBLazyFrame) -> list[Expression]: | |
| version=context._version, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def from_elementwise( | ||
| cls, func: Callable[[Iterable[Expression]], Expression], *exprs: Self | ||
| ) -> Self: | ||
| def call(df: DuckDBLazyFrame) -> list[Expression]: | ||
| cols = (col for _expr in exprs for col in _expr(df)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these could just be: return [func(chain.from_iterable(expr(df) for expr in exprs))] |
||
| return [func(cols)] | ||
|
|
||
| def window_function( | ||
| df: DuckDBLazyFrame, window_inputs: DuckDBWindowInputs | ||
| ) -> list[Expression]: | ||
| cols = ( | ||
| col for _expr in exprs for col in _expr.window_function(df, window_inputs) | ||
| ) | ||
| return [func(cols)] | ||
|
|
||
| context = exprs[0] | ||
| return cls( | ||
| call=call, | ||
| window_function=window_function, | ||
| evaluate_output_names=combine_evaluate_output_names(*exprs), | ||
| alias_output_names=combine_alias_output_names(*exprs), | ||
| backend_version=context._backend_version, | ||
| version=context._version, | ||
| ) | ||
|
|
||
| def _callable_to_eval_series( | ||
| self, call: Callable[..., Expression], /, **expressifiable_args: Self | Any | ||
| ) -> EvalSeries[DuckDBLazyFrame, Expression]: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@MarcoGorelli would you be open to adding a little doc here? π
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.
Actually, another thought.
What about
LazyExpr.from_horizontal_op?That would mirror the same constructor these all use for
ExprMetadatanarwhals/narwhals/functions.py
Lines 1369 to 1374 in f17acfc
narwhals/narwhals/_expression_parsing.py
Lines 477 to 481 in f17acfc
I think the detail that we should use this for
*_horizontal(andconcat_str) is more relevant than theelementwisepart