@@ -28,6 +28,12 @@ def _(mo):
2828 return
2929
3030
31+ @app .cell
32+ def _ (mo ):
33+ mo .md (r"""## Motivation""" )
34+ return
35+
36+
3137@app .cell
3238def _ ():
3339 from datetime import datetime
@@ -54,6 +60,24 @@ def _():
5460 return (data ,)
5561
5662
63+ @app .cell
64+ def _ (data , pd ):
65+ pdf = pd .DataFrame (data )
66+ pdf ["sales" ] = pdf .groupby ("store" )["sales" ].ffill ()
67+ pdf
68+ return
69+
70+
71+ @app .cell
72+ def _ (data , pl ):
73+ lazy_df = pl .DataFrame (data ).lazy ()
74+ lazy_df .with_columns (
75+ pl .col ("sales" ).fill_null (strategy = "forward" ).over ("store" )
76+ ).collect ()
77+ # ⚠️ This may not work as expected unless you specify order_by="sale_date"
78+ return
79+
80+
5781@app .cell (hide_code = True )
5882def _ (mo ):
5983 mo .md (r"""## Eager-only solution""" )
@@ -90,7 +114,7 @@ def _(agnostic_ffill_by_store, data):
90114 # polars.DataFrame
91115 df_polars = pl .DataFrame (data )
92116 agnostic_ffill_by_store (df_polars )
93- return ( df_pandas ,)
117+ return df_pandas , df_polars , pd , pl
94118
95119
96120@app .cell
@@ -102,6 +126,13 @@ def _():
102126 return (duckdb_rel ,)
103127
104128
129+ @app .cell
130+ def _ ():
131+ # agnostic_ffill_by_store(duckdb_rel)
132+ # Error: narwhals.exceptions.OrderDependentExprError: Order-dependent expressions are not supported for use in LazyFrame.
133+ return
134+
135+
105136@app .cell (hide_code = True )
106137def _ (mo ):
107138 mo .md (r"""## Eager and lazy solution""" )
@@ -130,6 +161,12 @@ def _(agnostic_ffill_by_store_improved, duckdb_rel):
130161 return
131162
132163
164+ @app .cell
165+ def _ (agnostic_ffill_by_store_improved , df_polars ):
166+ agnostic_ffill_by_store_improved (df_polars .lazy ()).collect ()
167+ return
168+
169+
133170@app .cell
134171def _ (agnostic_ffill_by_store_improved , df_pandas ):
135172 # Note that it still supports pandas
0 commit comments