@@ -28,6 +28,12 @@ def _(mo):
28
28
return
29
29
30
30
31
+ @app .cell
32
+ def _ (mo ):
33
+ mo .md (r"""## Motivation""" )
34
+ return
35
+
36
+
31
37
@app .cell
32
38
def _ ():
33
39
from datetime import datetime
@@ -54,6 +60,24 @@ def _():
54
60
return (data ,)
55
61
56
62
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
+
57
81
@app .cell (hide_code = True )
58
82
def _ (mo ):
59
83
mo .md (r"""## Eager-only solution""" )
@@ -90,7 +114,7 @@ def _(agnostic_ffill_by_store, data):
90
114
# polars.DataFrame
91
115
df_polars = pl .DataFrame (data )
92
116
agnostic_ffill_by_store (df_polars )
93
- return ( df_pandas ,)
117
+ return df_pandas , df_polars , pd , pl
94
118
95
119
96
120
@app .cell
@@ -102,6 +126,13 @@ def _():
102
126
return (duckdb_rel ,)
103
127
104
128
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
+
105
136
@app .cell (hide_code = True )
106
137
def _ (mo ):
107
138
mo .md (r"""## Eager and lazy solution""" )
@@ -130,6 +161,12 @@ def _(agnostic_ffill_by_store_improved, duckdb_rel):
130
161
return
131
162
132
163
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
+
133
170
@app .cell
134
171
def _ (agnostic_ffill_by_store_improved , df_pandas ):
135
172
# Note that it still supports pandas
0 commit comments