@@ -227,7 +227,7 @@ def _std(expr: ir.NumericColumn, ddof: int) -> ir.Value:
227227 return expr .std (how = "sample" )
228228 n_samples = expr .count ()
229229 std_pop = expr .std (how = "pop" )
230- ddof_lit = cast ( "ir.IntegerScalar" , ibis . literal ( ddof ) )
230+ ddof_lit = lit ( ddof )
231231 return std_pop * n_samples .sqrt () / (n_samples - ddof_lit ).sqrt ()
232232
233233 return self ._with_callable (lambda expr : _std (expr , ddof ))
@@ -240,7 +240,7 @@ def _var(expr: ir.NumericColumn, ddof: int) -> ir.Value:
240240 return expr .var (how = "sample" )
241241 n_samples = expr .count ()
242242 var_pop = expr .var (how = "pop" )
243- ddof_lit = cast ( "ir.IntegerScalar" , ibis . literal ( ddof ) )
243+ ddof_lit = lit ( ddof )
244244 return var_pop * n_samples / (n_samples - ddof_lit )
245245
246246 return self ._with_callable (lambda expr : _var (expr , ddof ))
@@ -290,35 +290,33 @@ def is_unique(self) -> Self:
290290 )
291291
292292 def rank (self , method : RankMethod , * , descending : bool ) -> Self :
293- def _rank (expr : ir .Column ) -> ir .Column :
293+ def _rank (expr : ir .Column ) -> ir .Value :
294294 order_by = next (self ._sort (expr , descending = [descending ], nulls_last = [True ]))
295295 window = ibis .window (order_by = order_by )
296296
297297 if method == "dense" :
298298 rank_ = order_by .dense_rank ()
299299 elif method == "ordinal" :
300- rank_ = cast ( "ir.IntegerColumn" , ibis .row_number ().over (window ) )
300+ rank_ = ibis .row_number ().over (window )
301301 else :
302302 rank_ = order_by .rank ()
303303
304304 # Ibis uses 0-based ranking. Add 1 to match polars 1-based rank.
305- rank_ = rank_ + cast ( "ir.IntegerValue" , lit (1 ) )
305+ rank_ = rank_ + lit (1 )
306306
307307 # For "max" and "average", adjust using the count of rows in the partition.
308308 if method == "max" :
309309 # Define a window partitioned by expr (i.e. each distinct value)
310310 partition = ibis .window (group_by = [expr ])
311- cnt = cast ( "ir.IntegerValue" , expr .count ().over (partition ) )
312- rank_ = rank_ + cnt - cast ( "ir.IntegerValue" , lit (1 ) )
311+ cnt = expr .count ().over (partition )
312+ rank_ = rank_ + cnt - lit (1 )
313313 elif method == "average" :
314314 partition = ibis .window (group_by = [expr ])
315- cnt = cast ("ir.IntegerValue" , expr .count ().over (partition ))
316- avg = cast (
317- "ir.NumericValue" , (cnt - cast ("ir.IntegerScalar" , lit (1 ))) / lit (2.0 )
318- )
315+ cnt = expr .count ().over (partition )
316+ avg = cast ("ir.NumericValue" , (cnt - lit (1 )) / lit (2.0 ))
319317 rank_ = rank_ + avg
320318
321- return cast ( "ir.Column" , ibis .cases ((expr .notnull (), rank_ ) ))
319+ return ibis .cases ((expr .notnull (), rank_ ))
322320
323321 return self ._with_callable (_rank )
324322
0 commit comments