Skip to content

Commit 5732544

Browse files
committed
Update documentation to not use deprecated window fn
1 parent 9e5af34 commit 5732544

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

docs/source/user-guide/common-operations/windows.rst

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ We'll use the pokemon dataset (from Ritchie Vink) in the following examples.
3131
.. ipython:: python
3232
3333
from datafusion import SessionContext
34-
from datafusion import col
34+
from datafusion import col, lit
3535
from datafusion import functions as f
3636
3737
ctx = SessionContext()
@@ -120,16 +120,14 @@ two preceding rows.
120120

121121
.. ipython:: python
122122
123-
from datafusion.expr import WindowFrame
123+
from datafusion.expr import Window, WindowFrame
124124
125125
df.select(
126126
col('"Name"'),
127127
col('"Speed"'),
128-
f.window("avg",
129-
[col('"Speed"')],
130-
order_by=[col('"Speed"')],
131-
window_frame=WindowFrame("rows", 2, 0)
132-
).alias("Previous Speed")
128+
f.avg(col('"Speed"'))
129+
.over(Window(window_frame=WindowFrame("rows", 2, 0), order_by=[col('"Speed"')]))
130+
.alias("Previous Speed"),
133131
)
134132
135133
Null Treatment
@@ -151,21 +149,27 @@ it's ``Type 2`` column that are null.
151149
152150
from datafusion.common import NullTreatment
153151
154-
df.filter(col('"Type 1"') == lit("Bug")).select(
152+
df.filter(col('"Type 1"') == lit("Bug")).select(
155153
'"Name"',
156154
'"Type 2"',
157-
f.window("last_value", [col('"Type 2"')])
158-
.window_frame(WindowFrame("rows", None, 0))
159-
.order_by(col('"Speed"'))
160-
.null_treatment(NullTreatment.IGNORE_NULLS)
161-
.build()
162-
.alias("last_wo_null"),
163-
f.window("last_value", [col('"Type 2"')])
164-
.window_frame(WindowFrame("rows", None, 0))
165-
.order_by(col('"Speed"'))
166-
.null_treatment(NullTreatment.RESPECT_NULLS)
167-
.build()
168-
.alias("last_with_null")
155+
f.last_value(col('"Type 2"'))
156+
.over(
157+
Window(
158+
window_frame=WindowFrame("rows", None, 0),
159+
order_by=[col('"Speed"')],
160+
null_treatment=NullTreatment.IGNORE_NULLS,
161+
)
162+
)
163+
.alias("last_wo_null"),
164+
f.last_value(col('"Type 2"'))
165+
.over(
166+
Window(
167+
window_frame=WindowFrame("rows", None, 0),
168+
order_by=[col('"Speed"')],
169+
null_treatment=NullTreatment.RESPECT_NULLS,
170+
)
171+
)
172+
.alias("last_with_null"),
169173
)
170174
171175
Aggregate Functions

0 commit comments

Comments
 (0)