3232 WindowFrame ,
3333 expr_list_to_raw_expr_list ,
3434 sort_list_to_raw_sort_list ,
35+ sort_or_default ,
3536)
3637
38+ try :
39+ from warnings import deprecated # Python 3.13+
40+ except ImportError :
41+ from typing_extensions import deprecated # Python 3.12
42+
3743if TYPE_CHECKING :
3844 from datafusion .context import SessionContext
3945
@@ -426,12 +432,15 @@ def when(when: Expr, then: Expr) -> CaseBuilder:
426432 return CaseBuilder (f .when (when .expr , then .expr ))
427433
428434
435+ @deprecated ("Prefer to call Expr.over() instead" )
429436def window (
430437 name : str ,
431438 args : list [Expr ],
432439 partition_by : list [Expr ] | Expr | None = None ,
433440 order_by : list [SortKey ] | SortKey | None = None ,
434441 window_frame : WindowFrame | None = None ,
442+ filter : Expr | None = None ,
443+ distinct : bool = False ,
435444 ctx : SessionContext | None = None ,
436445) -> Expr :
437446 """Creates a new Window function expression.
@@ -451,7 +460,19 @@ def window(
451460 order_by_raw = sort_list_to_raw_sort_list (order_by )
452461 window_frame = window_frame .window_frame if window_frame is not None else None
453462 ctx = ctx .ctx if ctx is not None else None
454- return Expr (f .window (name , args , partition_by_raw , order_by_raw , window_frame , ctx ))
463+ filter_raw = filter .expr if filter is not None else None
464+ return Expr (
465+ f .window (
466+ name ,
467+ args ,
468+ partition_by = partition_by_raw ,
469+ order_by = order_by_raw ,
470+ window_frame = window_frame ,
471+ ctx = ctx ,
472+ filter = filter_raw ,
473+ distinct = distinct ,
474+ )
475+ )
455476
456477
457478# scalar functions
@@ -1664,7 +1685,7 @@ def approx_median(expression: Expr, filter: Optional[Expr] = None) -> Expr:
16641685
16651686
16661687def approx_percentile_cont (
1667- expression : Expr ,
1688+ sort_expression : Expr | SortExpr ,
16681689 percentile : float ,
16691690 num_centroids : Optional [int ] = None ,
16701691 filter : Optional [Expr ] = None ,
@@ -1685,21 +1706,26 @@ def approx_percentile_cont(
16851706 the options ``order_by``, ``null_treatment``, and ``distinct``.
16861707
16871708 Args:
1688- expression : Values for which to find the approximate percentile
1709+ sort_expression : Values for which to find the approximate percentile
16891710 percentile: This must be between 0.0 and 1.0, inclusive
16901711 num_centroids: Max bin size for the t-digest algorithm
16911712 filter: If provided, only compute against rows for which the filter is True
16921713 """
1714+ sort_expr_raw = sort_or_default (sort_expression )
16931715 filter_raw = filter .expr if filter is not None else None
16941716 return Expr (
16951717 f .approx_percentile_cont (
1696- expression . expr , percentile , num_centroids = num_centroids , filter = filter_raw
1718+ sort_expr_raw , percentile , num_centroids = num_centroids , filter = filter_raw
16971719 )
16981720 )
16991721
17001722
17011723def approx_percentile_cont_with_weight (
1702- expression : Expr , weight : Expr , percentile : float , filter : Optional [Expr ] = None
1724+ sort_expression : Expr | SortExpr ,
1725+ weight : Expr ,
1726+ percentile : float ,
1727+ num_centroids : Optional [int ] = None ,
1728+ filter : Optional [Expr ] = None ,
17031729) -> Expr :
17041730 """Returns the value of the weighted approximate percentile.
17051731
@@ -1710,16 +1736,22 @@ def approx_percentile_cont_with_weight(
17101736 the options ``order_by``, ``null_treatment``, and ``distinct``.
17111737
17121738 Args:
1713- expression : Values for which to find the approximate percentile
1739+ sort_expression : Values for which to find the approximate percentile
17141740 weight: Relative weight for each of the values in ``expression``
17151741 percentile: This must be between 0.0 and 1.0, inclusive
1742+ num_centroids: Max bin size for the t-digest algorithm
17161743 filter: If provided, only compute against rows for which the filter is True
17171744
17181745 """
1746+ sort_expr_raw = sort_or_default (sort_expression )
17191747 filter_raw = filter .expr if filter is not None else None
17201748 return Expr (
17211749 f .approx_percentile_cont_with_weight (
1722- expression .expr , weight .expr , percentile , filter = filter_raw
1750+ sort_expr_raw ,
1751+ weight .expr ,
1752+ percentile ,
1753+ num_centroids = num_centroids ,
1754+ filter = filter_raw ,
17231755 )
17241756 )
17251757
0 commit comments