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.
- package/README.md +124 -8
- package/dist/api.d.ts +1 -1
- package/dist/columnExpressions/ColumnExpr.d.ts +2 -2
- package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
- package/dist/columnExpressions/functions/element.d.ts +1 -1
- package/dist/columnExpressions/functions/when.d.ts +2 -2
- package/dist/columnExpressions/index.d.ts +1 -1
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +2 -2
- package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +11 -10
- package/dist/columnExpressions/mixins/ArrayExpr.d.ts +39 -0
- package/dist/columnExpressions/mixins/ListExpr.d.ts +2 -2
- package/dist/columnExpressions/mixins/StringExpr.d.ts +2 -2
- package/dist/columnExpressions/types.d.ts +1 -0
- package/dist/constants.d.ts +11 -0
- package/dist/dataframe/dataframe.d.ts +1 -1
- package/dist/datatypes/index.d.ts +3 -2
- package/dist/datatypes/types.d.ts +7 -7
- package/dist/index.js +6 -6
- package/dist/types.d.ts +4 -2
- package/dist/utils/array.d.ts +217 -0
- package/dist/utils/binary.d.ts +3 -0
- package/dist/utils/date.d.ts +21 -35
- package/dist/utils/guards.d.ts +11 -10
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/list.d.ts +23 -1
- package/dist/utils/number.d.ts +14 -29
- package/dist/utils/object.d.ts +26 -0
- package/dist/utils/string.d.ts +3 -5
- package/package.json +2 -2
- 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.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.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
package/README.md
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
# 🚀 DFScript
|
|
2
2
|
|
|
3
|
+
[](https://github.com/trentamorris/df-script)
|
|
3
4
|
[](DONATIONS.md)
|
|
4
5
|
|
|
5
6
|
DFScript is a lightweight, high-performance, and **zero-dependency** data analysis library for TypeScript and JavaScript. Heavily inspired by modern dataframe libraries like **Polars** and **Pandas**, DFScript brings a robust, expression-based columnar data processing engine directly to the JavaScript ecosystem.
|
|
6
7
|
|
|
7
8
|
With optimized columnar storage under the hood, DFScript enables you to build clean, maintainable, and type-safe data pipelines using a declarative expression API.
|
|
8
9
|
|
|
10
|
+
## 💡 Why DFScript?
|
|
11
|
+
|
|
12
|
+
Like many developers, I spent years working on frontend codebases filled with deeply nested, unoptimized data processing loops. We've all seen them: chained `.map()`, `.filter()`, `.sort()`, and `.forEach()` loops processing arrays of objects. Each step in the chain allocates new intermediate arrays, triggers garbage collection thrashing, and operates on row-based layouts that slow down browser main threads.
|
|
13
|
+
|
|
14
|
+
When you need to perform complex analytical transformations on the client-side—handling missing values, formatting timezone-aware datetimes, parsing decimals, or computing rolling averages—relying on standard JavaScript array methods quickly becomes a performance and maintenance nightmare. There had to be a better, cleaner, and faster way to express these pipelines. I realized that if nobody else had built a lightweight, zero-dependency columnar expression engine for the JavaScript ecosystem yet, why not roll up my sleeves and build it myself?
|
|
15
|
+
|
|
16
|
+
DFScript was born from that frustration. It brings Polars-like columnar execution, strict domain namespaces (`.str`, `.dt`, `.arr`, `.struct`), and lazy/declarative expression compilation to JavaScript. Under the hood, it avoids intermediate array allocations and uses highly optimized loops with cached lengths, so your frontend code stays clean, type-safe, and incredibly fast.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 🗺️ Table of Contents
|
|
21
|
+
|
|
22
|
+
- [✨ Key Features](#-key-features)
|
|
23
|
+
- [⚙️ Compatibility & Design Principles](#-compatibility--design-principles)
|
|
24
|
+
- [🤝 Contributing & Collective Wisdom](#-contributing--collective-wisdom)
|
|
25
|
+
- [📦 Installation](#-installation)
|
|
26
|
+
- [🚀 Quick Start](#-quick-start)
|
|
27
|
+
- [📖 Core Concepts](#-core-concepts)
|
|
28
|
+
- [🛠️ DataFrame API Reference](#-dataframe-api-reference)
|
|
29
|
+
- [📂 File / Data I/O](#-file--data-io)
|
|
30
|
+
- [🧮 Expressions API Reference](#-expressions-api-reference)
|
|
31
|
+
- [📂 Namespaces](#-namespaces)
|
|
32
|
+
- [🪟 Window & Rolling Expressions](#-window--rolling-expressions)
|
|
33
|
+
- [🛡️ Typing and Schema Registry](#-typing-and-schema-registry)
|
|
34
|
+
- [🧑💻 Contributing & Development](#-contributing--development)
|
|
35
|
+
- [📄 License](#-license)
|
|
36
|
+
|
|
9
37
|
---
|
|
10
38
|
|
|
11
39
|
## ✨ Key Features
|
|
@@ -16,7 +44,8 @@ With optimized columnar storage under the hood, DFScript enables you to build cl
|
|
|
16
44
|
- 📂 **Strict Namespaces** — Clear API organization for specific domains:
|
|
17
45
|
- `.str` for advanced string manipulations.
|
|
18
46
|
- `.dt` for microsecond-precision datetimes, timezones, and duration calculations.
|
|
19
|
-
- `.
|
|
47
|
+
- `.arr` for robust array/list column operations.
|
|
48
|
+
- `.struct` for nested object and struct manipulation.
|
|
20
49
|
- 🪟 **Analytical Window Functions** — Windowing (`over()`), cumulative aggregations (`cum_sum()`, `cum_max()`), and rolling metrics (`rolling_mean()`, `rolling_std()`).
|
|
21
50
|
- 🛠️ **Relational Operations** — Rich, high-speed joins, pivots, unpivots, vertical/horizontal concatenations, and group-by aggregations.
|
|
22
51
|
- 🛡️ **Defensive & Type-Safe** — Native type-coercion, robust null-safety, and strict schema validation.
|
|
@@ -35,6 +64,14 @@ DFScript is designed with a **low-abstraction, zero-dependency** philosophy to g
|
|
|
35
64
|
|
|
36
65
|
---
|
|
37
66
|
|
|
67
|
+
## 🤝 Contributing & Collective Wisdom
|
|
68
|
+
|
|
69
|
+
We don’t pretend to have encountered every localized date format, database quirk, or environment-specific edge case. DFScript is built on the belief that software correctness is a collective endeavor.
|
|
70
|
+
|
|
71
|
+
If you run into an unsupported edge case or unexpected behavior in any of our functions, we want to hear about it. Help us harden this engine by opening a GitHub Issue or submitting a PR—every report makes the library more robust for everyone.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
38
75
|
## 📦 Installation
|
|
39
76
|
|
|
40
77
|
Install DFScript using your favorite package manager:
|
|
@@ -73,7 +110,7 @@ const processedDf = df.select(
|
|
|
73
110
|
$df.col("name").str.upper().alias("NAME_UPPER"),
|
|
74
111
|
$df.col("join_date").str.to_datetime().dt.year().alias("join_year"),
|
|
75
112
|
$df.col("sales").add(500).alias("sales_adjusted"),
|
|
76
|
-
$df.col("tags").
|
|
113
|
+
$df.col("tags").arr.lengths().alias("tag_count")
|
|
77
114
|
);
|
|
78
115
|
|
|
79
116
|
console.log(processedDf.to_dicts());
|
|
@@ -93,12 +130,20 @@ console.log(processedDf.to_dicts());
|
|
|
93
130
|
|
|
94
131
|
### The `$df` Entry Point
|
|
95
132
|
|
|
96
|
-
DFScript uses the `$df` namespace to bootstrap DataFrames, refer to columns, and access
|
|
133
|
+
DFScript uses the `$df` namespace to bootstrap DataFrames, refer to columns, build expressions, and access data types.
|
|
97
134
|
|
|
98
135
|
- `$df.data(dataRowsOrCols, schema?)`: Instantiates a new `DataFrame`.
|
|
99
136
|
- `$df.read_json(content, options?)`: Reads JSON/NDJSON content into a new `DataFrame`.
|
|
137
|
+
- `$df.read_csv(content, options?)`: Reads CSV content into a new `DataFrame`.
|
|
100
138
|
- `$df.col(name)`: Creates a column reference expression.
|
|
101
139
|
- `$df.all()`: Selects all columns in the DataFrame.
|
|
140
|
+
- `$df.exclude(columns)`: Creates an expression matching all columns except the specified ones.
|
|
141
|
+
- `$df.coalesce(...exprs)`: Returns the first non-null value among columns or literal expressions.
|
|
142
|
+
- `$df.lit(val)`: Explicitly wraps a raw value into a literal expression.
|
|
143
|
+
- `$df.when(predicate).then(value)...otherwise(value)`: Constructs a conditional expression (when-then-otherwise chain).
|
|
144
|
+
- `$df.implode(column)`: Aggregates a column's rows (or grouped values) into a list.
|
|
145
|
+
- `$df.seq_range(value, options?)`: Generates a sequence range of values.
|
|
146
|
+
- `$df.element()`: References the current array element within an `.arr.eval(...)` expression.
|
|
102
147
|
- `$df.DataType`: Direct access to the `DataTypeRegistry` for schema specification.
|
|
103
148
|
|
|
104
149
|
### DataFrames vs. Columns
|
|
@@ -154,6 +199,17 @@ DFScript provides helpers to serialize and parse data formats like JSON and CSV.
|
|
|
154
199
|
// Read Newline Delimited JSON (NDJSON)
|
|
155
200
|
const dfNdjson = $df.read_json('{"id": 1}\n{"id": 2}', { format: "ndjson" });
|
|
156
201
|
```
|
|
202
|
+
- **`$df.read_csv(content, options?)`**: Reads a CSV string and loads it into a new DataFrame, with automatic data type inference.
|
|
203
|
+
```typescript
|
|
204
|
+
import { $df } from "df-script";
|
|
205
|
+
|
|
206
|
+
const csvContent = "id,name,active\n1,Alice,true\n2,Bob,false";
|
|
207
|
+
const df = $df.read_csv(csvContent, {
|
|
208
|
+
separator: ",",
|
|
209
|
+
hasHeader: true,
|
|
210
|
+
inferSchema: true
|
|
211
|
+
});
|
|
212
|
+
```
|
|
157
213
|
|
|
158
214
|
### Writing Data
|
|
159
215
|
- **`df.write_json(file?, options?)`**: Serializes a DataFrame into a JSON or NDJSON string. If a file path or writable stream/object (with a `.write` method) is provided, writes/streams the content as a side-effect. Always returns the serialized string.
|
|
@@ -197,6 +253,23 @@ Chained mathematical functions execute cleanly with built-in null-safety (Kleene
|
|
|
197
253
|
- `.first()`, `.last()`
|
|
198
254
|
- `.any()`, `.all()`, `.any_null()`, `.all_null()`, `.n_unique()`
|
|
199
255
|
|
|
256
|
+
### 🔀 Control Flow & Conditionals
|
|
257
|
+
Construct dynamic `CASE WHEN` branches using the `$df.when` API:
|
|
258
|
+
```typescript
|
|
259
|
+
import { $df } from "df-script";
|
|
260
|
+
|
|
261
|
+
df.select(
|
|
262
|
+
$df.col("sales"),
|
|
263
|
+
$df.when($df.col("sales").gt(2000)).then("High Performance")
|
|
264
|
+
.when($df.col("sales").gt(1000)).then("Standard Performance")
|
|
265
|
+
.otherwise("Low Performance")
|
|
266
|
+
.alias("sales_category")
|
|
267
|
+
);
|
|
268
|
+
```
|
|
269
|
+
- `$df.when(predicate).then(value)`: Starts a conditional evaluation.
|
|
270
|
+
- `.when(predicate).then(value)`: Chains additional conditions.
|
|
271
|
+
- `.otherwise(value)`: Specifies the fallback value when no conditions match (returns a complete `ColumnExpr`).
|
|
272
|
+
|
|
200
273
|
---
|
|
201
274
|
|
|
202
275
|
## 📂 Namespaces
|
|
@@ -222,13 +295,36 @@ $df.col("duration").dt.total_seconds()
|
|
|
222
295
|
- **Datetime Methods**: `year()`, `month()`, `day()`, `hour()`, `minute()`, `second()`, `millisecond()`, `microsecond()`, `nanosecond()`, `weekday()`, `week()`, `quarter()`, `century()`, `millennium()`, `ordinal_day()`, `is_leap_year()`, `month_start()`, `month_end()`, `date()`, `time()`, `datetime()`, `epoch(unit)`, `timestamp(unit)`, `strftime(format, locale?)`.
|
|
223
296
|
- **Duration Methods**: `total_days()`, `total_hours()`, `total_minutes()`, `total_seconds()`, `total_milliseconds()`, `total_microseconds()`, `total_nanoseconds()`.
|
|
224
297
|
|
|
225
|
-
### 📊 List Operations (`.
|
|
226
|
-
Available on
|
|
298
|
+
### 📊 Array/List Operations (`.arr`)
|
|
299
|
+
Available on any array or list column expression via `.arr`:
|
|
300
|
+
```typescript
|
|
301
|
+
$df.col("tags").arr.contains("vip")
|
|
302
|
+
$df.col("matrix").arr.get(2)
|
|
303
|
+
|
|
304
|
+
// Element-wise manipulation inside arrays:
|
|
305
|
+
$df.col("numbers").arr.eval(element().mul(2)).alias("numbers_doubled")
|
|
306
|
+
$df.col("tags").arr.eval(element().str.to_uppercase()).alias("upper_tags")
|
|
307
|
+
```
|
|
308
|
+
- **Methods**: `lengths()`, `len()`, `get(idx, null_on_oob?)`, `first(null_on_oob?)`, `last(null_on_oob?)`, `gather(indices, null_on_oob?)`, `gather_every(n, offset?)`, `slice(offset, length?)`, `contains(item)`, `count_matches(item)`, `join(separator)`, `sort(descending?)`, `reverse()`, `unique()`, `sum()`, `mean()`, `median()`, `mode()`, `min()`, `max()`, `eval(expr)`.
|
|
309
|
+
|
|
310
|
+
### 🗃️ Struct/Object Operations (`.struct`)
|
|
311
|
+
Available on any struct or nested object column expression via `.struct`. You can access fields dynamically via properties or explicit methods:
|
|
227
312
|
```typescript
|
|
228
|
-
|
|
229
|
-
$df.col("
|
|
313
|
+
// Sibling fields access via Proxy
|
|
314
|
+
$df.col("address").struct.city.alias("city")
|
|
315
|
+
|
|
316
|
+
// Or using the explicit field method
|
|
317
|
+
$df.col("address").struct.field("city")
|
|
230
318
|
```
|
|
231
|
-
- **Methods**:
|
|
319
|
+
- **Methods**:
|
|
320
|
+
- `field(name)`: Accesses a field within the struct.
|
|
321
|
+
- `rename_fields(mapping)`: Renames fields in the struct based on a `{ oldKey: newKey }` mapping.
|
|
322
|
+
- `with_fields(fields)`: Adds or overrides fields in the struct. Accepts an array of aliased expressions or an object.
|
|
323
|
+
- `unnest()`: Expands the fields of the struct into individual top-level columns in a select projection.
|
|
324
|
+
```typescript
|
|
325
|
+
// Flattens the address struct into "city", "state", etc. at the top-level
|
|
326
|
+
df.select($df.col("address").struct.unnest())
|
|
327
|
+
```
|
|
232
328
|
|
|
233
329
|
---
|
|
234
330
|
|
|
@@ -291,6 +387,26 @@ const schema = {
|
|
|
291
387
|
const df = $df.data(rawData, schema);
|
|
292
388
|
```
|
|
293
389
|
|
|
390
|
+
### 🧠 TypeScript Type Inference & IDE Safety
|
|
391
|
+
|
|
392
|
+
When you pass a schema to `$df.data()`, DFScript's types automatically infer the target types of the fields, turning dynamic dataframes into compile-safe records. Your IDE will auto-complete column names and validate that operations match the underlying types.
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
import { $df } from "df-script";
|
|
396
|
+
|
|
397
|
+
const schema = {
|
|
398
|
+
name: $df.DataType.Utf8,
|
|
399
|
+
age: $df.DataType.Int32,
|
|
400
|
+
is_active: $df.DataType.Boolean
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// Inferred DataFrame type is DataFrame<{ name: string; age: number; is_active: boolean }>
|
|
404
|
+
const df = $df.data(rawData, schema);
|
|
405
|
+
|
|
406
|
+
// Full IDE autocomplete, type validation, and compiler safety!
|
|
407
|
+
const activeUsers = df.filter($df.col("is_active").eq(true));
|
|
408
|
+
```
|
|
409
|
+
|
|
294
410
|
### Supported Data Types
|
|
295
411
|
- **Integers**: `Int8`, `Int16`, `Int32`, `Int64`, `UInt8`, `UInt16`, `UInt32`, `UInt64`
|
|
296
412
|
- **Floats & Decimals**: `Float32`, `Float64`, `Decimal(precision?, scale?)`
|
package/dist/api.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare const $df: {
|
|
|
40
40
|
Duration: import("./datatypes").DurationType;
|
|
41
41
|
Object: import("./datatypes").ObjectType;
|
|
42
42
|
Null: import("./datatypes").NullType;
|
|
43
|
-
|
|
43
|
+
Array: <TInner>(inner: import("./datatypes").RegisteredDataType & DataType<TInner>) => import("./datatypes").ArrayType<TInner>;
|
|
44
44
|
Struct: <TFields extends RowRecord>(fields: { [K in keyof TFields]: import("./datatypes").RegisteredDataType & DataType<TFields[K]>; }) => import("./datatypes").StructType<TFields>;
|
|
45
45
|
};
|
|
46
46
|
};
|
|
@@ -6,7 +6,7 @@ import { WindowExpr } from "./mixins/WindowExpr";
|
|
|
6
6
|
import { StringExpr } from "./mixins/StringExpr";
|
|
7
7
|
import { LogicalExpr } from "./mixins/LogicalExpr";
|
|
8
8
|
import { TemporalExpr } from "./mixins/TemporalExpr";
|
|
9
|
-
import {
|
|
9
|
+
import { ArrayExpr } from "./mixins/ArrayExpr";
|
|
10
10
|
import { StructExpr } from "./mixins/StructExpr";
|
|
11
11
|
import { ManipulationExpr } from "./mixins/ManipulationExpr";
|
|
12
12
|
import { DataType } from "../datatypes";
|
|
@@ -21,7 +21,7 @@ export declare class ColumnExpr<T> extends ExprBase {
|
|
|
21
21
|
static toColExpr(col: IntoExpr | IntoExpr[]): ColumnExpr<any>;
|
|
22
22
|
constructor(colName: keyof T | string | (keyof T | string)[] | DataType | Function | (DataType | Function)[]);
|
|
23
23
|
}
|
|
24
|
-
export interface ColumnExpr<T> extends ArithmeticExpr, ComparisonExpr, AggregationExpr, WindowExpr, StringExpr, LogicalExpr, TemporalExpr,
|
|
24
|
+
export interface ColumnExpr<T> extends ArithmeticExpr, ComparisonExpr, AggregationExpr, WindowExpr, StringExpr, LogicalExpr, TemporalExpr, ArrayExpr, StructExpr, ManipulationExpr {
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Resolves column selectors, expanding wildcards, datatypes, and arrays of columns/types
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ColumnExpr } from "../ColumnExpr";
|
|
2
|
-
import type { IExpr,
|
|
3
|
-
export declare function coalesce(...exprs: (IExpr |
|
|
2
|
+
import type { IExpr, ValidScalarTypes } from "../../types";
|
|
3
|
+
export declare function coalesce(...exprs: (IExpr | ValidScalarTypes | (IExpr | ValidScalarTypes)[])[]): ColumnExpr<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColumnExpr } from "../ColumnExpr";
|
|
2
2
|
/**
|
|
3
|
-
* Creates an expression referencing the current element(s) of
|
|
3
|
+
* Creates an expression referencing the current element(s) of an array during evaluation.
|
|
4
4
|
*/
|
|
5
5
|
export declare function element<T = any>(): ColumnExpr<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ColumnExpr } from "../ColumnExpr";
|
|
2
|
-
import type { IExpr,
|
|
3
|
-
type WhenArg = IExpr |
|
|
2
|
+
import type { IExpr, ValidScalarTypes } from "../../types";
|
|
3
|
+
type WhenArg = IExpr | ValidScalarTypes;
|
|
4
4
|
export declare class WhenThenChain {
|
|
5
5
|
private predicates;
|
|
6
6
|
private values;
|
|
@@ -8,7 +8,7 @@ export * from "./mixins/StringExpr";
|
|
|
8
8
|
export * from "./mixins/AggregationExpr";
|
|
9
9
|
export * from "./mixins/WindowExpr";
|
|
10
10
|
export * from "./mixins/TemporalExpr";
|
|
11
|
-
export * from "./mixins/
|
|
11
|
+
export * from "./mixins/ArrayExpr";
|
|
12
12
|
export * from "./mixins/StructExpr";
|
|
13
13
|
export * from "./ColumnExpr";
|
|
14
14
|
export * from "./functions/lit";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AggFn,
|
|
1
|
+
import type { AggFn, UniqueArrayStatsOptions } from "../../types";
|
|
2
2
|
import { ExprBase } from "../ExprBase";
|
|
3
3
|
export declare class AggregationExpr extends ExprBase {
|
|
4
4
|
_deriveAgg(fn: AggFn<any>): this;
|
|
@@ -18,7 +18,7 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
18
18
|
median(): this;
|
|
19
19
|
min(): this;
|
|
20
20
|
mode(): this;
|
|
21
|
-
n_unique(options?:
|
|
21
|
+
n_unique(options?: UniqueArrayStatsOptions): this;
|
|
22
22
|
quantile(q: number): this;
|
|
23
23
|
std(): this;
|
|
24
24
|
sum(): this;
|
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { RandomOptions } from "../types";
|
|
1
|
+
import type { RandomOptions, NumericArg } from "../types";
|
|
3
2
|
import { ExprBase } from "../ExprBase";
|
|
4
3
|
export declare class ArithmeticExpr extends ExprBase {
|
|
5
4
|
abs(): this;
|
|
6
5
|
acos(): this;
|
|
7
6
|
acosh(): this;
|
|
8
|
-
add(val:
|
|
7
|
+
add(val: NumericArg): this;
|
|
9
8
|
asin(): this;
|
|
10
9
|
asinh(): this;
|
|
11
10
|
atan(): this;
|
|
11
|
+
atan2(val: NumericArg): this;
|
|
12
12
|
atanh(): this;
|
|
13
13
|
cbrt(): this;
|
|
14
14
|
ceil(): this;
|
|
15
15
|
clip(lower?: number | null, upper?: number | null): this;
|
|
16
|
+
copysign(val: NumericArg): this;
|
|
16
17
|
cos(): this;
|
|
17
18
|
cosh(): this;
|
|
18
19
|
degrees(): this;
|
|
19
|
-
div(val:
|
|
20
|
+
div(val: NumericArg): this;
|
|
20
21
|
exp(): this;
|
|
21
22
|
expm1(): this;
|
|
22
23
|
floor(): this;
|
|
23
|
-
floordiv(val:
|
|
24
|
-
hypot(val:
|
|
24
|
+
floordiv(val: NumericArg): this;
|
|
25
|
+
hypot(val: NumericArg): this;
|
|
25
26
|
log(base?: number): this;
|
|
26
27
|
log1p(): this;
|
|
27
|
-
mod(val:
|
|
28
|
-
mul(val:
|
|
28
|
+
mod(val: NumericArg): this;
|
|
29
|
+
mul(val: NumericArg): this;
|
|
29
30
|
negate(): this;
|
|
30
|
-
pow(val:
|
|
31
|
+
pow(val: NumericArg): this;
|
|
31
32
|
radians(): this;
|
|
32
33
|
rand(seed?: number, { min, max, integer }?: RandomOptions): this;
|
|
33
34
|
round(decimals?: number): this;
|
|
@@ -35,7 +36,7 @@ export declare class ArithmeticExpr extends ExprBase {
|
|
|
35
36
|
sin(): this;
|
|
36
37
|
sinh(): this;
|
|
37
38
|
sqrt(): this;
|
|
38
|
-
sub(val:
|
|
39
|
+
sub(val: NumericArg): this;
|
|
39
40
|
tan(): this;
|
|
40
41
|
tanh(): this;
|
|
41
42
|
trunc(): this;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ExprBase } from "../ExprBase";
|
|
2
|
+
import { SortArrayOptions, StepSliceArrayOptions } from "../../utils";
|
|
3
|
+
import type { UniqueArrayStatsOptions, JoinArrayOptions, ExplodeOptions, IExpr } from "../../types";
|
|
4
|
+
export declare class ArrayExprNamespace {
|
|
5
|
+
expr: any;
|
|
6
|
+
constructor(expr: any);
|
|
7
|
+
_deriveArray(fn: (arr: any[] | ArrayBufferView) => any): any;
|
|
8
|
+
all(): any;
|
|
9
|
+
any(): any;
|
|
10
|
+
contains(item: any): any;
|
|
11
|
+
contains_all(items: ArrayLike<any>): any;
|
|
12
|
+
contains_any(items: ArrayLike<any>): any;
|
|
13
|
+
count_matches(item: any): any;
|
|
14
|
+
drop_nulls(): any;
|
|
15
|
+
explode({ empty_as_null, keep_nulls }?: ExplodeOptions): any;
|
|
16
|
+
first(null_on_oob?: boolean): any;
|
|
17
|
+
gather(indices: number | ArrayLike<number>, null_on_oob?: boolean): any;
|
|
18
|
+
gather_every(options?: StepSliceArrayOptions): any;
|
|
19
|
+
get(index: number, null_on_oob?: boolean): any;
|
|
20
|
+
join(separator?: string, options?: JoinArrayOptions): any;
|
|
21
|
+
last(null_on_oob?: boolean): any;
|
|
22
|
+
len(): any;
|
|
23
|
+
lengths(): any;
|
|
24
|
+
max(): any;
|
|
25
|
+
mean(): any;
|
|
26
|
+
median(): any;
|
|
27
|
+
min(): any;
|
|
28
|
+
mode(): any;
|
|
29
|
+
n_unique(options?: UniqueArrayStatsOptions): any;
|
|
30
|
+
reverse(): any;
|
|
31
|
+
slice(offset: number, length?: number): any;
|
|
32
|
+
sort(options?: SortArrayOptions): any;
|
|
33
|
+
sum(): any;
|
|
34
|
+
unique(options?: UniqueArrayStatsOptions): any;
|
|
35
|
+
eval(expr: IExpr): any;
|
|
36
|
+
}
|
|
37
|
+
export declare class ArrayExpr extends ExprBase {
|
|
38
|
+
get arr(): ArrayExprNamespace;
|
|
39
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExprBase } from "../ExprBase";
|
|
2
|
-
import { StepSliceListOptions } from "../../utils";
|
|
2
|
+
import { SortListOptions, StepSliceListOptions } from "../../utils";
|
|
3
3
|
import type { UniqueListStatsOptions, JoinListOptions, ExplodeOptions, IExpr } from "../../types";
|
|
4
4
|
export declare class ListExprNamespace {
|
|
5
5
|
expr: any;
|
|
@@ -29,7 +29,7 @@ export declare class ListExprNamespace {
|
|
|
29
29
|
n_unique(options?: UniqueListStatsOptions): any;
|
|
30
30
|
reverse(): any;
|
|
31
31
|
slice(offset: number, length?: number): any;
|
|
32
|
-
sort(
|
|
32
|
+
sort(options?: SortListOptions): any;
|
|
33
33
|
sum(): any;
|
|
34
34
|
unique(options?: UniqueListStatsOptions): any;
|
|
35
35
|
eval(expr: IExpr): any;
|
|
@@ -21,8 +21,8 @@ export declare class StringExprNamespace {
|
|
|
21
21
|
lpad(width: number, fill?: string): any;
|
|
22
22
|
pad_end(width: number, fill?: string): any;
|
|
23
23
|
pad_start(width: number, fill?: string): any;
|
|
24
|
-
replace(pattern: string | RegExp, replacement: string): any;
|
|
25
|
-
replace_all(pattern: string | RegExp, replacement: string): any;
|
|
24
|
+
replace(pattern: string | RegExp, replacement: string | ((match: string, ...args: any[]) => string)): any;
|
|
25
|
+
replace_all(pattern: string | RegExp, replacement: string | ((match: string, ...args: any[]) => string)): any;
|
|
26
26
|
reverse(): any;
|
|
27
27
|
rpad(width: number, fill?: string): any;
|
|
28
28
|
slice(offset: number, length?: number): any;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const NEWLINE = "\n";
|
|
2
|
+
export declare const CARRIAGE_RETURN = "\r";
|
|
3
|
+
export declare const UTF8_BOM = "\uFEFF";
|
|
4
|
+
export declare const MS_PER_SECOND = 1000;
|
|
5
|
+
export declare const MS_PER_MINUTE = 60000;
|
|
6
|
+
export declare const MS_PER_HOUR = 3600000;
|
|
7
|
+
export declare const MS_PER_DAY = 86400000;
|
|
8
|
+
export declare const US_PER_MS = 1000;
|
|
9
|
+
export declare const NS_PER_MS = 1000000;
|
|
10
|
+
export declare const US_PER_MS_BI = 1000n;
|
|
11
|
+
export declare const NS_PER_MS_BI = 1000000n;
|
|
@@ -41,7 +41,7 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
41
41
|
tail(n?: number): DataFrame<T>;
|
|
42
42
|
to_dict(): DataFrameColumns<T>;
|
|
43
43
|
to_dicts(): T[];
|
|
44
|
-
|
|
44
|
+
to_array<K extends keyof T>(nameOrExpr: K | IExpr): any[];
|
|
45
45
|
transpose({ include_header: includeHeader, header_name: headerName, column_names: colNamesOpt }?: TransposeOptions): DataFrame<any>;
|
|
46
46
|
unique<K extends keyof T>(columns?: K | K[]): DataFrame<T>;
|
|
47
47
|
unpivot<U extends RowRecord = any>(config: UnpivotOptions<T>): DataFrame<U>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataType as BaseDataType } from "./DataType";
|
|
2
|
-
import { DecimalType } from "./types";
|
|
2
|
+
import { DecimalType, BooleanDataType as Boolean, DateDataType as Date, ObjectDataType as Object, ArrayDataType as Array } from "./types";
|
|
3
3
|
export { BaseDataType as DataType };
|
|
4
4
|
export declare const DataTypeRegistry: {
|
|
5
5
|
Int8: import("./types").Int8Type;
|
|
@@ -22,8 +22,9 @@ export declare const DataTypeRegistry: {
|
|
|
22
22
|
Duration: import("./types").DurationType;
|
|
23
23
|
Object: import("./types").ObjectType;
|
|
24
24
|
Null: import("./types").NullType;
|
|
25
|
-
|
|
25
|
+
Array: <TInner>(inner: import("./types").RegisteredDataType & BaseDataType<TInner>) => import("./types").ArrayType<TInner>;
|
|
26
26
|
Struct: <TFields extends import("..").RowRecord>(fields: { [K in keyof TFields]: import("./types").RegisteredDataType & BaseDataType<TFields[K]>; }) => import("./types").StructType<TFields>;
|
|
27
27
|
};
|
|
28
|
+
export { Boolean, Date, Object, Array };
|
|
28
29
|
export * from "./types";
|
|
29
30
|
export * from "./DataType";
|
|
@@ -86,7 +86,7 @@ export declare class BooleanType extends DataType<boolean | null> {
|
|
|
86
86
|
equals(other: DataType): boolean;
|
|
87
87
|
allocate(size: number): (boolean | null)[];
|
|
88
88
|
}
|
|
89
|
-
export declare const
|
|
89
|
+
export declare const BooleanDataType: BooleanType;
|
|
90
90
|
export declare class Utf8Type extends DataType<string | null> {
|
|
91
91
|
readonly name = "Utf8";
|
|
92
92
|
get isString(): boolean;
|
|
@@ -119,14 +119,14 @@ export declare class ObjectType extends DataType {
|
|
|
119
119
|
equals(other: DataType): boolean;
|
|
120
120
|
allocate(size: number): any[];
|
|
121
121
|
}
|
|
122
|
-
export declare const
|
|
122
|
+
export declare const ObjectDataType: ObjectType;
|
|
123
123
|
export declare class DateType extends TemporalDataType<Date | null> {
|
|
124
124
|
readonly name = "Date";
|
|
125
125
|
coerce(val: unknown): Date | null;
|
|
126
126
|
equals(other: DataType): boolean;
|
|
127
127
|
allocate(size: number): (Date | null)[];
|
|
128
128
|
}
|
|
129
|
-
export declare const
|
|
129
|
+
export declare const DateDataType: DateType;
|
|
130
130
|
export declare class DatetimeType extends TemporalDataType<Date | null> {
|
|
131
131
|
readonly name = "Datetime";
|
|
132
132
|
coerce(val: unknown): Date | null;
|
|
@@ -148,15 +148,15 @@ export declare class DurationType extends TemporalDataType<number | null> {
|
|
|
148
148
|
allocate(size: number): (number | null)[];
|
|
149
149
|
}
|
|
150
150
|
export declare const Duration: DurationType;
|
|
151
|
-
export declare class
|
|
151
|
+
export declare class ArrayType<TInner = any> extends NestedDataType<TInner[] | null> {
|
|
152
152
|
readonly innerType: RegisteredDataType & DataType<TInner>;
|
|
153
|
-
readonly name = "
|
|
153
|
+
readonly name = "Array";
|
|
154
154
|
constructor(innerType: RegisteredDataType & DataType<TInner>);
|
|
155
155
|
coerce(val: unknown): TInner[] | null;
|
|
156
156
|
equals(other: DataType): boolean;
|
|
157
157
|
allocate(size: number): (TInner[] | null)[];
|
|
158
158
|
}
|
|
159
|
-
export declare const
|
|
159
|
+
export declare const ArrayDataType: <TInner>(inner: RegisteredDataType & DataType<TInner>) => ArrayType<TInner>;
|
|
160
160
|
export declare class StructType<TFields extends RowRecord = any> extends NestedDataType<TFields | null> {
|
|
161
161
|
readonly fields: {
|
|
162
162
|
[K in keyof TFields]: RegisteredDataType & DataType<TFields[K]>;
|
|
@@ -170,4 +170,4 @@ export declare class StructType<TFields extends RowRecord = any> extends NestedD
|
|
|
170
170
|
allocate(size: number): (TFields | null)[];
|
|
171
171
|
}
|
|
172
172
|
export declare const Struct: <TFields extends RowRecord>(fields: { [K in keyof TFields]: RegisteredDataType & DataType<TFields[K]>; }) => StructType<TFields>;
|
|
173
|
-
export type RegisteredDataType = Int8Type | Int16Type | Int32Type | Int64Type | UInt8Type | UInt16Type | UInt32Type | UInt64Type | Float32Type | Float64Type | DecimalType | BooleanType | Utf8Type | BinaryType | NullType | ObjectType | DateType | DatetimeType | TimeType | DurationType |
|
|
173
|
+
export type RegisteredDataType = Int8Type | Int16Type | Int32Type | Int64Type | UInt8Type | UInt16Type | UInt32Type | UInt64Type | Float32Type | Float64Type | DecimalType | BooleanType | Utf8Type | BinaryType | NullType | ObjectType | DateType | DatetimeType | TimeType | DurationType | ArrayType<any> | StructType<any>;
|