df-script 1.5.0 → 1.7.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 +125 -9
- package/dist/api.d.ts +3 -2
- package/dist/assets/index-DBhGK6Tp.css +1 -0
- package/dist/assets/index-DEJEV_tU.js +195 -0
- package/dist/columnExpressions/ColumnExpr.d.ts +14 -7
- package/dist/columnExpressions/ExprBase.d.ts +26 -12
- package/dist/columnExpressions/constants.d.ts +1 -0
- package/dist/columnExpressions/functions/all.d.ts +23 -0
- package/dist/columnExpressions/functions/coalesce.d.ts +31 -2
- package/dist/columnExpressions/functions/element.d.ts +26 -1
- package/dist/columnExpressions/functions/exclude.d.ts +24 -0
- package/dist/columnExpressions/functions/implode.d.ts +28 -0
- package/dist/columnExpressions/functions/lit.d.ts +27 -0
- package/dist/columnExpressions/functions/seq_range.d.ts +36 -0
- package/dist/columnExpressions/functions/struct.d.ts +31 -0
- package/dist/columnExpressions/functions/when.d.ts +38 -8
- package/dist/columnExpressions/index.d.ts +2 -1
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +336 -2
- package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +620 -10
- package/dist/columnExpressions/mixins/ArrayExpr.d.ts +567 -0
- package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +353 -0
- package/dist/columnExpressions/mixins/LogicalExpr.d.ts +82 -0
- package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +40 -0
- package/dist/columnExpressions/mixins/StringExpr.d.ts +658 -5
- package/dist/columnExpressions/mixins/StructExpr.d.ts +70 -0
- package/dist/columnExpressions/mixins/TemporalExpr.d.ts +530 -4
- package/dist/columnExpressions/mixins/WindowExpr.d.ts +313 -2
- package/dist/columnExpressions/types.d.ts +2 -0
- package/dist/constants.d.ts +11 -0
- package/dist/dataframe/dataframe.d.ts +933 -3
- package/dist/dataframe/grouped/grouped.d.ts +41 -6
- package/dist/dataframe/types.d.ts +1 -0
- package/dist/dataframe/utils.d.ts +1 -0
- package/dist/datatypes/index.d.ts +3 -2
- package/dist/datatypes/types.d.ts +52 -7
- package/dist/exceptions/index.d.ts +23 -0
- package/dist/functions/concat.d.ts +50 -0
- package/dist/functions/read_csv.d.ts +9 -0
- package/dist/functions/read_json.d.ts +7 -2
- package/dist/index.html +17 -0
- package/dist/index.js +6 -6
- package/dist/index.mjs +6 -0
- package/dist/types.d.ts +51 -16
- package/dist/utils/{list.d.ts → array.d.ts} +68 -15
- package/dist/utils/binary.d.ts +3 -0
- package/dist/utils/csv.d.ts +1 -0
- package/dist/utils/date.d.ts +23 -54
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/json.d.ts +1 -0
- package/dist/utils/number.d.ts +15 -29
- package/dist/utils/object.d.ts +27 -0
- package/dist/utils/string.d.ts +15 -5
- package/package.json +18 -4
- package/dist/api.js +0 -26
- package/dist/bundle.min.js +0 -1
- package/dist/columnExpressions/ColumnExpr.js +0 -219
- package/dist/columnExpressions/ExprBase.js +0 -92
- package/dist/columnExpressions/constants.js +0 -7
- package/dist/columnExpressions/functions/all.js +0 -11
- package/dist/columnExpressions/functions/coalesce.js +0 -44
- package/dist/columnExpressions/functions/element.js +0 -11
- package/dist/columnExpressions/functions/exclude.js +0 -13
- package/dist/columnExpressions/functions/implode.js +0 -7
- package/dist/columnExpressions/functions/lit.js +0 -17
- package/dist/columnExpressions/functions/repeat.d.ts +0 -47
- package/dist/columnExpressions/functions/repeat.js +0 -131
- package/dist/columnExpressions/functions/seq_range.js +0 -91
- package/dist/columnExpressions/functions/when.js +0 -85
- package/dist/columnExpressions/index.js +0 -38
- package/dist/columnExpressions/mixins/AggregationExpr.js +0 -76
- package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -131
- package/dist/columnExpressions/mixins/BooleanExpr.d.ts +0 -40
- package/dist/columnExpressions/mixins/BooleanExpr.js +0 -67
- package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -250
- package/dist/columnExpressions/mixins/ListExpr.d.ts +0 -39
- package/dist/columnExpressions/mixins/ListExpr.js +0 -224
- package/dist/columnExpressions/mixins/LogicalExpr.js +0 -53
- package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -71
- package/dist/columnExpressions/mixins/NumericExpr.d.ts +0 -92
- package/dist/columnExpressions/mixins/NumericExpr.js +0 -259
- package/dist/columnExpressions/mixins/StringExpr.js +0 -237
- package/dist/columnExpressions/mixins/StructExpr.js +0 -139
- package/dist/columnExpressions/mixins/TemporalExpr.js +0 -126
- package/dist/columnExpressions/mixins/WindowExpr.js +0 -151
- package/dist/columnExpressions/types.js +0 -2
- package/dist/columnExpressions/utils.js +0 -45
- package/dist/dataframe/constants.js +0 -7
- package/dist/dataframe/dataframe.js +0 -990
- package/dist/dataframe/grouped/grouped.js +0 -114
- package/dist/dataframe/index.js +0 -20
- package/dist/dataframe/types.js +0 -2
- package/dist/dataframe/utils.js +0 -307
- package/dist/datatypes/DataType.js +0 -76
- package/dist/datatypes/index.js +0 -46
- package/dist/datatypes/types/Binary.d.ts +0 -9
- package/dist/datatypes/types/Binary.js +0 -18
- package/dist/datatypes/types/Boolean.d.ts +0 -9
- package/dist/datatypes/types/Boolean.js +0 -19
- package/dist/datatypes/types/Date.d.ts +0 -8
- package/dist/datatypes/types/Date.js +0 -21
- package/dist/datatypes/types/Datetime.d.ts +0 -8
- package/dist/datatypes/types/Datetime.js +0 -17
- package/dist/datatypes/types/Decimal.d.ts +0 -10
- package/dist/datatypes/types/Decimal.js +0 -28
- package/dist/datatypes/types/Duration.d.ts +0 -8
- package/dist/datatypes/types/Duration.js +0 -17
- package/dist/datatypes/types/Float32.d.ts +0 -8
- package/dist/datatypes/types/Float32.js +0 -17
- package/dist/datatypes/types/Float64.d.ts +0 -8
- package/dist/datatypes/types/Float64.js +0 -17
- package/dist/datatypes/types/Int16.d.ts +0 -8
- package/dist/datatypes/types/Int16.js +0 -17
- package/dist/datatypes/types/Int32.d.ts +0 -8
- package/dist/datatypes/types/Int32.js +0 -17
- package/dist/datatypes/types/Int64.d.ts +0 -8
- package/dist/datatypes/types/Int64.js +0 -17
- package/dist/datatypes/types/Int8.d.ts +0 -8
- package/dist/datatypes/types/Int8.js +0 -17
- package/dist/datatypes/types/List.d.ts +0 -10
- package/dist/datatypes/types/List.js +0 -31
- package/dist/datatypes/types/Null.d.ts +0 -9
- package/dist/datatypes/types/Null.js +0 -17
- package/dist/datatypes/types/Object.d.ts +0 -9
- package/dist/datatypes/types/Object.js +0 -17
- package/dist/datatypes/types/Struct.d.ts +0 -14
- package/dist/datatypes/types/Struct.js +0 -39
- package/dist/datatypes/types/Time.d.ts +0 -8
- package/dist/datatypes/types/Time.js +0 -29
- package/dist/datatypes/types/UInt16.d.ts +0 -8
- package/dist/datatypes/types/UInt16.js +0 -17
- package/dist/datatypes/types/UInt32.d.ts +0 -8
- package/dist/datatypes/types/UInt32.js +0 -17
- package/dist/datatypes/types/UInt64.d.ts +0 -8
- package/dist/datatypes/types/UInt64.js +0 -17
- package/dist/datatypes/types/UInt8.d.ts +0 -8
- package/dist/datatypes/types/UInt8.js +0 -17
- package/dist/datatypes/types/Utf8.d.ts +0 -10
- package/dist/datatypes/types/Utf8.js +0 -20
- package/dist/datatypes/types.js +0 -290
- package/dist/exceptions/index.js +0 -46
- package/dist/exceptions/utils.js +0 -28
- package/dist/functions/concat.js +0 -260
- package/dist/functions/index.js +0 -9
- package/dist/functions/read_csv.js +0 -53
- package/dist/functions/read_json.js +0 -21
- package/dist/functions/transpose.d.ts +0 -7
- package/dist/functions/transpose.js +0 -84
- package/dist/types.js +0 -2
- package/dist/utils/boolean.d.ts +0 -1
- package/dist/utils/boolean.js +0 -18
- package/dist/utils/csv.js +0 -313
- package/dist/utils/date.js +0 -348
- package/dist/utils/guards.d.ts +0 -12
- package/dist/utils/guards.js +0 -112
- package/dist/utils/index.js +0 -23
- package/dist/utils/json.js +0 -217
- package/dist/utils/list.js +0 -361
- package/dist/utils/number.js +0 -401
- package/dist/utils/string.js +0 -209
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExprBase = exports.derive = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
const exceptions_1 = require("../exceptions");
|
|
6
|
-
const derive = (instance, nextOp) => {
|
|
7
|
-
const Constructor = instance.constructor;
|
|
8
|
-
const colNameVal = instance.colNames || instance.colName || "";
|
|
9
|
-
const newInst = new Constructor(colNameVal);
|
|
10
|
-
Object.assign(newInst, instance);
|
|
11
|
-
newInst.ops = nextOp ? [...instance.ops, nextOp] : [...instance.ops];
|
|
12
|
-
return newInst;
|
|
13
|
-
};
|
|
14
|
-
exports.derive = derive;
|
|
15
|
-
class ExprBase {
|
|
16
|
-
ops = [];
|
|
17
|
-
outputName = "";
|
|
18
|
-
isLiteral;
|
|
19
|
-
literalValue;
|
|
20
|
-
aggFn = null;
|
|
21
|
-
groupingOpsIndex;
|
|
22
|
-
partitionOpsIndex;
|
|
23
|
-
partitionBy = null;
|
|
24
|
-
evaluateWindow;
|
|
25
|
-
_resolve(val, columns, height) {
|
|
26
|
-
if (val instanceof ExprBase) {
|
|
27
|
-
if (val.isLiteral && val.ops.length === 1) {
|
|
28
|
-
return val.literalValue;
|
|
29
|
-
}
|
|
30
|
-
return val.evaluate(columns, height);
|
|
31
|
-
}
|
|
32
|
-
return val;
|
|
33
|
-
}
|
|
34
|
-
alias(name) {
|
|
35
|
-
const newInst = (0, exports.derive)(this);
|
|
36
|
-
newInst.outputName = name;
|
|
37
|
-
return newInst;
|
|
38
|
-
}
|
|
39
|
-
cast(dataType) {
|
|
40
|
-
return (0, exports.derive)(this, (vArray) => {
|
|
41
|
-
const height = vArray.length;
|
|
42
|
-
const result = new Array(height);
|
|
43
|
-
for (let i = 0; i < height; i++) {
|
|
44
|
-
result[i] = dataType.coerce(vArray[i]);
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
debug(label) {
|
|
50
|
-
return (0, exports.derive)(this, (vArray) => {
|
|
51
|
-
console.log(`[DEBUG] ${label ? label + ': ' : ''}`, vArray);
|
|
52
|
-
return vArray;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
_getInitialValue(columns, height) {
|
|
56
|
-
const name = this.colName;
|
|
57
|
-
if (name && name !== constants_1.ALL_COLUMNS_MARKER && !name.startsWith("*") && !(name in columns)) {
|
|
58
|
-
throw new exceptions_1.ColumnNotFoundError(name);
|
|
59
|
-
}
|
|
60
|
-
return name && name !== constants_1.ALL_COLUMNS_MARKER
|
|
61
|
-
? (columns[name] || new Array(height).fill(null))
|
|
62
|
-
: new Array(height).fill(null);
|
|
63
|
-
}
|
|
64
|
-
evaluate(columns, height) {
|
|
65
|
-
let value = this._getInitialValue(columns, height);
|
|
66
|
-
const ops = this.ops;
|
|
67
|
-
const len = ops.length;
|
|
68
|
-
for (let i = 0; i < len; i++) {
|
|
69
|
-
value = ops[i](value, columns);
|
|
70
|
-
}
|
|
71
|
-
return value;
|
|
72
|
-
}
|
|
73
|
-
evaluatePre(opsIndex, columns, height) {
|
|
74
|
-
let value = this._getInitialValue(columns, height);
|
|
75
|
-
const ops = this.ops;
|
|
76
|
-
const idx = opsIndex !== undefined ? opsIndex : ops.length;
|
|
77
|
-
for (let i = 0; i < idx; i++) {
|
|
78
|
-
value = ops[i](value, columns);
|
|
79
|
-
}
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
evaluatePost(opsIndex, aggregatedArray, columns) {
|
|
83
|
-
const ops = this.ops;
|
|
84
|
-
const idx = opsIndex !== undefined ? opsIndex : ops.length;
|
|
85
|
-
let value = aggregatedArray;
|
|
86
|
-
for (let i = idx; i < ops.length; i++) {
|
|
87
|
-
value = ops[i](value, columns);
|
|
88
|
-
}
|
|
89
|
-
return value;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.ExprBase = ExprBase;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ELEMENT_MARKER = exports.COALESCE_MARKER = exports.LITERAL_MARKER = exports.ALL_COLUMNS_MARKER = void 0;
|
|
4
|
-
exports.ALL_COLUMNS_MARKER = "*";
|
|
5
|
-
exports.LITERAL_MARKER = "*literal*";
|
|
6
|
-
exports.COALESCE_MARKER = "*coalesce*";
|
|
7
|
-
exports.ELEMENT_MARKER = "*element*";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.all = all;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
/**
|
|
7
|
-
* Creates an expression targeting all columns in the DataFrame.
|
|
8
|
-
*/
|
|
9
|
-
function all() {
|
|
10
|
-
return new ColumnExpr_1.ColumnExpr(constants_1.ALL_COLUMNS_MARKER);
|
|
11
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.coalesce = coalesce;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
const constants_1 = require("../constants");
|
|
7
|
-
function coalesce(...exprs) {
|
|
8
|
-
const rawArgs = (exprs.length === 1 && Array.isArray(exprs[0]))
|
|
9
|
-
? exprs[0]
|
|
10
|
-
: exprs;
|
|
11
|
-
const expr = new ColumnExpr_1.ColumnExpr(constants_1.COALESCE_MARKER);
|
|
12
|
-
expr.ops.push((_, columns) => {
|
|
13
|
-
const height = _.length;
|
|
14
|
-
const evaluateArg = (arg) => {
|
|
15
|
-
if (ColumnExpr_1.ColumnExpr.isColExpr(arg)) {
|
|
16
|
-
return arg.evaluate(columns, height);
|
|
17
|
-
}
|
|
18
|
-
if (typeof arg === "string") {
|
|
19
|
-
return columns[arg] || new Array(height).fill(null);
|
|
20
|
-
}
|
|
21
|
-
return arg;
|
|
22
|
-
};
|
|
23
|
-
const exprCount = rawArgs.length;
|
|
24
|
-
const evaluatedArrays = new Array(exprCount);
|
|
25
|
-
for (let j = 0; j < exprCount; j++) {
|
|
26
|
-
evaluatedArrays[j] = evaluateArg(rawArgs[j]);
|
|
27
|
-
}
|
|
28
|
-
const result = new Array(height);
|
|
29
|
-
for (let i = 0; i < height; i++) {
|
|
30
|
-
let foundVal = null;
|
|
31
|
-
for (let j = 0; j < exprCount; j++) {
|
|
32
|
-
const arr = evaluatedArrays[j];
|
|
33
|
-
const val = (0, utils_1.isArrayOrTypedArray)(arr) ? arr[i] : arr;
|
|
34
|
-
if (val != null) {
|
|
35
|
-
foundVal = val;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
result[i] = foundVal;
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
});
|
|
43
|
-
return expr;
|
|
44
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.element = element;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
/**
|
|
7
|
-
* Creates an expression referencing the current element(s) of a list during evaluation.
|
|
8
|
-
*/
|
|
9
|
-
function element() {
|
|
10
|
-
return new ColumnExpr_1.ColumnExpr(constants_1.ELEMENT_MARKER);
|
|
11
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exclude = exclude;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
/**
|
|
7
|
-
* Creates an expression targeting all columns except the specified ones.
|
|
8
|
-
*/
|
|
9
|
-
function exclude(columns) {
|
|
10
|
-
const expr = new ColumnExpr_1.ColumnExpr(constants_1.ALL_COLUMNS_MARKER);
|
|
11
|
-
expr.excludedCols = Array.isArray(columns) ? columns : [columns];
|
|
12
|
-
return expr;
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lit = lit;
|
|
4
|
-
const seq_range_1 = require("./seq_range");
|
|
5
|
-
/**
|
|
6
|
-
* Creates a literal column expression that repeats the given value for all rows.
|
|
7
|
-
*/
|
|
8
|
-
function lit(value, options) {
|
|
9
|
-
const expr = (0, seq_range_1.seq_range)(value, {
|
|
10
|
-
strict: true,
|
|
11
|
-
mode: "constant",
|
|
12
|
-
dtype: options?.dtype,
|
|
13
|
-
name: options?.name,
|
|
14
|
-
});
|
|
15
|
-
expr.isLiteral = true;
|
|
16
|
-
return expr;
|
|
17
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ColumnExpr } from "../ColumnExpr";
|
|
2
|
-
import type { RegisteredDataType } from "../../types";
|
|
3
|
-
export type RepeatOptions = {
|
|
4
|
-
n?: number;
|
|
5
|
-
dtype?: RegisteredDataType;
|
|
6
|
-
name?: string;
|
|
7
|
-
} & ({
|
|
8
|
-
mode?: "constant";
|
|
9
|
-
} | {
|
|
10
|
-
mode: "cumulative" | "independent";
|
|
11
|
-
step?: number | ((prevOrIndex: any, index: number) => any);
|
|
12
|
-
}) & ({
|
|
13
|
-
strict?: true;
|
|
14
|
-
} | {
|
|
15
|
-
strict: false;
|
|
16
|
-
pad?: boolean;
|
|
17
|
-
truncate?: boolean;
|
|
18
|
-
padValue?: any;
|
|
19
|
-
startIndex?: number;
|
|
20
|
-
endIndex?: number;
|
|
21
|
-
});
|
|
22
|
-
export type SeqRangeOptions = {
|
|
23
|
-
n?: number;
|
|
24
|
-
dtype?: RegisteredDataType;
|
|
25
|
-
name?: string;
|
|
26
|
-
step?: number | ((prevOrIndex: any, index: number) => any);
|
|
27
|
-
mode?: "cumulative" | "independent";
|
|
28
|
-
} & ({
|
|
29
|
-
strict?: true;
|
|
30
|
-
} | {
|
|
31
|
-
strict: false;
|
|
32
|
-
pad?: boolean;
|
|
33
|
-
truncate?: boolean;
|
|
34
|
-
padValue?: any;
|
|
35
|
-
startIndex?: number;
|
|
36
|
-
endIndex?: number;
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Creates a literal column expression that repeats the given value.
|
|
40
|
-
* If n is specified, it repeats the value n times.
|
|
41
|
-
* If strict is true (default), a height mismatch with the DataFrame will throw a ShapeError.
|
|
42
|
-
*/
|
|
43
|
-
export declare function repeat(value: any, options?: RepeatOptions): ColumnExpr<any>;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a column expression that generates a sequence of values starting from the given start value.
|
|
46
|
-
*/
|
|
47
|
-
export declare function seq_range(start: any, options?: SeqRangeOptions): ColumnExpr<any>;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.repeat = repeat;
|
|
4
|
-
exports.seq_range = seq_range;
|
|
5
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
6
|
-
const constants_1 = require("../constants");
|
|
7
|
-
const exceptions_1 = require("../../exceptions");
|
|
8
|
-
const utils_1 = require("../../utils");
|
|
9
|
-
/**
|
|
10
|
-
* Creates a literal column expression that repeats the given value.
|
|
11
|
-
* If n is specified, it repeats the value n times.
|
|
12
|
-
* If strict is true (default), a height mismatch with the DataFrame will throw a ShapeError.
|
|
13
|
-
*/
|
|
14
|
-
function repeat(value, options = { strict: true }) {
|
|
15
|
-
const expr = new ColumnExpr_1.ColumnExpr(constants_1.LITERAL_MARKER);
|
|
16
|
-
expr.isLiteral = true;
|
|
17
|
-
expr.literalValue = value;
|
|
18
|
-
const opts = options;
|
|
19
|
-
if (opts.name) {
|
|
20
|
-
expr.outputName = opts.name;
|
|
21
|
-
}
|
|
22
|
-
expr.ops.push((vArray) => {
|
|
23
|
-
const targetHeight = vArray.length;
|
|
24
|
-
let start = opts.startIndex !== undefined ? opts.startIndex : 0;
|
|
25
|
-
if (start < 0) {
|
|
26
|
-
start = targetHeight + start;
|
|
27
|
-
}
|
|
28
|
-
const safeStart = (0, utils_1.clamp)(start, 0, targetHeight);
|
|
29
|
-
let end = opts.endIndex !== undefined ? opts.endIndex : targetHeight;
|
|
30
|
-
if (end < 0) {
|
|
31
|
-
end = targetHeight + end;
|
|
32
|
-
}
|
|
33
|
-
const safeEnd = (0, utils_1.clamp)(end, 0, targetHeight);
|
|
34
|
-
const sliceWidth = Math.max(0, safeEnd - safeStart);
|
|
35
|
-
const specifiedHeight = opts.n !== undefined ? opts.n : sliceWidth;
|
|
36
|
-
const strict = opts.strict !== false;
|
|
37
|
-
if (strict) {
|
|
38
|
-
if (specifiedHeight !== targetHeight) {
|
|
39
|
-
throw new exceptions_1.ShapeError(`Column height mismatch: repeat length ${specifiedHeight} does not match DataFrame height ${targetHeight}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const pad = opts.pad ?? false;
|
|
44
|
-
const truncate = opts.truncate ?? false;
|
|
45
|
-
if (pad && !truncate) {
|
|
46
|
-
if (specifiedHeight > sliceWidth) {
|
|
47
|
-
throw new exceptions_1.ShapeError(`Cannot pad repeat output: specified length ${specifiedHeight} starting at index ${safeStart} exceeds slice width ${sliceWidth} (requires truncation).`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else if (truncate && !pad) {
|
|
51
|
-
if (specifiedHeight < sliceWidth) {
|
|
52
|
-
throw new exceptions_1.ShapeError(`Cannot truncate repeat output: specified length ${specifiedHeight} starting at index ${safeStart} is less than slice width ${sliceWidth} (requires padding).`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const finalHeight = targetHeight;
|
|
57
|
-
const result = new Array(finalHeight);
|
|
58
|
-
const repeatEnd = Math.min(safeStart + specifiedHeight, safeEnd);
|
|
59
|
-
const rawFill = opts.padValue !== undefined ? opts.padValue : null;
|
|
60
|
-
const coercedFill = opts.dtype ? opts.dtype.coerce(rawFill) : rawFill;
|
|
61
|
-
const hasDtype = !!opts.dtype;
|
|
62
|
-
const mode = opts.mode || "constant";
|
|
63
|
-
const step = opts.step !== undefined ? opts.step : 1;
|
|
64
|
-
// Fast-path optimization for simple constant lit/repeat operations
|
|
65
|
-
if (mode === "constant" && safeStart === 0 && repeatEnd === finalHeight && !opts.dtype) {
|
|
66
|
-
for (let i = 0; i < finalHeight; i++) {
|
|
67
|
-
result[i] = value;
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
const seqVals = new Array(specifiedHeight);
|
|
72
|
-
if (specifiedHeight > 0) {
|
|
73
|
-
if (mode === "constant") {
|
|
74
|
-
const finalVal = opts.dtype ? opts.dtype.coerce(value) : value;
|
|
75
|
-
for (let idx = 0; idx < specifiedHeight; idx++) {
|
|
76
|
-
seqVals[idx] = finalVal;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (mode === "independent") {
|
|
80
|
-
if (typeof step === "function") {
|
|
81
|
-
for (let idx = 0; idx < specifiedHeight; idx++) {
|
|
82
|
-
const val = step(idx, value);
|
|
83
|
-
seqVals[idx] = hasDtype ? opts.dtype.coerce(val) : val;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
for (let idx = 0; idx < specifiedHeight; idx++) {
|
|
88
|
-
const val = value + idx * step;
|
|
89
|
-
seqVals[idx] = hasDtype ? opts.dtype.coerce(val) : val;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// cumulative mode
|
|
95
|
-
let current = value;
|
|
96
|
-
seqVals[0] = hasDtype ? opts.dtype.coerce(current) : current;
|
|
97
|
-
if (typeof step === "function") {
|
|
98
|
-
for (let idx = 1; idx < specifiedHeight; idx++) {
|
|
99
|
-
current = step(current, idx);
|
|
100
|
-
seqVals[idx] = hasDtype ? opts.dtype.coerce(current) : current;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
for (let idx = 1; idx < specifiedHeight; idx++) {
|
|
105
|
-
current = current + step;
|
|
106
|
-
seqVals[idx] = hasDtype ? opts.dtype.coerce(current) : current;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
for (let i = 0; i < finalHeight; i++) {
|
|
112
|
-
if (i >= safeStart && i < repeatEnd) {
|
|
113
|
-
result[i] = seqVals[i - safeStart];
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
result[i] = coercedFill;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
});
|
|
121
|
-
return expr;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Creates a column expression that generates a sequence of values starting from the given start value.
|
|
125
|
-
*/
|
|
126
|
-
function seq_range(start, options = { strict: true }) {
|
|
127
|
-
return repeat(start, {
|
|
128
|
-
...options,
|
|
129
|
-
mode: options.mode || "cumulative"
|
|
130
|
-
});
|
|
131
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.seq_range = seq_range;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const exceptions_1 = require("../../exceptions");
|
|
7
|
-
const utils_1 = require("../../utils");
|
|
8
|
-
/**
|
|
9
|
-
* Creates a column expression that generates a range of values.
|
|
10
|
-
* If mode is "cumulative" (default) or "independent", it generates a sequence.
|
|
11
|
-
* If mode is "constant", it repeats the given value.
|
|
12
|
-
*/
|
|
13
|
-
function seq_range(value, options = { strict: true }) {
|
|
14
|
-
const opts = options;
|
|
15
|
-
const expr = new ColumnExpr_1.ColumnExpr(constants_1.LITERAL_MARKER);
|
|
16
|
-
expr.literalValue = value;
|
|
17
|
-
if (opts.name) {
|
|
18
|
-
expr.outputName = opts.name;
|
|
19
|
-
}
|
|
20
|
-
expr.ops.push((vArray) => {
|
|
21
|
-
const targetHeight = vArray.length;
|
|
22
|
-
const getIdx = (val, def) => {
|
|
23
|
-
if (val === undefined)
|
|
24
|
-
return def;
|
|
25
|
-
return (0, utils_1.clamp)(val < 0 ? targetHeight + val : val, { min: 0, max: targetHeight });
|
|
26
|
-
};
|
|
27
|
-
const safeStart = getIdx(opts.startIndex, 0);
|
|
28
|
-
const safeEnd = getIdx(opts.endIndex, targetHeight);
|
|
29
|
-
const sliceWidth = Math.max(0, safeEnd - safeStart);
|
|
30
|
-
const specifiedHeight = opts.n !== undefined ? opts.n : sliceWidth;
|
|
31
|
-
const strict = opts.strict !== false;
|
|
32
|
-
if (strict) {
|
|
33
|
-
if (specifiedHeight !== targetHeight) {
|
|
34
|
-
throw new exceptions_1.ShapeError(`Column height mismatch: seq_range length ${specifiedHeight} does not match DataFrame height ${targetHeight}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
const pad = opts.pad ?? false;
|
|
39
|
-
const truncate = opts.truncate ?? false;
|
|
40
|
-
if (pad && !truncate && specifiedHeight > sliceWidth) {
|
|
41
|
-
throw new exceptions_1.ShapeError(`Cannot pad seq_range output: specified length ${specifiedHeight} starting at index ${safeStart} exceeds slice width ${sliceWidth} (requires truncation).`);
|
|
42
|
-
}
|
|
43
|
-
if (truncate && !pad && specifiedHeight < sliceWidth) {
|
|
44
|
-
throw new exceptions_1.ShapeError(`Cannot truncate seq_range output: specified length ${specifiedHeight} starting at index ${safeStart} is less than slice width ${sliceWidth} (requires padding).`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const finalHeight = targetHeight;
|
|
48
|
-
const hasDtype = !!opts.dtype;
|
|
49
|
-
const mode = opts.mode || "cumulative";
|
|
50
|
-
const step = opts.step !== undefined ? opts.step : 1;
|
|
51
|
-
const coerceVal = hasDtype
|
|
52
|
-
? (val) => opts.dtype.coerce(val)
|
|
53
|
-
: (val) => val;
|
|
54
|
-
if (strict) {
|
|
55
|
-
const result = opts.dtype?.allocate
|
|
56
|
-
? opts.dtype.allocate(finalHeight)
|
|
57
|
-
: new Array(finalHeight);
|
|
58
|
-
(0, utils_1.fillSequence)(result, value, {
|
|
59
|
-
mode,
|
|
60
|
-
step,
|
|
61
|
-
coerce: coerceVal,
|
|
62
|
-
startIndex: 0,
|
|
63
|
-
endIndex: finalHeight
|
|
64
|
-
});
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
// Non-strict mode path:
|
|
68
|
-
const repeatEnd = Math.min(safeStart + specifiedHeight, safeEnd);
|
|
69
|
-
const rawFill = opts.padValue !== undefined ? opts.padValue : null;
|
|
70
|
-
const coercedFill = coerceVal(rawFill);
|
|
71
|
-
// Fast-path optimization for simple constant lit/repeat operations
|
|
72
|
-
if (mode === "constant" && safeStart === 0 && repeatEnd === finalHeight && !opts.dtype) {
|
|
73
|
-
const result = new Array(finalHeight);
|
|
74
|
-
for (let i = 0; i < finalHeight; i++) {
|
|
75
|
-
result[i] = value;
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
const result = new Array(finalHeight);
|
|
80
|
-
result.fill(coercedFill);
|
|
81
|
-
(0, utils_1.fillSequence)(result, value, {
|
|
82
|
-
mode,
|
|
83
|
-
step,
|
|
84
|
-
coerce: coerceVal,
|
|
85
|
-
startIndex: safeStart,
|
|
86
|
-
endIndex: repeatEnd
|
|
87
|
-
});
|
|
88
|
-
return result;
|
|
89
|
-
});
|
|
90
|
-
return expr;
|
|
91
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WhenThen = exports.When = exports.WhenThenChain = void 0;
|
|
4
|
-
exports.when = when;
|
|
5
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
6
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
class WhenThenChain {
|
|
8
|
-
predicates;
|
|
9
|
-
values;
|
|
10
|
-
constructor(predicates, values) {
|
|
11
|
-
this.predicates = predicates;
|
|
12
|
-
this.values = values;
|
|
13
|
-
}
|
|
14
|
-
then(value) {
|
|
15
|
-
return new WhenThen(this.predicates, this.values.concat(value));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.WhenThenChain = WhenThenChain;
|
|
19
|
-
class When {
|
|
20
|
-
predicates;
|
|
21
|
-
constructor(predicate) {
|
|
22
|
-
this.predicates = [predicate];
|
|
23
|
-
}
|
|
24
|
-
then(value) {
|
|
25
|
-
return new WhenThen(this.predicates, [value]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.When = When;
|
|
29
|
-
class WhenThen extends ColumnExpr_1.ColumnExpr {
|
|
30
|
-
predicates;
|
|
31
|
-
values;
|
|
32
|
-
otherwiseValue;
|
|
33
|
-
constructor(predicates, values, otherwiseValue = null) {
|
|
34
|
-
super(typeof predicates === "string" ? predicates : "*when*");
|
|
35
|
-
this.predicates = Array.isArray(predicates) ? predicates : [];
|
|
36
|
-
this.values = values || [];
|
|
37
|
-
this.otherwiseValue = otherwiseValue;
|
|
38
|
-
this.ops.push((_, columns) => {
|
|
39
|
-
const height = _.length;
|
|
40
|
-
const evaluateArg = (arg) => {
|
|
41
|
-
if (ColumnExpr_1.ColumnExpr.isColExpr(arg)) {
|
|
42
|
-
return arg.evaluate(columns, height);
|
|
43
|
-
}
|
|
44
|
-
if (typeof arg === "string" && (arg in columns)) {
|
|
45
|
-
return columns[arg];
|
|
46
|
-
}
|
|
47
|
-
return arg;
|
|
48
|
-
};
|
|
49
|
-
const numConditions = this.predicates.length;
|
|
50
|
-
const evaluatedPreds = new Array(numConditions);
|
|
51
|
-
const evaluatedVals = new Array(numConditions);
|
|
52
|
-
for (let j = 0; j < numConditions; j++) {
|
|
53
|
-
evaluatedPreds[j] = evaluateArg(this.predicates[j]);
|
|
54
|
-
evaluatedVals[j] = evaluateArg(this.values[j]);
|
|
55
|
-
}
|
|
56
|
-
const evaluatedOtherwise = evaluateArg(this.otherwiseValue);
|
|
57
|
-
const result = new Array(height);
|
|
58
|
-
for (let i = 0; i < height; i++) {
|
|
59
|
-
let matched = false;
|
|
60
|
-
for (let j = 0; j < numConditions; j++) {
|
|
61
|
-
const predVal = (0, utils_1.isArrayOrTypedArray)(evaluatedPreds[j]) ? evaluatedPreds[j][i] : evaluatedPreds[j];
|
|
62
|
-
if (predVal === true) {
|
|
63
|
-
result[i] = (0, utils_1.isArrayOrTypedArray)(evaluatedVals[j]) ? evaluatedVals[j][i] : evaluatedVals[j];
|
|
64
|
-
matched = true;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (!matched) {
|
|
69
|
-
result[i] = (0, utils_1.isArrayOrTypedArray)(evaluatedOtherwise) ? evaluatedOtherwise[i] : evaluatedOtherwise;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
when(predicate) {
|
|
76
|
-
return new WhenThenChain(this.predicates.concat(predicate), this.values);
|
|
77
|
-
}
|
|
78
|
-
otherwise(value) {
|
|
79
|
-
return new WhenThen(this.predicates, this.values, value);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.WhenThen = WhenThen;
|
|
83
|
-
function when(predicate) {
|
|
84
|
-
return new When(predicate);
|
|
85
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./constants"), exports);
|
|
18
|
-
__exportStar(require("./types"), exports);
|
|
19
|
-
__exportStar(require("./ExprBase"), exports);
|
|
20
|
-
__exportStar(require("./mixins/ArithmeticExpr"), exports);
|
|
21
|
-
__exportStar(require("./mixins/LogicalExpr"), exports);
|
|
22
|
-
__exportStar(require("./mixins/ComparisonExpr"), exports);
|
|
23
|
-
__exportStar(require("./mixins/StringExpr"), exports);
|
|
24
|
-
__exportStar(require("./mixins/AggregationExpr"), exports);
|
|
25
|
-
__exportStar(require("./mixins/WindowExpr"), exports);
|
|
26
|
-
__exportStar(require("./mixins/TemporalExpr"), exports);
|
|
27
|
-
__exportStar(require("./mixins/ListExpr"), exports);
|
|
28
|
-
__exportStar(require("./mixins/StructExpr"), exports);
|
|
29
|
-
__exportStar(require("./ColumnExpr"), exports);
|
|
30
|
-
__exportStar(require("./functions/lit"), exports);
|
|
31
|
-
__exportStar(require("./functions/all"), exports);
|
|
32
|
-
__exportStar(require("./functions/exclude"), exports);
|
|
33
|
-
__exportStar(require("./functions/coalesce"), exports);
|
|
34
|
-
__exportStar(require("./functions/when"), exports);
|
|
35
|
-
__exportStar(require("./functions/implode"), exports);
|
|
36
|
-
__exportStar(require("./functions/seq_range"), exports);
|
|
37
|
-
__exportStar(require("./functions/element"), exports);
|
|
38
|
-
__exportStar(require("./utils"), exports);
|