@@ -208,6 +208,11 @@ export function intRange(
208
208
if ( typeof opts ?. low === "number" ) {
209
209
return intRange ( opts . low , opts . high , opts . step , opts . dtype , opts . eager ) ;
210
210
}
211
+ // if expression like pl.len() passed
212
+ if ( high === undefined || high === null ) {
213
+ high = opts ;
214
+ opts = 0 ;
215
+ }
211
216
const low = exprToLitOrExpr ( opts , false ) ;
212
217
high = exprToLitOrExpr ( high , false ) ;
213
218
if ( eager ) {
@@ -472,7 +477,51 @@ export function head(column: Series | ExprOrString, n?): Series | Expr {
472
477
}
473
478
return exprToLitOrExpr ( column , false ) . head ( n ) ;
474
479
}
475
-
480
+ /** Return the number of elements in the column.
481
+ This is similar to `COUNT(*)` in SQL.
482
+
483
+ @return Expr - Expression of data type :class:`UInt32`.
484
+ @example
485
+ ```
486
+ >>> const df = pl.DataFrame(
487
+ ... {
488
+ ... "a": [1, 2, None],
489
+ ... "b": [3, None, None],
490
+ ... "c": ["foo", "bar", "foo"],
491
+ ... }
492
+ ... )
493
+ >>> df.select(pl.len())
494
+ shape: (1, 1)
495
+ ┌─────┐
496
+ │ len │
497
+ │ --- │
498
+ │ u32 │
499
+ ╞═════╡
500
+ │ 3 │
501
+ └─────┘
502
+ ```
503
+ Generate an index column by using `len` in conjunction with :func:`intRange`.
504
+
505
+ ```
506
+ >>> df.select(
507
+ ... pl.intRange(pl.len(), dtype=pl.UInt32).alias("index"),
508
+ ... pl.all(),
509
+ ... )
510
+ shape: (3, 4)
511
+ ┌───────┬──────┬──────┬─────┐
512
+ │ index ┆ a ┆ b ┆ c │
513
+ │ --- ┆ --- ┆ --- ┆ --- │
514
+ │ u32 ┆ i64 ┆ i64 ┆ str │
515
+ ╞═══════╪══════╪══════╪═════╡
516
+ │ 0 ┆ 1 ┆ 3 ┆ foo │
517
+ │ 1 ┆ 2 ┆ null ┆ bar │
518
+ │ 2 ┆ null ┆ null ┆ foo │
519
+ └───────┴──────┴──────┴─────┘
520
+ ```
521
+ */
522
+ export function len ( ) : any {
523
+ return _Expr ( pli . len ( ) ) ;
524
+ }
476
525
/** Get the last value. */
477
526
export function last ( column : ExprOrString | Series ) : any {
478
527
if ( Series . isSeries ( column ) ) {
0 commit comments