Skip to content

Commit 9e5af34

Browse files
committed
Add support for passing filter and distinct in window()
1 parent 24a59f2 commit 9e5af34

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

python/datafusion/functions.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
sort_or_default,
3535
)
3636

37+
try:
38+
from warnings import deprecated # Python 3.13+
39+
except ImportError:
40+
from typing_extensions import deprecated # Python 3.12
41+
3742
if TYPE_CHECKING:
3843
from datafusion.context import SessionContext
3944

@@ -426,12 +431,15 @@ def when(when: Expr, then: Expr) -> CaseBuilder:
426431
return CaseBuilder(f.when(when.expr, then.expr))
427432

428433

434+
@deprecated("Prefer to call Expr.over() instead")
429435
def window(
430436
name: str,
431437
args: list[Expr],
432438
partition_by: list[Expr] | Expr | None = None,
433439
order_by: list[Expr | SortExpr] | Expr | SortExpr | None = None,
434440
window_frame: WindowFrame | None = None,
441+
filter: Expr | None = None,
442+
distinct: bool = False,
435443
ctx: SessionContext | None = None,
436444
) -> Expr:
437445
"""Creates a new Window function expression.
@@ -447,7 +455,19 @@ def window(
447455
order_by_raw = sort_list_to_raw_sort_list(order_by)
448456
window_frame = window_frame.window_frame if window_frame is not None else None
449457
ctx = ctx.ctx if ctx is not None else None
450-
return Expr(f.window(name, args, partition_by_raw, order_by_raw, window_frame, ctx))
458+
filter_raw = filter.expr if filter is not None else None
459+
return Expr(
460+
f.window(
461+
name,
462+
args,
463+
partition_by=partition_by_raw,
464+
order_by=order_by_raw,
465+
window_frame=window_frame,
466+
ctx=ctx,
467+
filter=filter_raw,
468+
distinct=distinct,
469+
)
470+
)
451471

452472

453473
# scalar functions

0 commit comments

Comments
 (0)