df-script 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -235
- package/dist/api.d.ts +41 -36
- package/dist/columnExpressions/ColumnExpr.d.ts +5 -8
- package/dist/columnExpressions/functions/all.d.ts +13 -13
- package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
- package/dist/columnExpressions/functions/duration.d.ts +16 -21
- package/dist/columnExpressions/functions/element.d.ts +10 -10
- package/dist/columnExpressions/functions/exclude.d.ts +14 -14
- package/dist/columnExpressions/functions/implode.d.ts +7 -7
- package/dist/columnExpressions/functions/lit.d.ts +9 -9
- package/dist/columnExpressions/functions/seqRange.d.ts +69 -0
- package/dist/columnExpressions/functions/struct.d.ts +6 -6
- package/dist/columnExpressions/functions/when.d.ts +25 -28
- package/dist/columnExpressions/index.d.ts +3 -7
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +550 -221
- package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +701 -327
- package/dist/columnExpressions/mixins/ArrayExpr.d.ts +508 -212
- package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +398 -201
- package/dist/columnExpressions/mixins/LogicalExpr.d.ts +59 -29
- package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +23 -9
- package/dist/columnExpressions/mixins/StandardExpr.d.ts +3234 -0
- package/dist/columnExpressions/mixins/StringExpr.d.ts +1163 -524
- package/dist/columnExpressions/mixins/StructExpr.d.ts +67 -25
- package/dist/columnExpressions/mixins/TemporalExpr.d.ts +518 -212
- package/dist/columnExpressions/mixins/WindowExpr.d.ts +270 -102
- package/dist/columnExpressions/typeInference.d.ts +3 -3
- package/dist/columnExpressions/types.d.ts +5 -0
- package/dist/columnExpressions/utils.d.ts +7 -0
- package/dist/constants.d.ts +11 -2
- package/dist/dataframe/dataframe.d.ts +755 -592
- package/dist/dataframe/grouped/grouped.d.ts +24 -6
- package/dist/dataframe/grouped.d.ts +70 -0
- package/dist/dataframe/index.d.ts +1 -1
- package/dist/dataframe/lazy.d.ts +37 -0
- package/dist/dataframe/types.d.ts +46 -22
- package/dist/dataframe/utils.d.ts +10 -4
- package/dist/datatypes/index.d.ts +11 -4
- package/dist/expressions.js +1 -0
- package/dist/expressions.mjs +1 -0
- package/dist/functions/concat.d.ts +68 -16
- package/dist/functions/index.d.ts +2 -2
- package/dist/functions/readCsv.d.ts +35 -0
- package/dist/functions/readJson.d.ts +33 -0
- package/dist/index.js +5 -6
- package/dist/index.mjs +5 -6
- package/dist/types.d.ts +42 -9
- package/dist/utils/array.d.ts +17 -14
- package/dist/utils/csv.d.ts +4 -1
- package/dist/utils/date.d.ts +3 -19
- package/dist/utils/duration.d.ts +7 -5
- package/dist/utils/json.d.ts +5 -3
- package/dist/utils/object.d.ts +0 -18
- package/dist/utils/string.d.ts +5 -0
- package/dist/utils.js +4 -0
- package/dist/utils.mjs +4 -0
- package/package.json +29 -8
- package/dist/assets/index-DBhGK6Tp.css +0 -1
- package/dist/assets/index-DEJEV_tU.js +0 -195
- package/dist/index.html +0 -17
package/dist/api.d.ts
CHANGED
|
@@ -1,49 +1,54 @@
|
|
|
1
1
|
import { DataFrame } from "./dataframe";
|
|
2
|
-
import { ColumnExpr, lit, all, exclude, coalesce, when, implode,
|
|
2
|
+
import { ColumnExpr, lit, all, exclude, coalesce, when, implode, seqRange, element, struct, duration } from "./columnExpressions";
|
|
3
3
|
import { DataType } from "./datatypes";
|
|
4
|
-
import { concat,
|
|
4
|
+
import { concat, readJson, readCsv } from "./functions";
|
|
5
5
|
import type { RowRecord, DataFrameSchema, ColumnDict, InferSchema } from "./types";
|
|
6
6
|
declare function data<S extends DataFrameSchema>(data: any[] | ColumnDict, schema: S): DataFrame<InferSchema<S>>;
|
|
7
7
|
declare function data<T extends RowRecord = any>(data: T[] | ColumnDict, schema?: DataFrameSchema): DataFrame<T>;
|
|
8
8
|
export declare const $df: {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Int8: import("./datatypes").Int8Type;
|
|
10
|
+
Int16: import("./datatypes").Int16Type;
|
|
11
|
+
Int32: import("./datatypes").Int32Type;
|
|
12
|
+
Int64: import("./datatypes").Int64Type;
|
|
13
|
+
UInt8: import("./datatypes").UInt8Type;
|
|
14
|
+
UInt16: import("./datatypes").UInt16Type;
|
|
15
|
+
UInt32: import("./datatypes").UInt32Type;
|
|
16
|
+
UInt64: import("./datatypes").UInt64Type;
|
|
17
|
+
Float32: import("./datatypes").Float32Type;
|
|
18
|
+
Float64: import("./datatypes").Float64Type;
|
|
19
|
+
Decimal: (precision?: number, scale?: number) => import("./datatypes").DecimalType;
|
|
20
|
+
Boolean: import("./datatypes").BooleanType;
|
|
21
|
+
Utf8: import("./datatypes").Utf8Type;
|
|
22
|
+
Binary: import("./datatypes").BinaryType;
|
|
23
|
+
Date: import("./datatypes").DateType;
|
|
24
|
+
Datetime: import("./datatypes").DatetimeType;
|
|
25
|
+
Time: import("./datatypes").TimeType;
|
|
26
|
+
Duration: import("./datatypes").DurationType;
|
|
27
|
+
Object: import("./datatypes").ObjectType;
|
|
28
|
+
Null: import("./datatypes").NullType;
|
|
29
|
+
Array: <TInner>(inner: import("./datatypes").RegisteredDataType & DataType<TInner>) => import("./datatypes").ArrayType<TInner>;
|
|
30
|
+
Struct: <TFields extends RowRecord>(fields: { [K in keyof TFields]: import("./datatypes").RegisteredDataType & DataType<TFields[K]>; }) => import("./datatypes").StructType<TFields>;
|
|
31
|
+
Numeric: typeof import("./datatypes").NumericDataType;
|
|
32
|
+
Integer: typeof import("./datatypes").IntegerDataType;
|
|
33
|
+
SignedInteger: typeof import("./datatypes").SignedIntegerType;
|
|
34
|
+
UnsignedInteger: typeof import("./datatypes").UnsignedIntegerType;
|
|
35
|
+
Float: typeof import("./datatypes").FloatDataType;
|
|
36
|
+
Temporal: typeof import("./datatypes").TemporalDataType;
|
|
37
|
+
Nested: typeof import("./datatypes").NestedDataType;
|
|
11
38
|
all: typeof all;
|
|
12
|
-
exclude: typeof exclude;
|
|
13
39
|
coalesce: typeof coalesce;
|
|
40
|
+
col: <T = any>(name: keyof T | string | (keyof T | string)[] | RegExp | RegExp[] | DataType | Function | (DataType | Function)[]) => ColumnExpr<T>;
|
|
14
41
|
concat: typeof concat;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
lit: typeof lit;
|
|
18
|
-
when: typeof when;
|
|
19
|
-
implode: typeof implode;
|
|
20
|
-
seq_range: typeof seq_range;
|
|
42
|
+
data: typeof data;
|
|
43
|
+
duration: typeof duration;
|
|
21
44
|
element: typeof element;
|
|
45
|
+
exclude: typeof exclude;
|
|
46
|
+
implode: typeof implode;
|
|
47
|
+
lit: typeof lit;
|
|
48
|
+
readCsv: typeof readCsv;
|
|
49
|
+
readJson: typeof readJson;
|
|
50
|
+
seqRange: typeof seqRange;
|
|
22
51
|
struct: typeof struct;
|
|
23
|
-
|
|
24
|
-
DataType: {
|
|
25
|
-
Int8: import("./datatypes").Int8Type;
|
|
26
|
-
Int16: import("./datatypes").Int16Type;
|
|
27
|
-
Int32: import("./datatypes").Int32Type;
|
|
28
|
-
Int64: import("./datatypes").Int64Type;
|
|
29
|
-
UInt8: import("./datatypes").UInt8Type;
|
|
30
|
-
UInt16: import("./datatypes").UInt16Type;
|
|
31
|
-
UInt32: import("./datatypes").UInt32Type;
|
|
32
|
-
UInt64: import("./datatypes").UInt64Type;
|
|
33
|
-
Float32: import("./datatypes").Float32Type;
|
|
34
|
-
Float64: import("./datatypes").Float64Type;
|
|
35
|
-
Decimal: (precision?: number, scale?: number) => import("./datatypes").DecimalType;
|
|
36
|
-
Boolean: import("./datatypes").BooleanType;
|
|
37
|
-
Utf8: import("./datatypes").Utf8Type;
|
|
38
|
-
Binary: import("./datatypes").BinaryType;
|
|
39
|
-
Date: import("./datatypes").DateType;
|
|
40
|
-
Datetime: import("./datatypes").DatetimeType;
|
|
41
|
-
Time: import("./datatypes").TimeType;
|
|
42
|
-
Duration: import("./datatypes").DurationType;
|
|
43
|
-
Object: import("./datatypes").ObjectType;
|
|
44
|
-
Null: import("./datatypes").NullType;
|
|
45
|
-
Array: <TInner>(inner: import("./datatypes").RegisteredDataType & DataType<TInner>) => import("./datatypes").ArrayType<TInner>;
|
|
46
|
-
Struct: <TFields extends RowRecord>(fields: { [K in keyof TFields]: import("./datatypes").RegisteredDataType & DataType<TFields[K]>; }) => import("./datatypes").StructType<TFields>;
|
|
47
|
-
};
|
|
52
|
+
when: typeof when;
|
|
48
53
|
};
|
|
49
54
|
export {};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { ExprBase } from "./ExprBase";
|
|
2
|
-
import {
|
|
3
|
-
import { ComparisonExpr } from "./mixins/ComparisonExpr";
|
|
4
|
-
import { AggregationExpr } from "./mixins/AggregationExpr";
|
|
5
|
-
import { WindowExpr } from "./mixins/WindowExpr";
|
|
2
|
+
import { StandardExpr } from "./mixins/StandardExpr";
|
|
6
3
|
import { StringExpr } from "./mixins/StringExpr";
|
|
7
|
-
import { LogicalExpr } from "./mixins/LogicalExpr";
|
|
8
4
|
import { TemporalExpr } from "./mixins/TemporalExpr";
|
|
9
5
|
import { ArrayExpr } from "./mixins/ArrayExpr";
|
|
10
6
|
import { StructExpr } from "./mixins/StructExpr";
|
|
11
|
-
import { ManipulationExpr } from "./mixins/ManipulationExpr";
|
|
12
7
|
import { DataType } from "../datatypes";
|
|
13
8
|
import type { IntoExpr, IExpr, DataFrameSchema, ColumnDict } from "../types";
|
|
14
9
|
export declare class ColumnExpr<T> extends ExprBase {
|
|
@@ -17,6 +12,8 @@ export declare class ColumnExpr<T> extends ExprBase {
|
|
|
17
12
|
_excludedCols: string[];
|
|
18
13
|
_targetType?: any;
|
|
19
14
|
_targetTypes?: any[];
|
|
15
|
+
_pattern?: RegExp;
|
|
16
|
+
_patterns?: RegExp[];
|
|
20
17
|
static isColExpr(v: unknown): v is ColumnExpr<any>;
|
|
21
18
|
static toColExpr(col: IntoExpr | IntoExpr[]): ColumnExpr<any>;
|
|
22
19
|
/**
|
|
@@ -25,9 +22,9 @@ export declare class ColumnExpr<T> extends ExprBase {
|
|
|
25
22
|
* @category ColumnExpression
|
|
26
23
|
* @syntax $df.col(<column_name>).{symbol}(...)
|
|
27
24
|
*/
|
|
28
|
-
constructor(colName: keyof T | string | (keyof T | string)[] | DataType | Function | (DataType | Function)[]);
|
|
25
|
+
constructor(colName: keyof T | string | (keyof T | string)[] | RegExp | RegExp[] | DataType | Function | (DataType | Function)[]);
|
|
29
26
|
}
|
|
30
|
-
export interface ColumnExpr<T> extends
|
|
27
|
+
export interface ColumnExpr<T> extends StandardExpr, StringExpr, TemporalExpr, ArrayExpr, StructExpr {
|
|
31
28
|
}
|
|
32
29
|
/**
|
|
33
30
|
* @internal
|
|
@@ -7,22 +7,22 @@ import { ColumnExpr } from "../ColumnExpr";
|
|
|
7
7
|
* @category ColumnExpression
|
|
8
8
|
* @syntax $df.{symbol}(...)
|
|
9
9
|
* @example
|
|
10
|
-
* >>> const df = $df.data({ a: [1, 2], b: [
|
|
10
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
11
11
|
* >>> df
|
|
12
12
|
* shape: (2, 2)
|
|
13
|
-
*
|
|
14
|
-
* │ a
|
|
15
|
-
*
|
|
16
|
-
* │ 1
|
|
17
|
-
* │ 2
|
|
18
|
-
*
|
|
13
|
+
* ┌───┬───┐
|
|
14
|
+
* │ a │ b │
|
|
15
|
+
* ├───┼───┤
|
|
16
|
+
* │ 1 │ x │
|
|
17
|
+
* │ 2 │ y │
|
|
18
|
+
* └───┴───┘
|
|
19
19
|
* >>> df.select($df.all())
|
|
20
20
|
* shape: (2, 2)
|
|
21
|
-
*
|
|
22
|
-
* │ a
|
|
23
|
-
*
|
|
24
|
-
* │ 1
|
|
25
|
-
* │ 2
|
|
26
|
-
*
|
|
21
|
+
* ┌───┬───┐
|
|
22
|
+
* │ a │ b │
|
|
23
|
+
* ├───┼───┤
|
|
24
|
+
* │ 1 │ x │
|
|
25
|
+
* │ 2 │ y │
|
|
26
|
+
* └───┴───┘
|
|
27
27
|
*/
|
|
28
28
|
export declare function all(): ColumnExpr<any>;
|
|
@@ -9,7 +9,7 @@ import type { IExpr, ValidScalarTypes } from "../../types";
|
|
|
9
9
|
* @category ColumnExpression
|
|
10
10
|
* @syntax $df.{symbol}(...)
|
|
11
11
|
* @example
|
|
12
|
-
* >>> const df = $df.data({ a: [1, null,
|
|
12
|
+
* >>> const df = $df.data({ a: [1, null, 3], b: [null, 2, null] })
|
|
13
13
|
* >>> df
|
|
14
14
|
* shape: (3, 2)
|
|
15
15
|
* ┌──────┬──────┐
|
|
@@ -17,7 +17,7 @@ import type { IExpr, ValidScalarTypes } from "../../types";
|
|
|
17
17
|
* ├──────┼──────┤
|
|
18
18
|
* │ 1 │ null │
|
|
19
19
|
* │ null │ 2 │
|
|
20
|
-
* │
|
|
20
|
+
* │ 3 │ null │
|
|
21
21
|
* └──────┴──────┘
|
|
22
22
|
* >>> df.select($df.coalesce($df.col("a"), $df.col("b"), $df.lit(3)).alias("coalesced"))
|
|
23
23
|
* shape: (3, 1)
|
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
import { ColumnExpr } from "../ColumnExpr";
|
|
2
|
-
import type {
|
|
3
|
-
export interface DurationOptions {
|
|
4
|
-
weeks?: IntoExpr | number;
|
|
5
|
-
days?: IntoExpr | number;
|
|
6
|
-
hours?: IntoExpr | number;
|
|
7
|
-
minutes?: IntoExpr | number;
|
|
8
|
-
seconds?: IntoExpr | number;
|
|
9
|
-
milliseconds?: IntoExpr | number;
|
|
10
|
-
microseconds?: IntoExpr | number;
|
|
11
|
-
nanoseconds?: IntoExpr | number;
|
|
12
|
-
timeUnit?: DatetimeTimeUnit;
|
|
13
|
-
}
|
|
2
|
+
import type { DurationOptions } from "../../types";
|
|
14
3
|
/**
|
|
15
|
-
* Constructs a Duration expression column from numeric values, column references, or expressions.
|
|
4
|
+
* Constructs a Duration expression column from numeric values, string intervals, column references, or expressions.
|
|
16
5
|
*
|
|
17
|
-
* @param {DurationOptions} [options] Duration component options
|
|
6
|
+
* @param {DurationOptions | string} [options] Duration component options or string interval (e.g. "1d 12h").
|
|
18
7
|
* @returns {ColumnExpr<any>} A column expression with the calculated duration values.
|
|
19
8
|
* @namespace $df
|
|
20
9
|
* @category ColumnExpression
|
|
21
10
|
* @syntax $df.duration(options)
|
|
22
11
|
* @example
|
|
23
|
-
* >>> const df = $df.data({
|
|
24
|
-
* >>> df
|
|
25
|
-
* shape: (
|
|
12
|
+
* >>> const df = $df.data({ date: ["2026-05-20T10:00:00.123Z"] })
|
|
13
|
+
* >>> df
|
|
14
|
+
* shape: (1, 1)
|
|
26
15
|
* ┌──────────────────────────┐
|
|
27
|
-
* │
|
|
16
|
+
* │ date │
|
|
28
17
|
* ├──────────────────────────┤
|
|
29
|
-
* │ 2026-
|
|
30
|
-
*
|
|
18
|
+
* │ 2026-05-20T10:00:00.123Z │
|
|
19
|
+
* └──────────────────────────┘
|
|
20
|
+
* >>> df.select($df.col("date").cast($df.Datetime).add($df.duration({ days: 1 })).alias("plus_1_day"))
|
|
21
|
+
* shape: (1, 1)
|
|
22
|
+
* ┌──────────────────────────┐
|
|
23
|
+
* │ plus_1_day │
|
|
24
|
+
* ├──────────────────────────┤
|
|
25
|
+
* │ 2026-05-21T10:00:00.123Z │
|
|
31
26
|
* └──────────────────────────┘
|
|
32
27
|
*/
|
|
33
|
-
export declare function duration(options?: DurationOptions): ColumnExpr<any>;
|
|
28
|
+
export declare function duration(options?: DurationOptions | string): ColumnExpr<any>;
|
|
@@ -9,22 +9,22 @@ import { ColumnExpr } from "../ColumnExpr";
|
|
|
9
9
|
* @category ColumnExpression
|
|
10
10
|
* @syntax $df.{symbol}(...)
|
|
11
11
|
* @example
|
|
12
|
-
* >>> const df = $df.data({ a: [[1,
|
|
12
|
+
* >>> const df = $df.data({ a: [[1, 2, 3], [4, 5]] })
|
|
13
13
|
* >>> df
|
|
14
14
|
* shape: (2, 1)
|
|
15
|
-
*
|
|
16
|
-
* │ a
|
|
17
|
-
*
|
|
18
|
-
* │ [1,
|
|
19
|
-
* │ [
|
|
20
|
-
*
|
|
21
|
-
* >>> df.select($df.col("a").arr.filter($df.element().gt(
|
|
15
|
+
* ┌───────────┐
|
|
16
|
+
* │ a │
|
|
17
|
+
* ├───────────┤
|
|
18
|
+
* │ [1, 2, 3] │
|
|
19
|
+
* │ [4, 5] │
|
|
20
|
+
* └───────────┘
|
|
21
|
+
* >>> df.select($df.col("a").arr.filter($df.element().gt(2)).alias("filtered"))
|
|
22
22
|
* shape: (2, 1)
|
|
23
23
|
* ┌──────────┐
|
|
24
24
|
* │ filtered │
|
|
25
25
|
* ├──────────┤
|
|
26
|
-
* │ [
|
|
27
|
-
* │ [
|
|
26
|
+
* │ [3] │
|
|
27
|
+
* │ [4, 5] │
|
|
28
28
|
* └──────────┘
|
|
29
29
|
*/
|
|
30
30
|
export declare function element<T = any>(): ColumnExpr<T>;
|
|
@@ -8,22 +8,22 @@ import { ColumnExpr } from "../ColumnExpr";
|
|
|
8
8
|
* @category ColumnExpression
|
|
9
9
|
* @syntax $df.{symbol}(...)
|
|
10
10
|
* @example
|
|
11
|
-
* >>> const df = $df.data({
|
|
11
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
12
12
|
* >>> df
|
|
13
13
|
* shape: (2, 2)
|
|
14
|
-
*
|
|
15
|
-
* │
|
|
16
|
-
*
|
|
17
|
-
* │
|
|
18
|
-
* │
|
|
19
|
-
*
|
|
20
|
-
* >>> df.select($df.exclude("
|
|
14
|
+
* ┌───┬───┐
|
|
15
|
+
* │ a │ b │
|
|
16
|
+
* ├───┼───┤
|
|
17
|
+
* │ 1 │ x │
|
|
18
|
+
* │ 2 │ y │
|
|
19
|
+
* └───┴───┘
|
|
20
|
+
* >>> df.select($df.exclude("a"))
|
|
21
21
|
* shape: (2, 1)
|
|
22
|
-
*
|
|
23
|
-
* │
|
|
24
|
-
*
|
|
25
|
-
* │
|
|
26
|
-
* │
|
|
27
|
-
*
|
|
22
|
+
* ┌───┐
|
|
23
|
+
* │ b │
|
|
24
|
+
* ├───┤
|
|
25
|
+
* │ x │
|
|
26
|
+
* │ y │
|
|
27
|
+
* └───┘
|
|
28
28
|
*/
|
|
29
29
|
export declare function exclude(columns: string | string[]): ColumnExpr<any>;
|
|
@@ -9,23 +9,23 @@ import type { IntoExpr } from "../../types";
|
|
|
9
9
|
* @category ColumnExpression
|
|
10
10
|
* @syntax $df.{symbol}(...)
|
|
11
11
|
* @example
|
|
12
|
-
* >>> const df = $df.data({ group: ["A", "A", "B"], val: [
|
|
12
|
+
* >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
|
|
13
13
|
* >>> df
|
|
14
14
|
* shape: (3, 2)
|
|
15
15
|
* ┌───────┬─────┐
|
|
16
16
|
* │ group │ val │
|
|
17
17
|
* ├───────┼─────┤
|
|
18
|
-
* │ A │
|
|
19
|
-
* │ A │
|
|
20
|
-
* │ B │
|
|
18
|
+
* │ A │ 10 │
|
|
19
|
+
* │ A │ 20 │
|
|
20
|
+
* │ B │ 30 │
|
|
21
21
|
* └───────┴─────┘
|
|
22
|
-
* >>> df.
|
|
22
|
+
* >>> df.groupBy("group").agg($df.implode("val").alias("imploded"))
|
|
23
23
|
* shape: (2, 2)
|
|
24
24
|
* ┌───────┬──────────┐
|
|
25
25
|
* │ group │ imploded │
|
|
26
26
|
* ├───────┼──────────┤
|
|
27
|
-
* │ A │ [
|
|
28
|
-
* │ B │ [
|
|
27
|
+
* │ A │ [10, 20] │
|
|
28
|
+
* │ B │ [30] │
|
|
29
29
|
* └───────┴──────────┘
|
|
30
30
|
*/
|
|
31
31
|
export declare function implode(column: IntoExpr | IntoExpr[]): ColumnExpr<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColumnExpr } from "../ColumnExpr";
|
|
2
|
-
import type { SeqRangeOptions } from "./
|
|
2
|
+
import type { SeqRangeOptions } from "./seqRange";
|
|
3
3
|
export type LitOptions = Pick<SeqRangeOptions, "dtype" | "name">;
|
|
4
4
|
/**
|
|
5
5
|
* Creates a literal column expression that repeats the given value for all rows.
|
|
@@ -13,15 +13,15 @@ export type LitOptions = Pick<SeqRangeOptions, "dtype" | "name">;
|
|
|
13
13
|
* @category ColumnExpression
|
|
14
14
|
* @syntax $df.{symbol}(...)
|
|
15
15
|
* @example
|
|
16
|
-
* >>> const df = $df.data({ a: [1, 2] })
|
|
16
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
17
17
|
* >>> df
|
|
18
|
-
* shape: (2,
|
|
19
|
-
*
|
|
20
|
-
* │ a │
|
|
21
|
-
*
|
|
22
|
-
* │ 1 │
|
|
23
|
-
* │ 2 │
|
|
24
|
-
*
|
|
18
|
+
* shape: (2, 2)
|
|
19
|
+
* ┌───┬───┐
|
|
20
|
+
* │ a │ b │
|
|
21
|
+
* ├───┼───┤
|
|
22
|
+
* │ 1 │ x │
|
|
23
|
+
* │ 2 │ y │
|
|
24
|
+
* └───┴───┘
|
|
25
25
|
* >>> df.select($df.lit(42).alias("answer"))
|
|
26
26
|
* shape: (2, 1)
|
|
27
27
|
* ┌────────┐
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ColumnExpr } from "../ColumnExpr";
|
|
2
|
+
import type { RegisteredDataType } from "../../types";
|
|
3
|
+
import { CumulativeStepContext, IndependentStepContext } from "../../utils";
|
|
4
|
+
export type SeqRangeOptions = {
|
|
5
|
+
n?: number;
|
|
6
|
+
dtype?: RegisteredDataType;
|
|
7
|
+
name?: string;
|
|
8
|
+
} & ({
|
|
9
|
+
mode: "constant";
|
|
10
|
+
} | {
|
|
11
|
+
mode?: "cumulative";
|
|
12
|
+
step?: number | ((context: CumulativeStepContext) => any);
|
|
13
|
+
} | {
|
|
14
|
+
mode: "independent";
|
|
15
|
+
step?: number | ((context: IndependentStepContext) => any);
|
|
16
|
+
}) & ({
|
|
17
|
+
strict?: true;
|
|
18
|
+
} | {
|
|
19
|
+
strict: false;
|
|
20
|
+
pad?: boolean;
|
|
21
|
+
truncate?: boolean;
|
|
22
|
+
padValue?: any;
|
|
23
|
+
startIndex?: number;
|
|
24
|
+
endIndex?: number;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Creates a column expression that generates a range of values.
|
|
28
|
+
* If mode is "cumulative" (default) or "independent", it generates a sequence.
|
|
29
|
+
* If mode is "constant", it repeats the given value.
|
|
30
|
+
*
|
|
31
|
+
* @param value The initial value to start the sequence or the constant value to repeat.
|
|
32
|
+
* @param [options] Configuration options.
|
|
33
|
+
* @param [options.n] The number of values to generate. Defaults to the slice/DataFrame height.
|
|
34
|
+
* @param [options.dtype] The registered data type to coerce/allocate for the generated sequence.
|
|
35
|
+
* @param [options.name] The name of the output column.
|
|
36
|
+
* @param [options.mode] The sequence generation mode ("constant", "cumulative", or "independent").
|
|
37
|
+
* @param [options.step] The step value or function to compute the step at each row.
|
|
38
|
+
* @param [options.strict] If true, throws an error if the generated sequence height does not match the target height.
|
|
39
|
+
* @param [options.pad] In non-strict mode, pads the sequence with `padValue` if it is shorter than target range.
|
|
40
|
+
* @param [options.truncate] In non-strict mode, truncates the sequence if it exceeds target range.
|
|
41
|
+
* @param [options.padValue] The value to use for padding in non-strict mode.
|
|
42
|
+
* @param [options.startIndex] The starting index in the DataFrame to insert the sequence.
|
|
43
|
+
* @param [options.endIndex] The ending index in the DataFrame to insert the sequence.
|
|
44
|
+
* @returns {ColumnExpr<any>} A column expression generating the sequence.
|
|
45
|
+
* @namespace $df
|
|
46
|
+
* @category ColumnExpression
|
|
47
|
+
* @syntax $df.{symbol}(...)
|
|
48
|
+
* @example
|
|
49
|
+
* >>> const df = $df.data({ a: [1, 2, 3] })
|
|
50
|
+
* >>> df
|
|
51
|
+
* shape: (3, 1)
|
|
52
|
+
* ┌───┐
|
|
53
|
+
* │ a │
|
|
54
|
+
* ├───┤
|
|
55
|
+
* │ 1 │
|
|
56
|
+
* │ 2 │
|
|
57
|
+
* │ 3 │
|
|
58
|
+
* └───┘
|
|
59
|
+
* >>> df.select($df.seqRange(1, { step: 2 }).alias("odd"))
|
|
60
|
+
* shape: (3, 1)
|
|
61
|
+
* ┌─────┐
|
|
62
|
+
* │ odd │
|
|
63
|
+
* ├─────┤
|
|
64
|
+
* │ 1 │
|
|
65
|
+
* │ 3 │
|
|
66
|
+
* │ 5 │
|
|
67
|
+
* └─────┘
|
|
68
|
+
*/
|
|
69
|
+
export declare function seqRange(value: any, options?: SeqRangeOptions): ColumnExpr<any>;
|
|
@@ -13,12 +13,12 @@ import type { IntoExpr } from "../../types";
|
|
|
13
13
|
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
14
14
|
* >>> df
|
|
15
15
|
* shape: (2, 2)
|
|
16
|
-
*
|
|
17
|
-
* │ a
|
|
18
|
-
*
|
|
19
|
-
* │ 1
|
|
20
|
-
* │ 2
|
|
21
|
-
*
|
|
16
|
+
* ┌───┬───┐
|
|
17
|
+
* │ a │ b │
|
|
18
|
+
* ├───┼───┤
|
|
19
|
+
* │ 1 │ x │
|
|
20
|
+
* │ 2 │ y │
|
|
21
|
+
* └───┴───┘
|
|
22
22
|
* >>> df.select($df.struct({ x: "a", y: "b" }).alias("coord"))
|
|
23
23
|
* shape: (2, 1)
|
|
24
24
|
* ┌──────────────────┐
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { ColumnExpr } from "../ColumnExpr";
|
|
2
2
|
import type { IExpr, ValidScalarTypes } from "../../types";
|
|
3
|
-
type WhenArg = IExpr | ValidScalarTypes | any[]
|
|
3
|
+
type WhenArg = IExpr | ValidScalarTypes | any[] | Record<string, any>;
|
|
4
4
|
export declare class WhenThenChain {
|
|
5
5
|
private _predicates;
|
|
6
6
|
private _values;
|
|
7
|
-
constructor(
|
|
8
|
-
then(value: WhenArg): WhenThen;
|
|
9
|
-
}
|
|
10
|
-
export declare class When {
|
|
11
|
-
private _predicates;
|
|
12
|
-
constructor(predicate: WhenArg);
|
|
7
|
+
constructor(_predicates: WhenArg[], _values?: WhenArg[]);
|
|
13
8
|
then(value: WhenArg): WhenThen;
|
|
14
9
|
}
|
|
10
|
+
export { WhenThenChain as When };
|
|
15
11
|
export declare class WhenThen extends ColumnExpr<any> {
|
|
16
12
|
_predicates: WhenArg[];
|
|
17
13
|
_values: WhenArg[];
|
|
18
14
|
_otherwise: WhenArg;
|
|
19
15
|
get _otherwiseValue(): WhenArg;
|
|
20
16
|
get _branchOperands(): WhenArg[];
|
|
21
|
-
constructor(
|
|
17
|
+
constructor(_predicates?: WhenArg[], _values?: WhenArg[], _otherwise?: WhenArg);
|
|
22
18
|
when(predicate: WhenArg): WhenThenChain;
|
|
23
19
|
otherwise(value: WhenArg): WhenThen;
|
|
24
20
|
}
|
|
@@ -26,31 +22,32 @@ export declare class WhenThen extends ColumnExpr<any> {
|
|
|
26
22
|
* Provides conditional branch evaluations inside column expressions.
|
|
27
23
|
*
|
|
28
24
|
* @param {WhenArg} predicate The boolean condition or expression.
|
|
29
|
-
* @returns {
|
|
25
|
+
* @returns {WhenThenChain} A When object builder to chain `.then()` and `.otherwise()`/`.when()`.
|
|
30
26
|
* @namespace $df
|
|
31
27
|
* @category ColumnExpression
|
|
32
28
|
* @syntax $df.{symbol}(...)
|
|
33
29
|
* @example
|
|
34
|
-
* >>> const df = $df.data({
|
|
30
|
+
* >>> const df = $df.data({ a: [1, 2, 3] })
|
|
35
31
|
* >>> df
|
|
36
|
-
* shape: (
|
|
37
|
-
*
|
|
38
|
-
* │
|
|
39
|
-
*
|
|
40
|
-
* │
|
|
41
|
-
* │
|
|
42
|
-
*
|
|
32
|
+
* shape: (3, 1)
|
|
33
|
+
* ┌───┐
|
|
34
|
+
* │ a │
|
|
35
|
+
* ├───┤
|
|
36
|
+
* │ 1 │
|
|
37
|
+
* │ 2 │
|
|
38
|
+
* │ 3 │
|
|
39
|
+
* └───┘
|
|
43
40
|
* >>> df.select(
|
|
44
|
-
* ... $df.when($df.col("
|
|
45
|
-
* ... .otherwise("
|
|
41
|
+
* ... $df.when($df.col("a").gt(2)).then("High")
|
|
42
|
+
* ... .otherwise("Low").alias("tier")
|
|
46
43
|
* ... )
|
|
47
|
-
* shape: (
|
|
48
|
-
*
|
|
49
|
-
* │
|
|
50
|
-
*
|
|
51
|
-
* │
|
|
52
|
-
* │
|
|
53
|
-
*
|
|
44
|
+
* shape: (3, 1)
|
|
45
|
+
* ┌──────┐
|
|
46
|
+
* │ tier │
|
|
47
|
+
* ├──────┤
|
|
48
|
+
* │ Low │
|
|
49
|
+
* │ Low │
|
|
50
|
+
* │ High │
|
|
51
|
+
* └──────┘
|
|
54
52
|
*/
|
|
55
|
-
export declare function when(predicate: WhenArg):
|
|
56
|
-
export {};
|
|
53
|
+
export declare function when(predicate: WhenArg): WhenThenChain;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
export * from "./constants";
|
|
2
2
|
export * from "./types";
|
|
3
3
|
export * from "./ExprBase";
|
|
4
|
-
export * from "./mixins/
|
|
5
|
-
export * from "./mixins/
|
|
6
|
-
export * from "./mixins/ComparisonExpr";
|
|
4
|
+
export * from "./mixins/StandardExpr";
|
|
5
|
+
export * from "./mixins/ArrayExpr";
|
|
7
6
|
export * from "./mixins/StringExpr";
|
|
8
|
-
export * from "./mixins/AggregationExpr";
|
|
9
|
-
export * from "./mixins/WindowExpr";
|
|
10
7
|
export * from "./mixins/TemporalExpr";
|
|
11
|
-
export * from "./mixins/ArrayExpr";
|
|
12
8
|
export * from "./mixins/StructExpr";
|
|
13
9
|
export * from "./ColumnExpr";
|
|
14
10
|
export * from "./functions/lit";
|
|
@@ -17,7 +13,7 @@ export * from "./functions/exclude";
|
|
|
17
13
|
export * from "./functions/coalesce";
|
|
18
14
|
export * from "./functions/when";
|
|
19
15
|
export * from "./functions/implode";
|
|
20
|
-
export * from "./functions/
|
|
16
|
+
export * from "./functions/seqRange";
|
|
21
17
|
export * from "./functions/element";
|
|
22
18
|
export * from "./functions/struct";
|
|
23
19
|
export * from "./functions/duration";
|