@@ -118,6 +118,8 @@ def __init__(
118118 req = plc .aggregation .mean ()
119119 elif name == "sum" :
120120 req = plc .aggregation .sum ()
121+ elif name == "product" :
122+ req = plc .aggregation .product ()
121123 elif name == "std" :
122124 # TODO: handle nans
123125 req = plc .aggregation .std (ddof = options )
@@ -172,7 +174,7 @@ def __init__(
172174 op = partial (op , propagate_nans = options )
173175 elif name == "count" :
174176 op = partial (op , include_nulls = options )
175- elif name in {"sum" , "first" , "last" , "item" , "first_non_null" }:
177+ elif name in {"sum" , "product" , " first" , "last" , "item" , "first_non_null" }:
176178 pass
177179 else :
178180 raise NotImplementedError (
@@ -194,6 +196,7 @@ def __init__(
194196 "m2" ,
195197 "merge_m2" ,
196198 "sum" ,
199+ "product" ,
197200 "count" ,
198201 "std" ,
199202 "var" ,
@@ -280,6 +283,20 @@ def _sum(self, column: Column, stream: Stream) -> Column:
280283 )
281284 return self ._reduce (column , request = plc .aggregation .sum (), stream = stream )
282285
286+ def _product (self , column : Column , stream : Stream ) -> Column :
287+ if column .size == 0 or column .null_count == column .size :
288+ # The product of an empty or all-null column is 1 in polars.
289+ return Column (
290+ plc .Column .from_scalar (
291+ plc .Scalar .from_py (1 , self .dtype .plc_type , stream = stream ),
292+ 1 ,
293+ stream = stream ,
294+ ),
295+ name = column .name ,
296+ dtype = self .dtype ,
297+ )
298+ return self ._reduce (column , request = plc .aggregation .product (), stream = stream )
299+
283300 def _min (self , column : Column , * , propagate_nans : bool , stream : Stream ) -> Column :
284301 nan_count = column .nan_count (stream = stream )
285302 if propagate_nans and nan_count > 0 :
0 commit comments