Skip to content

Commit 03f5b5a

Browse files
authored
Improving ListNamespace docs (#352)
Improving ListNamespace docs Co-authored-by: Bidek56 <[email protected]>
1 parent 3829494 commit 03f5b5a

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

polars/lazy/expr/list.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { concatList } from "../functions";
88
* List functions for Lazy dataframes
99
*/
1010
export interface ExprList extends ListFunctions<Expr> {}
11-
// export interface ListNamespace extends ListFunctions<Expr> {}
1211

1312
export const ExprListFunctions = (_expr: any): ExprList => {
1413
const wrap = (method, ...args: any[]): Expr => {
@@ -43,17 +42,21 @@ export const ExprListFunctions = (_expr: any): ExprList => {
4342

4443
return concatList(otherList);
4544
},
46-
contains(item) {
47-
return wrap("listContains", exprToLitOrExpr(item)._expr, false);
45+
contains(item, nullsEqual?: boolean) {
46+
return wrap(
47+
"listContains",
48+
exprToLitOrExpr(item)._expr,
49+
nullsEqual ?? true,
50+
);
4851
},
4952
diff(n = 1, nullBehavior = "ignore") {
5053
return wrap("listDiff", n, nullBehavior);
5154
},
52-
get(index: number | Expr) {
55+
get(index: number | Expr, nullOnOob?: boolean) {
5356
if (Expr.isExpr(index)) {
54-
return wrap("listGet", index._expr, true);
57+
return wrap("listGet", index._expr, nullOnOob ?? true);
5558
}
56-
return wrap("listGet", pli.lit(index), true);
59+
return wrap("listGet", pli.lit(index), nullOnOob ?? true);
5760
},
5861
head(n = 5) {
5962
return this.slice(0, n);

polars/series/list.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { col } from "../lazy/functions";
22
import type { ListFunctions } from "../shared_traits";
33
import { _Series, type Series } from ".";
44

5-
// export type ListNamespace = ListFunctions<Series>;
6-
75
/**
86
* List functions for Series
97
*/

polars/shared_traits.ts

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,37 @@ export interface Bincode<T> {
511511
* Functions that can be applied to dtype List
512512
*/
513513
export interface ListFunctions<T> {
514+
/**
515+
* Retrieve the index of the minimal value in every sublist.
516+
* @returns Expression of data type :class:`UInt32` or :class:`UInt64`
517+
* @example
518+
* --------
519+
* ```
520+
* const s0 = pl.Series("a", [[1, 2], [2, 1]]);
521+
* s0.lst.argMax();
522+
* Series: 'a' [u32]
523+
* [
524+
* 0
525+
* 1
526+
* ]
527+
* ```
528+
*/
514529
argMin(): T;
530+
/**
531+
* Retrieve the index of the maximum value in every sublist.
532+
* @returns Expression of data type :class:`UInt32` or :class:`UInt64`
533+
* @example
534+
* --------
535+
* ```
536+
* const s0 = pl.Series("a", [[1, 2], [2, 1]]);
537+
* s0.lst.argMax();
538+
* Series: 'a' [u32]
539+
* [
540+
* 1
541+
* 0
542+
* ]
543+
* ```
544+
*/
515545
argMax(): T;
516546
/**
517547
* Concat the arrays in a Series dtype List in linear time.
@@ -541,6 +571,7 @@ export interface ListFunctions<T> {
541571
/**
542572
* Check if sublists contain the given item.
543573
* @param item Item that will be checked for membership
574+
* @param nullBehavior - bool, default True If True, treat null as a distinct value. Null values will not propagate.
544575
* @example
545576
* --------
546577
* ```
@@ -561,7 +592,7 @@ export interface ListFunctions<T> {
561592
* ```
562593
* @category List
563594
*/
564-
contains(item: any): T;
595+
contains(item: any, nullBehavior?: boolean): T;
565596
/**
566597
* Calculate the n-th discrete difference of every sublist.
567598
* @param n number of slots to shift
@@ -582,22 +613,30 @@ export interface ListFunctions<T> {
582613
diff(n?: number, nullBehavior?: "ignore" | "drop"): T;
583614
/**
584615
* Get the value by index in the sublists.
585-
* So index `0` would return the first item of every sublist
586-
* and index `-1` would return the last item of every sublist
587-
* if an index is out of bounds, it will return a `null`.
616+
* @param index - Index to return per sublist
617+
* @param nullOnOob - Behavior if an index is out of bounds:
618+
* True -> set as null
619+
* False -> raise an error
620+
* @example
621+
* -------
622+
* ```
623+
* const s0 = pl.Series("a", [[1, 2], [2, 1]]);
624+
* s0.lst.get(0);
625+
* Series: 'a' [f64]
626+
[
627+
1.0
628+
2.0
629+
]
630+
* ```
588631
* @category List
589632
*/
590-
get(index: number | Expr): T;
633+
get(index: number | Expr, nullOnOob?: boolean): T;
591634
/**
592635
* Run any polars expression against the lists' elements
593636
* Parameters
594637
* ----------
595638
* @param expr
596639
* Expression to run. Note that you can select an element with `pl.first()`, or `pl.col()`
597-
* @param parallel
598-
* Run all expression parallel. Don't activate this blindly.
599-
* Parallelism is worth it if there is enough work to do per thread.
600-
* This likely should not be use in the groupby context, because we already parallel execution per group
601640
* @example
602641
* >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
603642
* >df.withColumn(
@@ -617,7 +656,7 @@ export interface ListFunctions<T> {
617656
* └─────┴─────┴────────────┘
618657
* @category List
619658
*/
620-
eval(expr: Expr, parallel?: boolean): T;
659+
eval(expr: Expr): T;
621660
/**
622661
* Get the first value of the sublists.
623662
* @category List
@@ -797,7 +836,7 @@ export interface DateFunctions<T> {
797836
*/
798837
second(): T;
799838
/**
800-
* Format Date/datetime with a formatting rule: See [chrono strftime/strptime](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html).
839+
* Format Date/datetime with a formatting rule: See [chrono strftime/strptime](https://docs.rs/chrono/0.4.41/chrono/format/strftime/index.html).
801840
*/
802841
strftime(fmt: string): T;
803842
/** Return timestamp in ms as Int64 type. */

0 commit comments

Comments
 (0)