df-script 1.4.0 → 1.6.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 +203 -38
- package/dist/api.d.ts +16 -8
- package/dist/columnExpressions/ColumnExpr.d.ts +26 -364
- package/dist/columnExpressions/ExprBase.d.ts +8 -11
- package/dist/columnExpressions/constants.d.ts +2 -0
- package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
- package/dist/columnExpressions/functions/element.d.ts +5 -0
- package/dist/columnExpressions/functions/implode.d.ts +3 -0
- package/dist/columnExpressions/functions/lit.d.ts +3 -1
- package/dist/columnExpressions/functions/seq_range.d.ts +31 -0
- package/dist/columnExpressions/functions/when.d.ts +2 -2
- package/dist/columnExpressions/index.d.ts +6 -3
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +25 -50
- package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +43 -67
- package/dist/columnExpressions/mixins/ArrayExpr.d.ts +39 -0
- package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +31 -60
- package/dist/columnExpressions/mixins/ListExpr.d.ts +16 -40
- package/dist/columnExpressions/mixins/LogicalExpr.d.ts +7 -33
- package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +6 -31
- package/dist/columnExpressions/mixins/StringExpr.d.ts +7 -32
- package/dist/columnExpressions/mixins/StructExpr.d.ts +16 -0
- package/dist/columnExpressions/mixins/TemporalExpr.d.ts +4 -30
- package/dist/columnExpressions/mixins/WindowExpr.d.ts +27 -49
- package/dist/columnExpressions/types.d.ts +1 -0
- package/dist/columnExpressions/utils.d.ts +4 -0
- package/dist/constants.d.ts +11 -0
- package/dist/dataframe/constants.d.ts +3 -0
- package/dist/dataframe/dataframe.d.ts +28 -11
- package/dist/dataframe/grouped/grouped.d.ts +2 -3
- package/dist/dataframe/types.d.ts +65 -1
- package/dist/dataframe/utils.d.ts +11 -3
- package/dist/datatypes/DataType.d.ts +2 -1
- package/dist/datatypes/index.d.ts +4 -3
- package/dist/datatypes/types.d.ts +42 -41
- package/dist/exceptions/index.d.ts +2 -0
- package/dist/exceptions/utils.d.ts +1 -0
- package/dist/functions/concat.d.ts +1 -2
- package/dist/functions/index.d.ts +3 -1
- package/dist/functions/read_csv.d.ts +8 -0
- package/dist/functions/read_json.d.ts +10 -0
- package/dist/index.js +6 -1
- package/dist/types.d.ts +34 -6
- package/dist/utils/array.d.ts +217 -0
- package/dist/utils/binary.d.ts +3 -0
- package/dist/utils/csv.d.ts +77 -0
- package/dist/utils/date.d.ts +21 -35
- package/dist/utils/guards.d.ts +11 -12
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/json.d.ts +120 -2
- package/dist/utils/list.d.ts +196 -2
- package/dist/utils/number.d.ts +47 -29
- package/dist/utils/object.d.ts +26 -0
- package/dist/utils/string.d.ts +7 -4
- package/package.json +6 -2
- package/dist/api.js +0 -18
- package/dist/bundle.min.js +0 -1
- package/dist/columnExpressions/ColumnExpr.js +0 -23
- package/dist/columnExpressions/ExprBase.js +0 -133
- package/dist/columnExpressions/constants.js +0 -5
- package/dist/columnExpressions/functions/all.js +0 -11
- package/dist/columnExpressions/functions/coalesce.js +0 -40
- package/dist/columnExpressions/functions/exclude.js +0 -13
- package/dist/columnExpressions/functions/lit.js +0 -22
- package/dist/columnExpressions/functions/when.js +0 -81
- package/dist/columnExpressions/index.js +0 -81
- package/dist/columnExpressions/mixins/AggregationExpr.js +0 -172
- package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -143
- package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -389
- package/dist/columnExpressions/mixins/ListExpr.js +0 -248
- package/dist/columnExpressions/mixins/LogicalExpr.js +0 -54
- package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -35
- package/dist/columnExpressions/mixins/StringExpr.js +0 -249
- package/dist/columnExpressions/mixins/TemporalExpr.js +0 -127
- package/dist/columnExpressions/mixins/WindowExpr.js +0 -281
- package/dist/columnExpressions/types.js +0 -2
- package/dist/dataframe/constants.js +0 -4
- package/dist/dataframe/dataframe.js +0 -749
- package/dist/dataframe/grouped/grouped.js +0 -113
- package/dist/dataframe/index.js +0 -20
- package/dist/dataframe/types.js +0 -2
- package/dist/dataframe/utils.js +0 -215
- package/dist/datatypes/DataType.js +0 -47
- 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 -286
- package/dist/exceptions/index.js +0 -43
- package/dist/exceptions/utils.js +0 -9
- package/dist/functions/concat.js +0 -248
- package/dist/functions/index.js +0 -17
- package/dist/types.js +0 -2
- package/dist/utils/boolean.d.ts +0 -1
- package/dist/utils/boolean.js +0 -18
- package/dist/utils/date.js +0 -349
- package/dist/utils/guards.js +0 -143
- package/dist/utils/index.js +0 -21
- package/dist/utils/json.js +0 -33
- package/dist/utils/list.js +0 -128
- package/dist/utils/number.js +0 -223
- package/dist/utils/string.js +0 -120
package/dist/datatypes/types.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Struct = exports.StructType = exports.List = exports.ListType = exports.Duration = exports.DurationType = exports.Time = exports.TimeType = exports.Datetime = exports.DatetimeType = exports.Date = exports.DateType = exports.Object = exports.ObjectType = exports.Null = exports.NullType = exports.Binary = exports.BinaryType = exports.Utf8 = exports.Utf8Type = exports.Boolean = exports.BooleanType = exports.DecimalType = exports.Float64 = exports.Float64Type = exports.Float32 = exports.Float32Type = exports.UInt64 = exports.UInt64Type = exports.UInt32 = exports.UInt32Type = exports.UInt16 = exports.UInt16Type = exports.UInt8 = exports.UInt8Type = exports.Int64 = exports.Int64Type = exports.Int32 = exports.Int32Type = exports.Int16 = exports.Int16Type = exports.Int8 = exports.Int8Type = void 0;
|
|
4
|
-
const DataType_1 = require("./DataType");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// Numeric Types
|
|
8
|
-
// ============================================================================
|
|
9
|
-
class Int8Type extends DataType_1.SignedIntegerType {
|
|
10
|
-
name = "Int8";
|
|
11
|
-
coerce(val) { return (0, utils_1.toValidInt)(val, "Int8"); }
|
|
12
|
-
equals(other) { return other.name === "Int8"; }
|
|
13
|
-
allocate(size) { return new Int8Array(size); }
|
|
14
|
-
}
|
|
15
|
-
exports.Int8Type = Int8Type;
|
|
16
|
-
exports.Int8 = new Int8Type();
|
|
17
|
-
class Int16Type extends DataType_1.SignedIntegerType {
|
|
18
|
-
name = "Int16";
|
|
19
|
-
coerce(val) { return (0, utils_1.toValidInt)(val, "Int16"); }
|
|
20
|
-
equals(other) { return other.name === "Int16"; }
|
|
21
|
-
allocate(size) { return new Int16Array(size); }
|
|
22
|
-
}
|
|
23
|
-
exports.Int16Type = Int16Type;
|
|
24
|
-
exports.Int16 = new Int16Type();
|
|
25
|
-
class Int32Type extends DataType_1.SignedIntegerType {
|
|
26
|
-
name = "Int32";
|
|
27
|
-
coerce(val) { return (0, utils_1.toValidInt)(val, "Int32"); }
|
|
28
|
-
equals(other) { return other.name === "Int32"; }
|
|
29
|
-
allocate(size) { return new Int32Array(size); }
|
|
30
|
-
}
|
|
31
|
-
exports.Int32Type = Int32Type;
|
|
32
|
-
exports.Int32 = new Int32Type();
|
|
33
|
-
class Int64Type extends DataType_1.SignedIntegerType {
|
|
34
|
-
name = "Int64";
|
|
35
|
-
coerce(val) { return (0, utils_1.toValidBigInt)(val); }
|
|
36
|
-
equals(other) { return other.name === "Int64"; }
|
|
37
|
-
allocate(size) { return new BigInt64Array(size); }
|
|
38
|
-
}
|
|
39
|
-
exports.Int64Type = Int64Type;
|
|
40
|
-
exports.Int64 = new Int64Type();
|
|
41
|
-
class UInt8Type extends DataType_1.UnsignedIntegerType {
|
|
42
|
-
name = "UInt8";
|
|
43
|
-
coerce(val) { return (0, utils_1.toValidInt)(val, "UInt8"); }
|
|
44
|
-
equals(other) { return other.name === "UInt8"; }
|
|
45
|
-
allocate(size) { return new Uint8Array(size); }
|
|
46
|
-
}
|
|
47
|
-
exports.UInt8Type = UInt8Type;
|
|
48
|
-
exports.UInt8 = new UInt8Type();
|
|
49
|
-
class UInt16Type extends DataType_1.UnsignedIntegerType {
|
|
50
|
-
name = "UInt16";
|
|
51
|
-
coerce(val) { return (0, utils_1.toValidInt)(val, "UInt16"); }
|
|
52
|
-
equals(other) { return other.name === "UInt16"; }
|
|
53
|
-
allocate(size) { return new Uint16Array(size); }
|
|
54
|
-
}
|
|
55
|
-
exports.UInt16Type = UInt16Type;
|
|
56
|
-
exports.UInt16 = new UInt16Type();
|
|
57
|
-
class UInt32Type extends DataType_1.UnsignedIntegerType {
|
|
58
|
-
name = "UInt32";
|
|
59
|
-
coerce(val) { return (0, utils_1.toValidInt)(val, "UInt32"); }
|
|
60
|
-
equals(other) { return other.name === "UInt32"; }
|
|
61
|
-
allocate(size) { return new Uint32Array(size); }
|
|
62
|
-
}
|
|
63
|
-
exports.UInt32Type = UInt32Type;
|
|
64
|
-
exports.UInt32 = new UInt32Type();
|
|
65
|
-
class UInt64Type extends DataType_1.UnsignedIntegerType {
|
|
66
|
-
name = "UInt64";
|
|
67
|
-
coerce(val) { return (0, utils_1.toValidBigInt)(val, "UInt64"); }
|
|
68
|
-
equals(other) { return other.name === "UInt64"; }
|
|
69
|
-
allocate(size) { return new BigUint64Array(size); }
|
|
70
|
-
}
|
|
71
|
-
exports.UInt64Type = UInt64Type;
|
|
72
|
-
exports.UInt64 = new UInt64Type();
|
|
73
|
-
class Float32Type extends DataType_1.FloatDataType {
|
|
74
|
-
name = "Float32";
|
|
75
|
-
coerce(val) { return (0, utils_1.toValidFloat)(val, "Float32"); }
|
|
76
|
-
equals(other) { return other.name === "Float32"; }
|
|
77
|
-
allocate(size) { return new Float32Array(size); }
|
|
78
|
-
}
|
|
79
|
-
exports.Float32Type = Float32Type;
|
|
80
|
-
exports.Float32 = new Float32Type();
|
|
81
|
-
class Float64Type extends DataType_1.FloatDataType {
|
|
82
|
-
name = "Float64";
|
|
83
|
-
coerce(val) { return (0, utils_1.toValidFloat)(val, "Float64"); }
|
|
84
|
-
equals(other) { return other.name === "Float64"; }
|
|
85
|
-
allocate(size) { return new Float64Array(size); }
|
|
86
|
-
}
|
|
87
|
-
exports.Float64Type = Float64Type;
|
|
88
|
-
exports.Float64 = new Float64Type();
|
|
89
|
-
class DecimalType extends DataType_1.NumericDataType {
|
|
90
|
-
precision;
|
|
91
|
-
scale;
|
|
92
|
-
name;
|
|
93
|
-
constructor(precision, scale) {
|
|
94
|
-
super();
|
|
95
|
-
this.precision = precision;
|
|
96
|
-
this.scale = scale;
|
|
97
|
-
this.name = precision !== undefined && scale !== undefined
|
|
98
|
-
? `Decimal(${precision}, ${scale})`
|
|
99
|
-
: "Decimal";
|
|
100
|
-
}
|
|
101
|
-
coerce(val) {
|
|
102
|
-
return (0, utils_1.toValidDecimal)(val, { precision: this.precision, scale: this.scale });
|
|
103
|
-
}
|
|
104
|
-
equals(other) {
|
|
105
|
-
return other instanceof DecimalType &&
|
|
106
|
-
this.precision === other.precision &&
|
|
107
|
-
this.scale === other.scale;
|
|
108
|
-
}
|
|
109
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
110
|
-
}
|
|
111
|
-
exports.DecimalType = DecimalType;
|
|
112
|
-
// ============================================================================
|
|
113
|
-
// Standard Types
|
|
114
|
-
// ============================================================================
|
|
115
|
-
class BooleanType extends DataType_1.DataType {
|
|
116
|
-
name = "Boolean";
|
|
117
|
-
get isBoolean() { return true; }
|
|
118
|
-
coerce(val) {
|
|
119
|
-
if (val == null)
|
|
120
|
-
return null;
|
|
121
|
-
return !!val;
|
|
122
|
-
}
|
|
123
|
-
equals(other) { return other.name === "Boolean"; }
|
|
124
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
125
|
-
}
|
|
126
|
-
exports.BooleanType = BooleanType;
|
|
127
|
-
exports.Boolean = new BooleanType();
|
|
128
|
-
class Utf8Type extends DataType_1.DataType {
|
|
129
|
-
name = "Utf8";
|
|
130
|
-
get isString() { return true; }
|
|
131
|
-
get isUtf8() { return true; }
|
|
132
|
-
coerce(val) {
|
|
133
|
-
if (val == null)
|
|
134
|
-
return null;
|
|
135
|
-
return String(val);
|
|
136
|
-
}
|
|
137
|
-
equals(other) { return other.name === "Utf8"; }
|
|
138
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
139
|
-
}
|
|
140
|
-
exports.Utf8Type = Utf8Type;
|
|
141
|
-
exports.Utf8 = new Utf8Type();
|
|
142
|
-
class BinaryType extends DataType_1.DataType {
|
|
143
|
-
name = "Binary";
|
|
144
|
-
get isBinary() { return true; }
|
|
145
|
-
coerce(val) { return (0, utils_1.toValidBinary)(val); }
|
|
146
|
-
equals(other) { return other.name === "Binary"; }
|
|
147
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
148
|
-
}
|
|
149
|
-
exports.BinaryType = BinaryType;
|
|
150
|
-
exports.Binary = new BinaryType();
|
|
151
|
-
class NullType extends DataType_1.DataType {
|
|
152
|
-
name = "Null";
|
|
153
|
-
get isNull() { return true; }
|
|
154
|
-
coerce(_val) { return null; }
|
|
155
|
-
equals(other) { return other.name === "Null"; }
|
|
156
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
157
|
-
}
|
|
158
|
-
exports.NullType = NullType;
|
|
159
|
-
exports.Null = new NullType();
|
|
160
|
-
class ObjectType extends DataType_1.DataType {
|
|
161
|
-
name = "Object";
|
|
162
|
-
get isObject() { return true; }
|
|
163
|
-
coerce(val) { return val === undefined ? null : val; }
|
|
164
|
-
equals(other) { return other.name === "Object"; }
|
|
165
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
166
|
-
}
|
|
167
|
-
exports.ObjectType = ObjectType;
|
|
168
|
-
exports.Object = new ObjectType();
|
|
169
|
-
// ============================================================================
|
|
170
|
-
// Temporal Types
|
|
171
|
-
// ============================================================================
|
|
172
|
-
class DateType extends DataType_1.TemporalDataType {
|
|
173
|
-
name = "Date";
|
|
174
|
-
coerce(val) {
|
|
175
|
-
const d = (0, utils_1.toValidDate)(val);
|
|
176
|
-
if (!d)
|
|
177
|
-
return null;
|
|
178
|
-
d.setUTCHours(0, 0, 0, 0);
|
|
179
|
-
return d;
|
|
180
|
-
}
|
|
181
|
-
equals(other) { return other.name === "Date"; }
|
|
182
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
183
|
-
}
|
|
184
|
-
exports.DateType = DateType;
|
|
185
|
-
exports.Date = new DateType();
|
|
186
|
-
class DatetimeType extends DataType_1.TemporalDataType {
|
|
187
|
-
name = "Datetime";
|
|
188
|
-
coerce(val) { return (0, utils_1.toValidDate)(val); }
|
|
189
|
-
equals(other) { return other.name === "Datetime"; }
|
|
190
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
191
|
-
}
|
|
192
|
-
exports.DatetimeType = DatetimeType;
|
|
193
|
-
exports.Datetime = new DatetimeType();
|
|
194
|
-
class TimeType extends DataType_1.TemporalDataType {
|
|
195
|
-
name = "Time";
|
|
196
|
-
coerce(val) {
|
|
197
|
-
if (val == null)
|
|
198
|
-
return null;
|
|
199
|
-
if (typeof val === "string") {
|
|
200
|
-
const trimmed = val.trim();
|
|
201
|
-
if (utils_1.TIME_PREFIX_REGEX.test(trimmed)) {
|
|
202
|
-
const d = new globalThis.Date(`1970-01-01T${trimmed}${utils_1.ZONE_OFFSET_REGEX.test(trimmed) ? "" : "Z"}`);
|
|
203
|
-
if ((0, utils_1.isValidDateObj)(d)) {
|
|
204
|
-
return d.toISOString().split("T")[1].slice(0, 12);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
const d = (0, utils_1.toValidDate)(val);
|
|
209
|
-
return d ? d.toISOString().split("T")[1].slice(0, 12) : null;
|
|
210
|
-
}
|
|
211
|
-
equals(other) { return other.name === "Time"; }
|
|
212
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
213
|
-
}
|
|
214
|
-
exports.TimeType = TimeType;
|
|
215
|
-
exports.Time = new TimeType();
|
|
216
|
-
class DurationType extends DataType_1.TemporalDataType {
|
|
217
|
-
name = "Duration";
|
|
218
|
-
coerce(val) { return (0, utils_1.toValidNumber)(val); }
|
|
219
|
-
equals(other) { return other.name === "Duration"; }
|
|
220
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
221
|
-
}
|
|
222
|
-
exports.DurationType = DurationType;
|
|
223
|
-
exports.Duration = new DurationType();
|
|
224
|
-
// ============================================================================
|
|
225
|
-
// Nested Types
|
|
226
|
-
// ============================================================================
|
|
227
|
-
class ListType extends DataType_1.NestedDataType {
|
|
228
|
-
innerType;
|
|
229
|
-
name = "List";
|
|
230
|
-
constructor(innerType) {
|
|
231
|
-
super();
|
|
232
|
-
this.innerType = innerType;
|
|
233
|
-
}
|
|
234
|
-
coerce(val) {
|
|
235
|
-
if (val == null)
|
|
236
|
-
return null;
|
|
237
|
-
const arr = (0, utils_1.isArrayOrTypedArray)(val) ? Array.from(val) : [val];
|
|
238
|
-
const len = arr.length;
|
|
239
|
-
const res = new Array(len);
|
|
240
|
-
for (let i = 0; i < len; i++) {
|
|
241
|
-
res[i] = this.innerType.coerce(arr[i]);
|
|
242
|
-
}
|
|
243
|
-
return res;
|
|
244
|
-
}
|
|
245
|
-
equals(other) {
|
|
246
|
-
return other instanceof ListType && this.innerType.equals(other.innerType);
|
|
247
|
-
}
|
|
248
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
249
|
-
}
|
|
250
|
-
exports.ListType = ListType;
|
|
251
|
-
const List = (inner) => new ListType(inner);
|
|
252
|
-
exports.List = List;
|
|
253
|
-
class StructType extends DataType_1.NestedDataType {
|
|
254
|
-
fields;
|
|
255
|
-
name = "Struct";
|
|
256
|
-
constructor(fields) {
|
|
257
|
-
super();
|
|
258
|
-
this.fields = fields;
|
|
259
|
-
}
|
|
260
|
-
coerce(val) {
|
|
261
|
-
if (!(0, utils_1.isObj)(val))
|
|
262
|
-
return null;
|
|
263
|
-
const res = {};
|
|
264
|
-
for (const [k, type] of globalThis.Object.entries(this.fields)) {
|
|
265
|
-
res[k] = type.coerce(val[k]);
|
|
266
|
-
}
|
|
267
|
-
return res;
|
|
268
|
-
}
|
|
269
|
-
equals(other) {
|
|
270
|
-
if (!(other instanceof StructType))
|
|
271
|
-
return false;
|
|
272
|
-
const keysThis = globalThis.Object.keys(this.fields);
|
|
273
|
-
const keysOther = globalThis.Object.keys(other.fields);
|
|
274
|
-
if (keysThis.length !== keysOther.length)
|
|
275
|
-
return false;
|
|
276
|
-
for (const k of keysThis) {
|
|
277
|
-
if (!other.fields[k] || !this.fields[k].equals(other.fields[k]))
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
allocate(size) { return new Array(size).fill(null); }
|
|
283
|
-
}
|
|
284
|
-
exports.StructType = StructType;
|
|
285
|
-
const Struct = (fields) => new StructType(fields);
|
|
286
|
-
exports.Struct = Struct;
|
package/dist/exceptions/index.js
DELETED
|
@@ -1,43 +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
|
-
exports.ComputeError = exports.SchemaError = exports.ColumnNotFoundError = exports.DataFrameError = exports.DFScriptError = void 0;
|
|
18
|
-
class DFScriptError extends Error {
|
|
19
|
-
constructor(message) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.name = this.constructor.name;
|
|
22
|
-
if (Error.captureStackTrace) {
|
|
23
|
-
Error.captureStackTrace(this, this.constructor);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.DFScriptError = DFScriptError;
|
|
28
|
-
class DataFrameError extends DFScriptError {
|
|
29
|
-
}
|
|
30
|
-
exports.DataFrameError = DataFrameError;
|
|
31
|
-
class ColumnNotFoundError extends DataFrameError {
|
|
32
|
-
constructor(columnName, message) {
|
|
33
|
-
super(message || `Column "${columnName}" does not exist in the DataFrame.`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.ColumnNotFoundError = ColumnNotFoundError;
|
|
37
|
-
class SchemaError extends DFScriptError {
|
|
38
|
-
}
|
|
39
|
-
exports.SchemaError = SchemaError;
|
|
40
|
-
class ComputeError extends DFScriptError {
|
|
41
|
-
}
|
|
42
|
-
exports.ComputeError = ComputeError;
|
|
43
|
-
__exportStar(require("./utils"), exports);
|
package/dist/exceptions/utils.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertColumnExists = assertColumnExists;
|
|
4
|
-
const index_1 = require("./index");
|
|
5
|
-
function assertColumnExists(columnName, columns, context, suffix = "") {
|
|
6
|
-
if (!(columnName in columns)) {
|
|
7
|
-
throw new index_1.ColumnNotFoundError(columnName, `${context} "${columnName}" does not exist${suffix}`);
|
|
8
|
-
}
|
|
9
|
-
}
|
package/dist/functions/concat.js
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeToDataFrames = normalizeToDataFrames;
|
|
4
|
-
exports.concat = concat;
|
|
5
|
-
const dataframe_1 = require("../dataframe/dataframe");
|
|
6
|
-
const datatypes_1 = require("../datatypes");
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
const exceptions_1 = require("../exceptions");
|
|
9
|
-
function normalizeToDataFrames(item, context, index) {
|
|
10
|
-
if (item == null) {
|
|
11
|
-
throw new exceptions_1.DataFrameError(`Invalid input to ${context} at index ${index}: item cannot be null or undefined.`);
|
|
12
|
-
}
|
|
13
|
-
if (item instanceof dataframe_1.DataFrame) {
|
|
14
|
-
return [item];
|
|
15
|
-
}
|
|
16
|
-
if ((0, utils_1.isPlainObj)(item)) {
|
|
17
|
-
return [new dataframe_1.DataFrame(item)];
|
|
18
|
-
}
|
|
19
|
-
if ((0, utils_1.isArrayOrTypedArray)(item)) {
|
|
20
|
-
if ((0, utils_1.isArrayOfType)(item, dataframe_1.DataFrame, { mode: "every" })) {
|
|
21
|
-
return item;
|
|
22
|
-
}
|
|
23
|
-
if ((0, utils_1.isArrayOfType)(item, "plainObject", { mode: "every" })) {
|
|
24
|
-
return [new dataframe_1.DataFrame(item)];
|
|
25
|
-
}
|
|
26
|
-
const anyDF = (0, utils_1.isArrayOfType)(item, dataframe_1.DataFrame, { mode: "some" });
|
|
27
|
-
for (let j = 0; j < item.length; j++) {
|
|
28
|
-
if (anyDF ? !(item[j] instanceof dataframe_1.DataFrame) : !(0, utils_1.isPlainObj)(item[j])) {
|
|
29
|
-
throw new exceptions_1.DataFrameError(anyDF
|
|
30
|
-
? `Invalid input to ${context} at index ${index}, sub-index ${j}: nested array must contain only DataFrame instances.`
|
|
31
|
-
: `Invalid input to ${context} at index ${index}, row ${j}: rows must be plain objects.`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
throw new exceptions_1.DataFrameError(`Invalid input to ${context} at index ${index}: expected DataFrame, row array, or column dictionary.`);
|
|
36
|
-
}
|
|
37
|
-
function concat(rawItems, options = {}) {
|
|
38
|
-
if (rawItems == null) {
|
|
39
|
-
throw new exceptions_1.DataFrameError("Invalid input to concat: rawItems cannot be null or undefined.");
|
|
40
|
-
}
|
|
41
|
-
const itemsArray = Array.isArray(rawItems) ? rawItems : [rawItems];
|
|
42
|
-
const items = [];
|
|
43
|
-
for (let i = 0; i < itemsArray.length; i++) {
|
|
44
|
-
items.push(...normalizeToDataFrames(itemsArray[i], "concat", i));
|
|
45
|
-
}
|
|
46
|
-
const { how = 'vertical' } = options;
|
|
47
|
-
const strict = options.horizontal?.strict ?? true;
|
|
48
|
-
if (items.length === 0)
|
|
49
|
-
return new dataframe_1.DataFrame({}, {}, 0);
|
|
50
|
-
if (items.length === 1 && how !== 'horizontal')
|
|
51
|
-
return items[0];
|
|
52
|
-
switch (how) {
|
|
53
|
-
case 'vertical': {
|
|
54
|
-
const validItems = [];
|
|
55
|
-
for (let i = 0; i < items.length; i++) {
|
|
56
|
-
if (items[i].height > 0) {
|
|
57
|
-
validItems.push(items[i]);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (validItems.length === 0)
|
|
61
|
-
return new dataframe_1.DataFrame({}, {}, 0);
|
|
62
|
-
const firstDF = validItems[0];
|
|
63
|
-
const firstKeys = Object.keys(firstDF._columns);
|
|
64
|
-
for (let i = 0; i < items.length; i++) {
|
|
65
|
-
const currentDF = items[i];
|
|
66
|
-
if (currentDF.height === 0)
|
|
67
|
-
continue;
|
|
68
|
-
const currentKeys = Object.keys(currentDF._columns);
|
|
69
|
-
if (firstKeys.length !== currentKeys.length) {
|
|
70
|
-
throw new exceptions_1.DataFrameError(`[Strict Vertical] Column count mismatch at index ${i}.`);
|
|
71
|
-
}
|
|
72
|
-
for (let j = 0; j < firstKeys.length; j++) {
|
|
73
|
-
if (firstKeys[j] !== currentKeys[j]) {
|
|
74
|
-
throw new exceptions_1.DataFrameError(`[Strict Vertical] Schema mismatch at position ${j} in DF ${i}. ` +
|
|
75
|
-
`Expected column "${firstKeys[j]}", but found "${currentKeys[j]}".`);
|
|
76
|
-
}
|
|
77
|
-
const typeA = firstDF.schema[firstKeys[j]];
|
|
78
|
-
const typeB = currentDF.schema[firstKeys[j]];
|
|
79
|
-
if (typeA && typeB && !typeA.equals(typeB)) {
|
|
80
|
-
throw new exceptions_1.SchemaError(`[Strict Type Check] Schema type mismatch for column "${firstKeys[j]}": expected ${typeA.name}, found ${typeB.name}.`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
let newHeight = 0;
|
|
85
|
-
for (const item of items) {
|
|
86
|
-
newHeight += item.height;
|
|
87
|
-
}
|
|
88
|
-
const outSchema = items.find(df => df.height > 0)?.schema || items[0]?.schema || {};
|
|
89
|
-
const newColumns = {};
|
|
90
|
-
for (const key of firstKeys) {
|
|
91
|
-
const type = outSchema[key];
|
|
92
|
-
let hasNulls = false;
|
|
93
|
-
for (const item of items) {
|
|
94
|
-
const colArr = item._columns[key];
|
|
95
|
-
if (!colArr) {
|
|
96
|
-
hasNulls = true;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
if (!(0, utils_1.isTypedArray)(colArr)) {
|
|
100
|
-
for (let i = 0; i < colArr.length; i++) {
|
|
101
|
-
if (colArr[i] == null) {
|
|
102
|
-
hasNulls = true;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (hasNulls)
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
let dest = type && type.allocate ? type.allocate(newHeight) : new Array(newHeight).fill(null);
|
|
111
|
-
if (hasNulls && (0, utils_1.isTypedArray)(dest)) {
|
|
112
|
-
dest = new Array(newHeight).fill(null);
|
|
113
|
-
}
|
|
114
|
-
newColumns[key] = dest;
|
|
115
|
-
}
|
|
116
|
-
let offset = 0;
|
|
117
|
-
for (const item of items) {
|
|
118
|
-
const h = item.height;
|
|
119
|
-
if (h === 0)
|
|
120
|
-
continue;
|
|
121
|
-
for (const key of firstKeys) {
|
|
122
|
-
const colArr = item._columns[key] || new Array(h).fill(null);
|
|
123
|
-
const dest = newColumns[key];
|
|
124
|
-
if ((0, utils_1.isTypedArray)(dest) && (0, utils_1.isTypedArray)(colArr)) {
|
|
125
|
-
dest.set(colArr, offset);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
const destArr = dest;
|
|
129
|
-
for (let i = 0; i < h; i++) {
|
|
130
|
-
destArr[offset + i] = colArr[i];
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
offset += h;
|
|
135
|
-
}
|
|
136
|
-
return new dataframe_1.DataFrame(newColumns, outSchema, newHeight);
|
|
137
|
-
}
|
|
138
|
-
case 'horizontal': {
|
|
139
|
-
let maxHeight = items[0].height;
|
|
140
|
-
for (let i = 1; i < items.length; i++) {
|
|
141
|
-
if (items[i].height > maxHeight) {
|
|
142
|
-
maxHeight = items[i].height;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
const allColNames = new Set();
|
|
146
|
-
for (let idx = 0; idx < items.length; idx++) {
|
|
147
|
-
const df = items[idx];
|
|
148
|
-
if (strict && df.height !== maxHeight) {
|
|
149
|
-
throw new exceptions_1.DataFrameError(`[Horizontal] Row count mismatch at index ${idx}. Expected ${maxHeight}, got ${df.height}. Set strict=false to allow padding.`);
|
|
150
|
-
}
|
|
151
|
-
for (const key of Object.keys(df._columns)) {
|
|
152
|
-
if (allColNames.has(key)) {
|
|
153
|
-
throw new exceptions_1.DataFrameError(`[Horizontal] Duplicate column name "${key}" detected. Horizontal concat requires unique names.`);
|
|
154
|
-
}
|
|
155
|
-
allColNames.add(key);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const newColumns = {};
|
|
159
|
-
const outSchema = {};
|
|
160
|
-
for (const df of items) {
|
|
161
|
-
const h = df.height;
|
|
162
|
-
Object.assign(outSchema, df.schema);
|
|
163
|
-
for (const [key, col] of Object.entries(df._columns)) {
|
|
164
|
-
if (h === maxHeight) {
|
|
165
|
-
newColumns[key] = (0, utils_1.isTypedArray)(col) ? Array.from(col) : col;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
const padded = new Array(maxHeight);
|
|
169
|
-
for (let i = 0; i < h; i++) {
|
|
170
|
-
padded[i] = col[i];
|
|
171
|
-
}
|
|
172
|
-
for (let i = h; i < maxHeight; i++) {
|
|
173
|
-
padded[i] = null;
|
|
174
|
-
}
|
|
175
|
-
newColumns[key] = padded;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return new dataframe_1.DataFrame(newColumns, outSchema, maxHeight);
|
|
180
|
-
}
|
|
181
|
-
case 'diagonal': {
|
|
182
|
-
const allColumnsSet = new Set();
|
|
183
|
-
for (const df of items) {
|
|
184
|
-
for (const key of Object.keys(df._columns)) {
|
|
185
|
-
allColumnsSet.add(key);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
const allColumns = Array.from(allColumnsSet);
|
|
189
|
-
let newHeight = 0;
|
|
190
|
-
for (let i = 0; i < items.length; i++) {
|
|
191
|
-
newHeight += items[i].height;
|
|
192
|
-
}
|
|
193
|
-
const outSchema = {};
|
|
194
|
-
for (const key of allColumns) {
|
|
195
|
-
let colType = null;
|
|
196
|
-
for (const item of items) {
|
|
197
|
-
const itemType = item.schema[key];
|
|
198
|
-
if (itemType) {
|
|
199
|
-
if (colType === null) {
|
|
200
|
-
colType = itemType;
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
if (!colType.equals(itemType)) {
|
|
204
|
-
throw new exceptions_1.SchemaError(`[Strict Type Check] Schema type mismatch for column "${key}": expected ${colType.name}, found ${itemType.name}.`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
outSchema[key] = colType || datatypes_1.DataTypeRegistry.Utf8;
|
|
210
|
-
}
|
|
211
|
-
const newColumns = {};
|
|
212
|
-
for (let j = 0; j < allColumns.length; j++) {
|
|
213
|
-
newColumns[allColumns[j]] = new Array(newHeight).fill(null);
|
|
214
|
-
}
|
|
215
|
-
let offset = 0;
|
|
216
|
-
for (let i = 0; i < items.length; i++) {
|
|
217
|
-
const df = items[i];
|
|
218
|
-
const h = df.height;
|
|
219
|
-
if (h === 0)
|
|
220
|
-
continue;
|
|
221
|
-
for (let j = 0; j < allColumns.length; j++) {
|
|
222
|
-
const col = allColumns[j];
|
|
223
|
-
const dest = newColumns[col];
|
|
224
|
-
const src = df._columns[col];
|
|
225
|
-
if (src !== undefined) {
|
|
226
|
-
if ((0, utils_1.isTypedArray)(src) && (0, utils_1.isTypedArray)(dest)) {
|
|
227
|
-
dest.set(src, offset);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
const destArr = dest;
|
|
231
|
-
for (let k = 0; k < h; k++) {
|
|
232
|
-
destArr[offset + k] = src[k];
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
const destArr = dest;
|
|
238
|
-
for (let k = 0; k < h; k++) {
|
|
239
|
-
destArr[offset + k] = null;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
offset += h;
|
|
244
|
-
}
|
|
245
|
-
return new dataframe_1.DataFrame(newColumns, outSchema, newHeight);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
package/dist/functions/index.js
DELETED
|
@@ -1,17 +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("./concat"), exports);
|
package/dist/types.js
DELETED
package/dist/utils/boolean.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function tryParseBoolean(v: unknown): boolean | undefined;
|
package/dist/utils/boolean.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tryParseBoolean = tryParseBoolean;
|
|
4
|
-
const boolMap = {
|
|
5
|
-
true: true, "1": true, yes: true, y: true, on: true,
|
|
6
|
-
false: false, "0": false, no: false, n: false, off: false
|
|
7
|
-
};
|
|
8
|
-
function tryParseBoolean(v) {
|
|
9
|
-
if (typeof v === "boolean")
|
|
10
|
-
return v;
|
|
11
|
-
if (v === 1)
|
|
12
|
-
return true;
|
|
13
|
-
if (v === 0)
|
|
14
|
-
return false;
|
|
15
|
-
if (typeof v !== "string")
|
|
16
|
-
return undefined;
|
|
17
|
-
return boolMap[v.trim().toLowerCase()];
|
|
18
|
-
}
|