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.
Files changed (159) hide show
  1. package/README.md +125 -9
  2. package/dist/api.d.ts +3 -2
  3. package/dist/assets/index-DBhGK6Tp.css +1 -0
  4. package/dist/assets/index-DEJEV_tU.js +195 -0
  5. package/dist/columnExpressions/ColumnExpr.d.ts +14 -7
  6. package/dist/columnExpressions/ExprBase.d.ts +26 -12
  7. package/dist/columnExpressions/constants.d.ts +1 -0
  8. package/dist/columnExpressions/functions/all.d.ts +23 -0
  9. package/dist/columnExpressions/functions/coalesce.d.ts +31 -2
  10. package/dist/columnExpressions/functions/element.d.ts +26 -1
  11. package/dist/columnExpressions/functions/exclude.d.ts +24 -0
  12. package/dist/columnExpressions/functions/implode.d.ts +28 -0
  13. package/dist/columnExpressions/functions/lit.d.ts +27 -0
  14. package/dist/columnExpressions/functions/seq_range.d.ts +36 -0
  15. package/dist/columnExpressions/functions/struct.d.ts +31 -0
  16. package/dist/columnExpressions/functions/when.d.ts +38 -8
  17. package/dist/columnExpressions/index.d.ts +2 -1
  18. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +336 -2
  19. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +620 -10
  20. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +567 -0
  21. package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +353 -0
  22. package/dist/columnExpressions/mixins/LogicalExpr.d.ts +82 -0
  23. package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +40 -0
  24. package/dist/columnExpressions/mixins/StringExpr.d.ts +658 -5
  25. package/dist/columnExpressions/mixins/StructExpr.d.ts +70 -0
  26. package/dist/columnExpressions/mixins/TemporalExpr.d.ts +530 -4
  27. package/dist/columnExpressions/mixins/WindowExpr.d.ts +313 -2
  28. package/dist/columnExpressions/types.d.ts +2 -0
  29. package/dist/constants.d.ts +11 -0
  30. package/dist/dataframe/dataframe.d.ts +933 -3
  31. package/dist/dataframe/grouped/grouped.d.ts +41 -6
  32. package/dist/dataframe/types.d.ts +1 -0
  33. package/dist/dataframe/utils.d.ts +1 -0
  34. package/dist/datatypes/index.d.ts +3 -2
  35. package/dist/datatypes/types.d.ts +52 -7
  36. package/dist/exceptions/index.d.ts +23 -0
  37. package/dist/functions/concat.d.ts +50 -0
  38. package/dist/functions/read_csv.d.ts +9 -0
  39. package/dist/functions/read_json.d.ts +7 -2
  40. package/dist/index.html +17 -0
  41. package/dist/index.js +6 -6
  42. package/dist/index.mjs +6 -0
  43. package/dist/types.d.ts +51 -16
  44. package/dist/utils/{list.d.ts → array.d.ts} +68 -15
  45. package/dist/utils/binary.d.ts +3 -0
  46. package/dist/utils/csv.d.ts +1 -0
  47. package/dist/utils/date.d.ts +23 -54
  48. package/dist/utils/index.d.ts +3 -2
  49. package/dist/utils/json.d.ts +1 -0
  50. package/dist/utils/number.d.ts +15 -29
  51. package/dist/utils/object.d.ts +27 -0
  52. package/dist/utils/string.d.ts +15 -5
  53. package/package.json +18 -4
  54. package/dist/api.js +0 -26
  55. package/dist/bundle.min.js +0 -1
  56. package/dist/columnExpressions/ColumnExpr.js +0 -219
  57. package/dist/columnExpressions/ExprBase.js +0 -92
  58. package/dist/columnExpressions/constants.js +0 -7
  59. package/dist/columnExpressions/functions/all.js +0 -11
  60. package/dist/columnExpressions/functions/coalesce.js +0 -44
  61. package/dist/columnExpressions/functions/element.js +0 -11
  62. package/dist/columnExpressions/functions/exclude.js +0 -13
  63. package/dist/columnExpressions/functions/implode.js +0 -7
  64. package/dist/columnExpressions/functions/lit.js +0 -17
  65. package/dist/columnExpressions/functions/repeat.d.ts +0 -47
  66. package/dist/columnExpressions/functions/repeat.js +0 -131
  67. package/dist/columnExpressions/functions/seq_range.js +0 -91
  68. package/dist/columnExpressions/functions/when.js +0 -85
  69. package/dist/columnExpressions/index.js +0 -38
  70. package/dist/columnExpressions/mixins/AggregationExpr.js +0 -76
  71. package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -131
  72. package/dist/columnExpressions/mixins/BooleanExpr.d.ts +0 -40
  73. package/dist/columnExpressions/mixins/BooleanExpr.js +0 -67
  74. package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -250
  75. package/dist/columnExpressions/mixins/ListExpr.d.ts +0 -39
  76. package/dist/columnExpressions/mixins/ListExpr.js +0 -224
  77. package/dist/columnExpressions/mixins/LogicalExpr.js +0 -53
  78. package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -71
  79. package/dist/columnExpressions/mixins/NumericExpr.d.ts +0 -92
  80. package/dist/columnExpressions/mixins/NumericExpr.js +0 -259
  81. package/dist/columnExpressions/mixins/StringExpr.js +0 -237
  82. package/dist/columnExpressions/mixins/StructExpr.js +0 -139
  83. package/dist/columnExpressions/mixins/TemporalExpr.js +0 -126
  84. package/dist/columnExpressions/mixins/WindowExpr.js +0 -151
  85. package/dist/columnExpressions/types.js +0 -2
  86. package/dist/columnExpressions/utils.js +0 -45
  87. package/dist/dataframe/constants.js +0 -7
  88. package/dist/dataframe/dataframe.js +0 -990
  89. package/dist/dataframe/grouped/grouped.js +0 -114
  90. package/dist/dataframe/index.js +0 -20
  91. package/dist/dataframe/types.js +0 -2
  92. package/dist/dataframe/utils.js +0 -307
  93. package/dist/datatypes/DataType.js +0 -76
  94. package/dist/datatypes/index.js +0 -46
  95. package/dist/datatypes/types/Binary.d.ts +0 -9
  96. package/dist/datatypes/types/Binary.js +0 -18
  97. package/dist/datatypes/types/Boolean.d.ts +0 -9
  98. package/dist/datatypes/types/Boolean.js +0 -19
  99. package/dist/datatypes/types/Date.d.ts +0 -8
  100. package/dist/datatypes/types/Date.js +0 -21
  101. package/dist/datatypes/types/Datetime.d.ts +0 -8
  102. package/dist/datatypes/types/Datetime.js +0 -17
  103. package/dist/datatypes/types/Decimal.d.ts +0 -10
  104. package/dist/datatypes/types/Decimal.js +0 -28
  105. package/dist/datatypes/types/Duration.d.ts +0 -8
  106. package/dist/datatypes/types/Duration.js +0 -17
  107. package/dist/datatypes/types/Float32.d.ts +0 -8
  108. package/dist/datatypes/types/Float32.js +0 -17
  109. package/dist/datatypes/types/Float64.d.ts +0 -8
  110. package/dist/datatypes/types/Float64.js +0 -17
  111. package/dist/datatypes/types/Int16.d.ts +0 -8
  112. package/dist/datatypes/types/Int16.js +0 -17
  113. package/dist/datatypes/types/Int32.d.ts +0 -8
  114. package/dist/datatypes/types/Int32.js +0 -17
  115. package/dist/datatypes/types/Int64.d.ts +0 -8
  116. package/dist/datatypes/types/Int64.js +0 -17
  117. package/dist/datatypes/types/Int8.d.ts +0 -8
  118. package/dist/datatypes/types/Int8.js +0 -17
  119. package/dist/datatypes/types/List.d.ts +0 -10
  120. package/dist/datatypes/types/List.js +0 -31
  121. package/dist/datatypes/types/Null.d.ts +0 -9
  122. package/dist/datatypes/types/Null.js +0 -17
  123. package/dist/datatypes/types/Object.d.ts +0 -9
  124. package/dist/datatypes/types/Object.js +0 -17
  125. package/dist/datatypes/types/Struct.d.ts +0 -14
  126. package/dist/datatypes/types/Struct.js +0 -39
  127. package/dist/datatypes/types/Time.d.ts +0 -8
  128. package/dist/datatypes/types/Time.js +0 -29
  129. package/dist/datatypes/types/UInt16.d.ts +0 -8
  130. package/dist/datatypes/types/UInt16.js +0 -17
  131. package/dist/datatypes/types/UInt32.d.ts +0 -8
  132. package/dist/datatypes/types/UInt32.js +0 -17
  133. package/dist/datatypes/types/UInt64.d.ts +0 -8
  134. package/dist/datatypes/types/UInt64.js +0 -17
  135. package/dist/datatypes/types/UInt8.d.ts +0 -8
  136. package/dist/datatypes/types/UInt8.js +0 -17
  137. package/dist/datatypes/types/Utf8.d.ts +0 -10
  138. package/dist/datatypes/types/Utf8.js +0 -20
  139. package/dist/datatypes/types.js +0 -290
  140. package/dist/exceptions/index.js +0 -46
  141. package/dist/exceptions/utils.js +0 -28
  142. package/dist/functions/concat.js +0 -260
  143. package/dist/functions/index.js +0 -9
  144. package/dist/functions/read_csv.js +0 -53
  145. package/dist/functions/read_json.js +0 -21
  146. package/dist/functions/transpose.d.ts +0 -7
  147. package/dist/functions/transpose.js +0 -84
  148. package/dist/types.js +0 -2
  149. package/dist/utils/boolean.d.ts +0 -1
  150. package/dist/utils/boolean.js +0 -18
  151. package/dist/utils/csv.js +0 -313
  152. package/dist/utils/date.js +0 -348
  153. package/dist/utils/guards.d.ts +0 -12
  154. package/dist/utils/guards.js +0 -112
  155. package/dist/utils/index.js +0 -23
  156. package/dist/utils/json.js +0 -217
  157. package/dist/utils/list.js +0 -361
  158. package/dist/utils/number.js +0 -401
  159. package/dist/utils/string.js +0 -209
@@ -1,126 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TemporalExpr = exports.DateTimeExprNamespace = void 0;
4
- const ExprBase_1 = require("../ExprBase");
5
- const utils_1 = require("../utils");
6
- const utils_2 = require("../../utils");
7
- class DateTimeExprNamespace {
8
- expr;
9
- constructor(expr) {
10
- this.expr = expr;
11
- }
12
- _deriveDate(fn) {
13
- return (0, ExprBase_1.derive)(this.expr, (0, utils_1.kleeneUnary)((v) => {
14
- const d = (0, utils_2.toValidDate)(v);
15
- return d ? fn(d) : null;
16
- }));
17
- }
18
- _deriveDuration(fn) {
19
- return (0, ExprBase_1.derive)(this.expr, (0, utils_1.kleeneUnary)((v) => {
20
- return typeof v === "number" ? fn(v) : null;
21
- }));
22
- }
23
- century() {
24
- return this._deriveDate(utils_2.getCentury);
25
- }
26
- date() {
27
- return this._deriveDate((d) => new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate())));
28
- }
29
- datetime() {
30
- return this._deriveDate((d) => d);
31
- }
32
- day() {
33
- return this._deriveDate((d) => d.getUTCDate());
34
- }
35
- epoch(unit = "ms") {
36
- return this._deriveDate((d) => (0, utils_2.toEpoch)(d, unit));
37
- }
38
- hour() {
39
- return this._deriveDate((d) => d.getUTCHours());
40
- }
41
- is_leap_year() {
42
- return this._deriveDate(utils_2.isLeapYear);
43
- }
44
- microsecond() {
45
- return this._deriveDate((d) => d.getUTCMilliseconds() * utils_2.US_PER_MS);
46
- }
47
- millennium() {
48
- return this._deriveDate(utils_2.getMillennium);
49
- }
50
- millisecond() {
51
- return this._deriveDate((d) => d.getUTCMilliseconds());
52
- }
53
- minute() {
54
- return this._deriveDate((d) => d.getUTCMinutes());
55
- }
56
- month() {
57
- return this._deriveDate((d) => d.getUTCMonth() + 1);
58
- }
59
- month_end() {
60
- return this._deriveDate((d) => (0, utils_2.getMonthOffset)(d, 1, 0));
61
- }
62
- month_start() {
63
- return this._deriveDate((d) => (0, utils_2.getMonthOffset)(d, 0, 1));
64
- }
65
- nanosecond() {
66
- return this._deriveDate((d) => d.getUTCMilliseconds() * utils_2.NS_PER_MS);
67
- }
68
- ordinal_day() {
69
- return this._deriveDate(utils_2.getOrdinalDay);
70
- }
71
- quarter() {
72
- return this._deriveDate(utils_2.getQuarter);
73
- }
74
- second() {
75
- return this._deriveDate((d) => d.getUTCSeconds());
76
- }
77
- strftime(format, locale) {
78
- return this._deriveDate((d) => (0, utils_2.strftime)(d, format, locale));
79
- }
80
- time() {
81
- return this._deriveDate((d) => d.toISOString().split("T")[1].slice(0, 12));
82
- }
83
- timestamp(unit = "ms") {
84
- return this.epoch(unit);
85
- }
86
- to_string(format, locale) {
87
- return this.strftime(format, locale);
88
- }
89
- total_days() {
90
- return this._deriveDuration((v) => v / utils_2.MS_PER_DAY);
91
- }
92
- total_hours() {
93
- return this._deriveDuration((v) => v / utils_2.MS_PER_HOUR);
94
- }
95
- total_microseconds() {
96
- return this._deriveDuration((v) => v * utils_2.US_PER_MS);
97
- }
98
- total_milliseconds() {
99
- return this._deriveDuration((v) => v);
100
- }
101
- total_minutes() {
102
- return this._deriveDuration((v) => v / utils_2.MS_PER_MINUTE);
103
- }
104
- total_nanoseconds() {
105
- return this._deriveDuration((v) => v * utils_2.NS_PER_MS);
106
- }
107
- total_seconds() {
108
- return this._deriveDuration((v) => v / utils_2.MS_PER_SECOND);
109
- }
110
- week() {
111
- return this._deriveDate(utils_2.getISOWeek);
112
- }
113
- weekday() {
114
- return this._deriveDate((d) => d.getUTCDay() || 7);
115
- }
116
- year() {
117
- return this._deriveDate((d) => d.getUTCFullYear());
118
- }
119
- }
120
- exports.DateTimeExprNamespace = DateTimeExprNamespace;
121
- class TemporalExpr extends ExprBase_1.ExprBase {
122
- get dt() {
123
- return new DateTimeExprNamespace(this);
124
- }
125
- }
126
- exports.TemporalExpr = TemporalExpr;
@@ -1,151 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WindowExpr = void 0;
4
- const ExprBase_1 = require("../ExprBase");
5
- const utils_1 = require("../../utils");
6
- function computeRank(arr, value, options = {}) {
7
- if (value == null)
8
- return null;
9
- let targetArr = arr;
10
- if (options.ignoreNulls) {
11
- targetArr = [];
12
- const len = arr.length;
13
- for (let i = 0; i < len; i++) {
14
- if (arr[i] != null)
15
- targetArr.push(arr[i]);
16
- }
17
- }
18
- if (options.dense) {
19
- targetArr = Array.from(new Set(targetArr));
20
- }
21
- const sorted = [...targetArr].sort((a, b) => a - b);
22
- const valueToRank = new Map();
23
- const len = sorted.length;
24
- for (let i = 0; i < len; i++) {
25
- const v = sorted[i];
26
- if (!valueToRank.has(v)) {
27
- valueToRank.set(v, i + 1);
28
- }
29
- }
30
- return valueToRank.get(value) ?? null;
31
- }
32
- class WindowExpr extends ExprBase_1.ExprBase {
33
- partitionBy = this.partitionBy || null;
34
- _window(evaluateWindow) {
35
- const newInst = (0, ExprBase_1.derive)(this);
36
- newInst.partitionOpsIndex = this.ops.length;
37
- newInst.groupingOpsIndex = this.ops.length;
38
- newInst.evaluateWindow = evaluateWindow;
39
- return newInst;
40
- }
41
- _rolling(windowSize, aggFn) {
42
- return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
43
- const start = Math.max(0, currentIndex - windowSize + 1);
44
- const end = currentIndex + 1;
45
- const windowVals = groupPreValues.slice(start, end);
46
- return aggFn(windowVals);
47
- });
48
- }
49
- _cum(reverse, initialVal, stepFn, postFn) {
50
- return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
51
- let acc = initialVal;
52
- let hasValid = false;
53
- const start = reverse ? currentIndex : 0;
54
- const end = reverse ? groupPreValues.length - 1 : currentIndex;
55
- for (let i = start; i <= end; i++) {
56
- const val = groupPreValues[i];
57
- if (val != null) {
58
- acc = stepFn(acc, val);
59
- hasValid = true;
60
- }
61
- }
62
- return postFn ? postFn(acc, hasValid) : acc;
63
- });
64
- }
65
- get isWindow() {
66
- return this.partitionBy !== null || this.evaluateWindow !== undefined || this.aggFn !== null;
67
- }
68
- cum_count(reverse = false) {
69
- return this._cum(reverse, 0, (acc) => acc + 1);
70
- }
71
- cum_max(reverse = false) {
72
- return this._cum(reverse, null, (acc, val) => (acc === null || val > acc ? val : acc));
73
- }
74
- cum_min(reverse = false) {
75
- return this._cum(reverse, null, (acc, val) => (acc === null || val < acc ? val : acc));
76
- }
77
- cum_prod(reverse = false) {
78
- return this._cum(reverse, 1, (acc, val) => acc * val, (acc, hasValid) => (hasValid ? acc : null));
79
- }
80
- cum_sum(reverse = false) {
81
- return this._cum(reverse, 0, (acc, val) => acc + val);
82
- }
83
- dense_rank() {
84
- return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
85
- return computeRank(groupPreValues, groupPreValues[currentIndex], { dense: true });
86
- });
87
- }
88
- lag(offset = 1, defaultVal = null) {
89
- return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
90
- let val = defaultVal;
91
- if (currentIndex - offset >= 0) {
92
- val = groupPreValues[currentIndex - offset];
93
- }
94
- return val;
95
- });
96
- }
97
- lead(offset = 1, defaultVal = null) {
98
- return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
99
- let val = defaultVal;
100
- if (currentIndex + offset < groupPreValues.length) {
101
- val = groupPreValues[currentIndex + offset];
102
- }
103
- return val;
104
- });
105
- }
106
- over(columns) {
107
- const newInst = (0, ExprBase_1.derive)(this);
108
- const cols = Array.isArray(columns) ? columns : [columns];
109
- newInst.partitionBy = cols;
110
- return newInst;
111
- }
112
- rank() {
113
- return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
114
- return computeRank(groupPreValues, groupPreValues[currentIndex]);
115
- });
116
- }
117
- rolling_max(windowSize) {
118
- return this._rolling(windowSize, v => (0, utils_1.getListStats)(v).max);
119
- }
120
- rolling_mean(windowSize) {
121
- return this._rolling(windowSize, v => (0, utils_1.getListStats)(v).mean);
122
- }
123
- rolling_median(windowSize) {
124
- return this._rolling(windowSize, v => (0, utils_1.computeMedian)(v));
125
- }
126
- rolling_min(windowSize) {
127
- return this._rolling(windowSize, v => (0, utils_1.getListStats)(v).min);
128
- }
129
- rolling_quantile(quantile, windowSize) {
130
- return this._rolling(windowSize, v => (0, utils_1.computeQuantile)(v, quantile));
131
- }
132
- rolling_rank(windowSize) {
133
- return this._rolling(windowSize, (vals) => {
134
- return computeRank(vals, vals[vals.length - 1], { ignoreNulls: true });
135
- });
136
- }
137
- rolling_std(windowSize) {
138
- return this._rolling(windowSize, v => (0, utils_1.getListStats)(v).std);
139
- }
140
- rolling_sum(windowSize) {
141
- return this._rolling(windowSize, v => (0, utils_1.getListStats)(v).sum);
142
- }
143
- row_number() {
144
- const newInst = this._window(function (_groupPreValues, _partitionIndices, currentIndex) {
145
- return currentIndex + 1;
146
- });
147
- newInst.outputName = "row_number";
148
- return newInst;
149
- }
150
- }
151
- exports.WindowExpr = WindowExpr;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.kleeneBinary = exports.kleeneUnary = void 0;
4
- exports.evaluateExpression = evaluateExpression;
5
- const utils_1 = require("../utils");
6
- const utils_2 = require("../dataframe/utils");
7
- const kleeneUnary = (fn) => {
8
- return (vArray) => {
9
- const height = vArray.length;
10
- const result = new Array(height);
11
- for (let i = 0; i < height; i++) {
12
- const v = vArray[i];
13
- result[i] = v == null ? null : fn(v);
14
- }
15
- return result;
16
- };
17
- };
18
- exports.kleeneUnary = kleeneUnary;
19
- const kleeneBinary = (expr, other, fn) => {
20
- return (vArray, columns) => {
21
- const height = vArray.length;
22
- const rResolved = expr._resolve(other, columns, height);
23
- const result = new Array(height);
24
- if ((0, utils_1.isArrayOrTypedArray)(rResolved)) {
25
- for (let i = 0; i < height; i++) {
26
- const v = vArray[i];
27
- const r = rResolved[i];
28
- result[i] = (v == null || r == null) ? null : fn(v, r);
29
- }
30
- }
31
- else {
32
- for (let i = 0; i < height; i++) {
33
- const v = vArray[i];
34
- result[i] = (v == null || rResolved == null) ? null : fn(v, rResolved);
35
- }
36
- }
37
- return result;
38
- };
39
- };
40
- exports.kleeneBinary = kleeneBinary;
41
- function evaluateExpression(expr, columns, height) {
42
- return expr.isWindow
43
- ? (0, utils_2.resolveWindowExpr)(expr, columns, height)
44
- : expr.evaluate(columns, height);
45
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UTF8_BOM = exports.CARRIAGE_RETURN = exports.NEWLINE = exports.KEY_SEPARATOR = void 0;
4
- exports.KEY_SEPARATOR = "\x00";
5
- exports.NEWLINE = "\n";
6
- exports.CARRIAGE_RETURN = "\r";
7
- exports.UTF8_BOM = "\ufeff";