@@ -103,9 +103,9 @@ def __narwhals_namespace__(self) -> DuckDBNamespace: # pragma: no cover
103103
104104 def _cum_window_func (
105105 self ,
106+ func_name : Literal ["sum" , "max" , "min" , "count" , "product" ],
106107 * ,
107108 reverse : bool ,
108- func_name : Literal ["sum" , "max" , "min" , "count" , "product" ],
109109 ) -> DuckDBWindowFunction :
110110 def func (df : DuckDBLazyFrame , inputs : DuckDBWindowInputs ) -> list [Expression ]:
111111 return [
@@ -125,12 +125,12 @@ def func(df: DuckDBLazyFrame, inputs: DuckDBWindowInputs) -> list[Expression]:
125125
126126 def _rolling_window_func (
127127 self ,
128- * ,
129128 func_name : Literal ["sum" , "mean" , "std" , "var" ],
130- center : bool ,
131129 window_size : int ,
132130 min_samples : int ,
133131 ddof : int | None = None ,
132+ * ,
133+ center : bool ,
134134 ) -> DuckDBWindowFunction :
135135 supported_funcs = ["sum" , "mean" , "std" , "var" ]
136136 if center :
@@ -640,54 +640,36 @@ def func(df: DuckDBLazyFrame, inputs: DuckDBWindowInputs) -> list[Expression]:
640640
641641 @requires .backend_version ((1 , 3 ))
642642 def cum_sum (self , * , reverse : bool ) -> Self :
643- return self ._with_window_function (
644- self ._cum_window_func (reverse = reverse , func_name = "sum" )
645- )
643+ return self ._with_window_function (self ._cum_window_func ("sum" , reverse = reverse ))
646644
647645 @requires .backend_version ((1 , 3 ))
648646 def cum_max (self , * , reverse : bool ) -> Self :
649- return self ._with_window_function (
650- self ._cum_window_func (reverse = reverse , func_name = "max" )
651- )
647+ return self ._with_window_function (self ._cum_window_func ("max" , reverse = reverse ))
652648
653649 @requires .backend_version ((1 , 3 ))
654650 def cum_min (self , * , reverse : bool ) -> Self :
655- return self ._with_window_function (
656- self ._cum_window_func (reverse = reverse , func_name = "min" )
657- )
651+ return self ._with_window_function (self ._cum_window_func ("min" , reverse = reverse ))
658652
659653 @requires .backend_version ((1 , 3 ))
660654 def cum_count (self , * , reverse : bool ) -> Self :
661- return self ._with_window_function (
662- self ._cum_window_func (reverse = reverse , func_name = "count" )
663- )
655+ return self ._with_window_function (self ._cum_window_func ("count" , reverse = reverse ))
664656
665657 @requires .backend_version ((1 , 3 ))
666658 def cum_prod (self , * , reverse : bool ) -> Self :
667659 return self ._with_window_function (
668- self ._cum_window_func (reverse = reverse , func_name = "product" )
660+ self ._cum_window_func ("product" , reverse = reverse )
669661 )
670662
671663 @requires .backend_version ((1 , 3 ))
672664 def rolling_sum (self , window_size : int , * , min_samples : int , center : bool ) -> Self :
673665 return self ._with_window_function (
674- self ._rolling_window_func (
675- func_name = "sum" ,
676- center = center ,
677- window_size = window_size ,
678- min_samples = min_samples ,
679- )
666+ self ._rolling_window_func ("sum" , window_size , min_samples , center = center )
680667 )
681668
682669 @requires .backend_version ((1 , 3 ))
683670 def rolling_mean (self , window_size : int , * , min_samples : int , center : bool ) -> Self :
684671 return self ._with_window_function (
685- self ._rolling_window_func (
686- func_name = "mean" ,
687- center = center ,
688- window_size = window_size ,
689- min_samples = min_samples ,
690- )
672+ self ._rolling_window_func ("mean" , window_size , min_samples , center = center )
691673 )
692674
693675 @requires .backend_version ((1 , 3 ))
@@ -696,11 +678,7 @@ def rolling_var(
696678 ) -> Self :
697679 return self ._with_window_function (
698680 self ._rolling_window_func (
699- func_name = "var" ,
700- center = center ,
701- window_size = window_size ,
702- min_samples = min_samples ,
703- ddof = ddof ,
681+ "var" , window_size , min_samples , ddof = ddof , center = center
704682 )
705683 )
706684
@@ -710,11 +688,7 @@ def rolling_std(
710688 ) -> Self :
711689 return self ._with_window_function (
712690 self ._rolling_window_func (
713- func_name = "std" ,
714- center = center ,
715- window_size = window_size ,
716- min_samples = min_samples ,
717- ddof = ddof ,
691+ "std" , window_size , min_samples , ddof = ddof , center = center
718692 )
719693 )
720694
0 commit comments