Skip to content

Commit f5e8d08

Browse files
committed
feat: Add polars_expr_to_dict
1 parent 0707dbd commit f5e8d08

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

narwhals/_plan/meta.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def is_regex_projection(self) -> bool:
6262
raise NotImplementedError
6363

6464

65-
def profile_polars_expr(expr: pl.Expr) -> dict[str, Any]:
65+
def polars_expr_metadata(expr: pl.Expr) -> dict[str, Any]:
6666
"""Gather all metadata for a native `Expr`.
6767
6868
Eventual goal would be that a `nw.Expr` matches a `pl.Expr` in as much of this as possible.
@@ -83,3 +83,15 @@ def profile_polars_expr(expr: pl.Expr) -> dict[str, Any]:
8383
"undo_aliases": expr.meta.undo_aliases(),
8484
"expr": expr,
8585
}
86+
87+
88+
def polars_expr_to_dict(expr: pl.Expr) -> dict[str, Any]:
89+
"""Serialize a native `Expr`, roundtrip back to `dict`.
90+
91+
Using to inspect [`FunctionOptions`] and ensure we combine them in a similar way.
92+
93+
[`FunctionOptions`]: https://github.com/narwhals-dev/narwhals/pull/2572#issuecomment-2891577685
94+
"""
95+
import json
96+
97+
return json.loads(expr.meta.serialize(format="json")) # type: ignore[no-any-return]

0 commit comments

Comments
 (0)