df-script 1.5.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.
Files changed (133) hide show
  1. package/README.md +124 -8
  2. package/dist/api.d.ts +1 -1
  3. package/dist/columnExpressions/ColumnExpr.d.ts +2 -2
  4. package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
  5. package/dist/columnExpressions/functions/element.d.ts +1 -1
  6. package/dist/columnExpressions/functions/when.d.ts +2 -2
  7. package/dist/columnExpressions/index.d.ts +1 -1
  8. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +2 -2
  9. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +11 -10
  10. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +39 -0
  11. package/dist/columnExpressions/mixins/ListExpr.d.ts +2 -2
  12. package/dist/columnExpressions/mixins/StringExpr.d.ts +2 -2
  13. package/dist/columnExpressions/types.d.ts +1 -0
  14. package/dist/constants.d.ts +11 -0
  15. package/dist/dataframe/dataframe.d.ts +1 -1
  16. package/dist/datatypes/index.d.ts +3 -2
  17. package/dist/datatypes/types.d.ts +7 -7
  18. package/dist/index.js +6 -6
  19. package/dist/types.d.ts +4 -2
  20. package/dist/utils/array.d.ts +217 -0
  21. package/dist/utils/binary.d.ts +3 -0
  22. package/dist/utils/date.d.ts +21 -35
  23. package/dist/utils/guards.d.ts +11 -10
  24. package/dist/utils/index.d.ts +3 -2
  25. package/dist/utils/list.d.ts +23 -1
  26. package/dist/utils/number.d.ts +14 -29
  27. package/dist/utils/object.d.ts +26 -0
  28. package/dist/utils/string.d.ts +3 -5
  29. package/package.json +2 -2
  30. package/dist/api.js +0 -26
  31. package/dist/bundle.min.js +0 -1
  32. package/dist/columnExpressions/ColumnExpr.js +0 -219
  33. package/dist/columnExpressions/ExprBase.js +0 -92
  34. package/dist/columnExpressions/constants.js +0 -7
  35. package/dist/columnExpressions/functions/all.js +0 -11
  36. package/dist/columnExpressions/functions/coalesce.js +0 -44
  37. package/dist/columnExpressions/functions/element.js +0 -11
  38. package/dist/columnExpressions/functions/exclude.js +0 -13
  39. package/dist/columnExpressions/functions/implode.js +0 -7
  40. package/dist/columnExpressions/functions/lit.js +0 -17
  41. package/dist/columnExpressions/functions/repeat.d.ts +0 -47
  42. package/dist/columnExpressions/functions/repeat.js +0 -131
  43. package/dist/columnExpressions/functions/seq_range.js +0 -91
  44. package/dist/columnExpressions/functions/when.js +0 -85
  45. package/dist/columnExpressions/index.js +0 -38
  46. package/dist/columnExpressions/mixins/AggregationExpr.js +0 -76
  47. package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -131
  48. package/dist/columnExpressions/mixins/BooleanExpr.d.ts +0 -40
  49. package/dist/columnExpressions/mixins/BooleanExpr.js +0 -67
  50. package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -250
  51. package/dist/columnExpressions/mixins/ListExpr.js +0 -224
  52. package/dist/columnExpressions/mixins/LogicalExpr.js +0 -53
  53. package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -71
  54. package/dist/columnExpressions/mixins/NumericExpr.d.ts +0 -92
  55. package/dist/columnExpressions/mixins/NumericExpr.js +0 -259
  56. package/dist/columnExpressions/mixins/StringExpr.js +0 -237
  57. package/dist/columnExpressions/mixins/StructExpr.js +0 -139
  58. package/dist/columnExpressions/mixins/TemporalExpr.js +0 -126
  59. package/dist/columnExpressions/mixins/WindowExpr.js +0 -151
  60. package/dist/columnExpressions/types.js +0 -2
  61. package/dist/columnExpressions/utils.js +0 -45
  62. package/dist/dataframe/constants.js +0 -7
  63. package/dist/dataframe/dataframe.js +0 -990
  64. package/dist/dataframe/grouped/grouped.js +0 -114
  65. package/dist/dataframe/index.js +0 -20
  66. package/dist/dataframe/types.js +0 -2
  67. package/dist/dataframe/utils.js +0 -307
  68. package/dist/datatypes/DataType.js +0 -76
  69. package/dist/datatypes/index.js +0 -46
  70. package/dist/datatypes/types/Binary.d.ts +0 -9
  71. package/dist/datatypes/types/Binary.js +0 -18
  72. package/dist/datatypes/types/Boolean.d.ts +0 -9
  73. package/dist/datatypes/types/Boolean.js +0 -19
  74. package/dist/datatypes/types/Date.d.ts +0 -8
  75. package/dist/datatypes/types/Date.js +0 -21
  76. package/dist/datatypes/types/Datetime.d.ts +0 -8
  77. package/dist/datatypes/types/Datetime.js +0 -17
  78. package/dist/datatypes/types/Decimal.d.ts +0 -10
  79. package/dist/datatypes/types/Decimal.js +0 -28
  80. package/dist/datatypes/types/Duration.d.ts +0 -8
  81. package/dist/datatypes/types/Duration.js +0 -17
  82. package/dist/datatypes/types/Float32.d.ts +0 -8
  83. package/dist/datatypes/types/Float32.js +0 -17
  84. package/dist/datatypes/types/Float64.d.ts +0 -8
  85. package/dist/datatypes/types/Float64.js +0 -17
  86. package/dist/datatypes/types/Int16.d.ts +0 -8
  87. package/dist/datatypes/types/Int16.js +0 -17
  88. package/dist/datatypes/types/Int32.d.ts +0 -8
  89. package/dist/datatypes/types/Int32.js +0 -17
  90. package/dist/datatypes/types/Int64.d.ts +0 -8
  91. package/dist/datatypes/types/Int64.js +0 -17
  92. package/dist/datatypes/types/Int8.d.ts +0 -8
  93. package/dist/datatypes/types/Int8.js +0 -17
  94. package/dist/datatypes/types/List.d.ts +0 -10
  95. package/dist/datatypes/types/List.js +0 -31
  96. package/dist/datatypes/types/Null.d.ts +0 -9
  97. package/dist/datatypes/types/Null.js +0 -17
  98. package/dist/datatypes/types/Object.d.ts +0 -9
  99. package/dist/datatypes/types/Object.js +0 -17
  100. package/dist/datatypes/types/Struct.d.ts +0 -14
  101. package/dist/datatypes/types/Struct.js +0 -39
  102. package/dist/datatypes/types/Time.d.ts +0 -8
  103. package/dist/datatypes/types/Time.js +0 -29
  104. package/dist/datatypes/types/UInt16.d.ts +0 -8
  105. package/dist/datatypes/types/UInt16.js +0 -17
  106. package/dist/datatypes/types/UInt32.d.ts +0 -8
  107. package/dist/datatypes/types/UInt32.js +0 -17
  108. package/dist/datatypes/types/UInt64.d.ts +0 -8
  109. package/dist/datatypes/types/UInt64.js +0 -17
  110. package/dist/datatypes/types/UInt8.d.ts +0 -8
  111. package/dist/datatypes/types/UInt8.js +0 -17
  112. package/dist/datatypes/types/Utf8.d.ts +0 -10
  113. package/dist/datatypes/types/Utf8.js +0 -20
  114. package/dist/datatypes/types.js +0 -290
  115. package/dist/exceptions/index.js +0 -46
  116. package/dist/exceptions/utils.js +0 -28
  117. package/dist/functions/concat.js +0 -260
  118. package/dist/functions/index.js +0 -9
  119. package/dist/functions/read_csv.js +0 -53
  120. package/dist/functions/read_json.js +0 -21
  121. package/dist/functions/transpose.d.ts +0 -7
  122. package/dist/functions/transpose.js +0 -84
  123. package/dist/types.js +0 -2
  124. package/dist/utils/boolean.d.ts +0 -1
  125. package/dist/utils/boolean.js +0 -18
  126. package/dist/utils/csv.js +0 -313
  127. package/dist/utils/date.js +0 -348
  128. package/dist/utils/guards.js +0 -112
  129. package/dist/utils/index.js +0 -23
  130. package/dist/utils/json.js +0 -217
  131. package/dist/utils/list.js +0 -361
  132. package/dist/utils/number.js +0 -401
  133. 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";