df-script 1.7.0 β 1.9.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 +51 -12
- package/dist/api.d.ts +2 -1
- package/dist/columnExpressions/ExprBase.d.ts +8 -0
- package/dist/columnExpressions/constants.d.ts +2 -0
- package/dist/columnExpressions/functions/duration.d.ts +33 -0
- package/dist/columnExpressions/functions/when.d.ts +8 -6
- package/dist/columnExpressions/index.d.ts +2 -0
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +203 -1
- package/dist/columnExpressions/mixins/ArrayExpr.d.ts +57 -41
- package/dist/columnExpressions/mixins/StringExpr.d.ts +277 -13
- package/dist/columnExpressions/mixins/StructExpr.d.ts +7 -7
- package/dist/columnExpressions/mixins/TemporalExpr.d.ts +123 -72
- package/dist/columnExpressions/typeInference.d.ts +13 -0
- package/dist/columnExpressions/types.d.ts +1 -1
- package/dist/columnExpressions/utils.d.ts +19 -0
- package/dist/constants.d.ts +44 -3
- package/dist/dataframe/dataframe.d.ts +233 -109
- package/dist/dataframe/types.d.ts +25 -3
- package/dist/dataframe/utils.d.ts +21 -1
- package/dist/datatypes/types.d.ts +8 -3
- package/dist/exceptions/index.d.ts +10 -0
- package/dist/exceptions/utils.d.ts +2 -0
- package/dist/index.js +5 -5
- package/dist/index.mjs +5 -5
- package/dist/types.d.ts +132 -1
- package/dist/utils/array.d.ts +62 -6
- package/dist/utils/binary.d.ts +6 -2
- package/dist/utils/date.d.ts +6 -2
- package/dist/utils/duration.d.ts +5 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/json.d.ts +54 -2
- package/dist/utils/number.d.ts +5 -2
- package/dist/utils/object.d.ts +13 -0
- package/dist/utils/string.d.ts +78 -2
- package/dist/utils/table.d.ts +76 -0
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/trentamorris/df-script)
|
|
4
4
|
[](DONATIONS.md)
|
|
5
|
+
[](#)
|
|
6
|
+
[](#)
|
|
5
7
|
|
|
6
8
|
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.
|
|
7
9
|
|
|
@@ -140,6 +142,8 @@ DFScript uses the `$df` namespace to bootstrap DataFrames, refer to columns, bui
|
|
|
140
142
|
- `$df.exclude(columns)`: Creates an expression matching all columns except the specified ones.
|
|
141
143
|
- `$df.coalesce(...exprs)`: Returns the first non-null value among columns or literal expressions.
|
|
142
144
|
- `$df.lit(val)`: Explicitly wraps a raw value into a literal expression.
|
|
145
|
+
- `$df.duration(options)`: Constructs a `Duration` expression supporting days, hours, minutes, seconds, milliseconds, weeks, and timeUnit precision.
|
|
146
|
+
- `$df.struct(fields)`: Constructs a nested `Struct` object column expression from an object of named expressions or sibling columns.
|
|
143
147
|
- `$df.when(predicate).then(value)...otherwise(value)`: Constructs a conditional expression (when-then-otherwise chain).
|
|
144
148
|
- `$df.implode(column)`: Aggregates a column's rows (or grouped values) into a list.
|
|
145
149
|
- `$df.seq_range(value, options?)`: Generates a sequence range of values.
|
|
@@ -156,28 +160,38 @@ DFScript uses the `$df` namespace to bootstrap DataFrames, refer to columns, bui
|
|
|
156
160
|
## π οΈ DataFrame API Reference
|
|
157
161
|
|
|
158
162
|
### 1. Transformations & Projection
|
|
159
|
-
- **`select(...exprs)`**: Projects columns. Supports strings, raw column names, `$df.col(...)` expressions, and `$df.
|
|
163
|
+
- **`select(...exprs)`**: Projects columns. Supports strings, raw column names, `$df.col(...)` expressions, `$df.all()`, and `$df.col("struct").struct.unnest()`.
|
|
160
164
|
- **`with_columns(...exprs)`**: Adds or overrides columns. Accepts expressions, strings, or options objects mapping keys to values/expressions.
|
|
161
165
|
- **`drop(...names)`**: Drops one or more columns from the DataFrame.
|
|
162
166
|
- **`rename(mapping)`**: Renames columns using a `{ oldName: newName }` object.
|
|
167
|
+
- **`explode(columns)`**: Unnests list-like columns into multiple rows, replicating other columns per list element.
|
|
168
|
+
- **`implode(columns)`**: Groups values in specified columns back into a single list element per column.
|
|
163
169
|
|
|
164
170
|
### 2. Filtering & Row Selection
|
|
165
171
|
- **`filter(...predicates)`**: Filters rows where all predicate expressions evaluate to `true` (or non-null truthy values).
|
|
172
|
+
- **`find(predicate)`**: Evaluates a predicate expression and returns the first matching row record object (or `undefined` if no match is found).
|
|
166
173
|
- **`unique(columns?)`**: Returns unique rows. If a subset of columns is provided, deduplicates based on those columns.
|
|
167
174
|
- **`limit(n, options?)`**: Returns the first `n` rows. Options include `offset` and direction `from: "start" | "end"`.
|
|
168
175
|
- **`head(n)`** / **`tail(n)`**: Shortcuts for `limit` from the start or end of the DataFrame.
|
|
169
176
|
- **`slice(start, end?)`**: Extract a subset of rows using standard index slicing.
|
|
170
|
-
- **`gather(indices, options?)`**: Gathers rows at specified indices. Supports single index, arrays of indices, and negative indexing. Options include `{ null_on_oob?: boolean }
|
|
177
|
+
- **`gather(indices, options?)`**: Gathers rows at specified indices. Supports single index, arrays of indices, and negative indexing. Options include `{ null_on_oob?: boolean }`.
|
|
171
178
|
|
|
172
|
-
### 3. Sorting
|
|
179
|
+
### 3. Sorting & Structural Operations
|
|
173
180
|
- **`sort({ by, descending?, nullsLast?, custom? })`**: Sorts rows. Supports single or multiple columns/expressions, custom descending configurations per column, custom null sorting rules, and custom comparator functions.
|
|
181
|
+
- **`clone()`**: Performs a complete deep copy of the `DataFrame`, replicating all underlying column arrays and schema metadata.
|
|
174
182
|
|
|
175
183
|
### 4. Grouping & Aggregations
|
|
176
184
|
- **`groupby(keys)`**: Groups the data by one or more columns, returning a `GroupedData` object.
|
|
177
185
|
- **`GroupedData.agg(...exprs)`**: Run aggregations on grouped data (e.g. `$df.col("sales").sum()`).
|
|
178
186
|
|
|
179
187
|
### 5. Reshaping & Joining
|
|
180
|
-
- **`join(other,
|
|
188
|
+
- **`join(other, onOrOptions, how?, suffixes?)`**: Merges two DataFrames. Supports:
|
|
189
|
+
- Join modes (`how`): `"inner" | "left" | "right" | "outer" | "semi" | "anti" | "cross"`.
|
|
190
|
+
- Heterogeneous key names (`leftOn`, `rightOn`).
|
|
191
|
+
- Key coalescing (`coalesce: boolean`).
|
|
192
|
+
- Row order preservation (`maintain_order: "none" | "left" | "right" | "left_right" | "right_left"`).
|
|
193
|
+
- **`join_asof(other, options)`**: Performs inexact time-series or nearest-neighbor joins on sorted key columns.
|
|
194
|
+
- Parameters: `on`, `leftOn`, `rightOn`, grouping parameters (`by`, `leftBy`, `rightBy`), matching `strategy` (`"backward" | "forward" | "nearest"`), numeric/duration `tolerance`, and `allow_exact_matches`.
|
|
181
195
|
- **`pivot(index, columns, values)`**: Pivots the table, converting unique values in `columns` into column headers.
|
|
182
196
|
- **`unpivot(idVars, valueVars, varName?, valueName?)`**: Melts/unpivots the table, converting wide columns into long format name-value pairs.
|
|
183
197
|
- **`concat(items, options?)`**: Concatenates multiple DataFrames. Supported concat strategies: `"vertical" | "horizontal" | "diagonal"`.
|
|
@@ -248,10 +262,13 @@ Chained mathematical functions execute cleanly with built-in null-safety (Kleene
|
|
|
248
262
|
- `.is_in(arrayOrExpr)`, `.not_in(arrayOrExpr)`
|
|
249
263
|
|
|
250
264
|
### β‘ Aggregations
|
|
251
|
-
- `.sum()`, `.avg()` / `.mean()`, `.median()`, `.mode()`, `.std()`, `.
|
|
265
|
+
- `.sum()`, `.product()`, `.avg()` / `.mean()`, `.median()`, `.mode()`, `.variance()`, `.std()`, `.skew()`, `.kurtosis()`, `.entropy(base?, normalize?)`
|
|
266
|
+
- `.min()`, `.max()`, `.nan_min()`, `.nan_max()`, `.min_by(by)`, `.max_by(by)`, `.arg_min()`, `.arg_max()`
|
|
252
267
|
- `.count(options?)` β Option `{ includeNulls: boolean }`.
|
|
253
268
|
- `.first()`, `.last()`
|
|
254
|
-
- `.any()`, `.all()`, `.any_null()`, `.all_null()`, `.n_unique()`
|
|
269
|
+
- `.any()`, `.all()`, `.any_null()`, `.all_null()`, `.n_unique()`, `.null_count()`
|
|
270
|
+
- `.bitwise_and()`, `.bitwise_or()`, `.bitwise_xor()`
|
|
271
|
+
|
|
255
272
|
|
|
256
273
|
### π Control Flow & Conditionals
|
|
257
274
|
Construct dynamic `CASE WHEN` branches using the `$df.when` API:
|
|
@@ -269,6 +286,7 @@ df.select(
|
|
|
269
286
|
- `$df.when(predicate).then(value)`: Starts a conditional evaluation.
|
|
270
287
|
- `.when(predicate).then(value)`: Chains additional conditions.
|
|
271
288
|
- `.otherwise(value)`: Specifies the fallback value when no conditions match (returns a complete `ColumnExpr`).
|
|
289
|
+
- `$df.coalesce(...exprs)`: Returns the first non-null value among the provided expressions or literals.
|
|
272
290
|
|
|
273
291
|
---
|
|
274
292
|
|
|
@@ -283,16 +301,16 @@ $df.col("name").str.lower()
|
|
|
283
301
|
$df.col("code").str.starts_with("A")
|
|
284
302
|
$df.col("description").str.replace(/foo/i, "bar")
|
|
285
303
|
```
|
|
286
|
-
- **Methods**: `lower()`, `upper()`, `len()`, `len_bytes()`, `len_chars()`, `trim()`, `trim_start()`, `trim_end()`, `starts_with(prefix)`, `ends_with(suffix)`, `contains(pattern)`, `replace(pattern, repl)`, `replace_all(pattern, repl)`, `slice(offset, length?)`, `split(delimiter)`, `explode()`, `reverse()`, `lpad(w, f)`, `rpad(w, f)`, `zfill(w)`, `strip_chars(chars?)`, `strip_chars_start(chars?)`, `strip_chars_end(chars?)`, `strip_prefix(pfx)`, `strip_suffix(sfx)`, `
|
|
304
|
+
- **Methods**: `lower()`, `upper()`, `to_titlecase()`, `len()`, `len_bytes()`, `len_chars()`, `trim()`, `trim_start()`, `trim_end()`, `starts_with(prefix)`, `ends_with(suffix)`, `contains(pattern)`, `contains_any(patterns)`, `count_matches(pattern)`, `find(pattern)`, `find_many(patterns)`, `replace(pattern, repl)`, `replace_all(pattern, repl)`, `replace_many(patterns, replacements)`, `slice(offset, length?)`, `split(delimiter, options?)`, `explode()`, `reverse()`, `lpad(w, f)`, `rpad(w, f)`, `zfill(w)`, `strip_chars(chars?)`, `strip_chars_start(chars?)`, `strip_chars_end(chars?)`, `strip_prefix(pfx)`, `strip_suffix(sfx)`, `escape_regex()`, `extract(pattern, groupIndex?)`, `extract_all(pattern)`, `extract_groups(pattern)`, `extract_many(patterns)`, `encode(encoding)`, `decode(encoding, strict?)`, `json_decode(options?)`, `json_path_match(jsonPath)`, `normalize(form?)`, `join(separator)`, `strptime(format, strict?)`, `to_integer()`, `to_decimal(p, s)`, `to_date()`, `to_datetime()`, `to_time()`.
|
|
287
305
|
|
|
288
306
|
### π
Temporal Operations (`.dt`)
|
|
289
307
|
Available on datetime or duration values via `.dt`:
|
|
290
308
|
```typescript
|
|
291
309
|
$df.col("timestamp").dt.year()
|
|
292
|
-
$df.col("timestamp").dt.
|
|
310
|
+
$df.col("timestamp").dt.convert_time_zone("America/New_York")
|
|
293
311
|
$df.col("duration").dt.total_seconds()
|
|
294
312
|
```
|
|
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()`, `offset_day(n, options?)`, `offset_business_day(n, options?)`, `utc_offset(timeZone?, options?)`, `epoch(unit)`, `timestamp(unit)`, `strftime(format, locale?)`.
|
|
313
|
+
- **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()`, `offset_day(n, options?)`, `offset_business_day(n, options?)`, `convert_time_zone(tz)`, `cast_time_unit(unit)`, `with_time_unit(unit)`, `replace(options)`, `truncate(every)`, `utc_offset(timeZone?, options?)`, `epoch(unit)`, `timestamp(unit)`, `strftime(format, locale?)`.
|
|
296
314
|
- **Duration Methods**: `total_days()`, `total_hours()`, `total_minutes()`, `total_seconds()`, `total_milliseconds()`, `total_microseconds()`, `total_nanoseconds()`.
|
|
297
315
|
|
|
298
316
|
### π Array/List Operations (`.arr`)
|
|
@@ -305,7 +323,7 @@ $df.col("matrix").arr.get(2)
|
|
|
305
323
|
$df.col("numbers").arr.eval(element().mul(2)).alias("numbers_doubled")
|
|
306
324
|
$df.col("tags").arr.eval(element().str.to_uppercase()).alias("upper_tags")
|
|
307
325
|
```
|
|
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)`.
|
|
326
|
+
- **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()`, `arg_min()`, `arg_max()`, `agg(expr)`, `eval(expr)`.
|
|
309
327
|
|
|
310
328
|
### ποΈ Struct/Object Operations (`.struct`)
|
|
311
329
|
Available on any struct or nested object column expression via `.struct`. You can access fields dynamically via properties or explicit methods:
|
|
@@ -313,8 +331,8 @@ Available on any struct or nested object column expression via `.struct`. You ca
|
|
|
313
331
|
// Sibling fields access via Proxy
|
|
314
332
|
$df.col("address").struct.city.alias("city")
|
|
315
333
|
|
|
316
|
-
//
|
|
317
|
-
$df.col("
|
|
334
|
+
// Explicit struct field access or struct creation
|
|
335
|
+
$df.struct({ city: $df.col("city"), state: $df.col("state") })
|
|
318
336
|
```
|
|
319
337
|
- **Methods**:
|
|
320
338
|
- `field(name)`: Accesses a field within the struct.
|
|
@@ -407,6 +425,27 @@ const df = $df.data(rawData, schema);
|
|
|
407
425
|
const activeUsers = df.filter($df.col("is_active").eq(true));
|
|
408
426
|
```
|
|
409
427
|
|
|
428
|
+
### β‘ Post-Operation Schema Type Deduction
|
|
429
|
+
|
|
430
|
+
DFScript features an intelligent post-operation schema inference engine that automatically determines the correct resulting `DataType` across complex expression trees without requiring manual `.cast()` calls:
|
|
431
|
+
|
|
432
|
+
- **Temporal & Duration Arithmetic**:
|
|
433
|
+
- `Datetime - Datetime => Duration`
|
|
434
|
+
- `Datetime Β± Duration => Datetime`
|
|
435
|
+
- `Time - Time => Duration`
|
|
436
|
+
- `Time Β± Duration => Time`
|
|
437
|
+
- `Duration * / Numeric => Duration`
|
|
438
|
+
- **Integer Promotion & Signedness Hierarchy**: Automatically preserves or promotes integer widths:
|
|
439
|
+
- Preserves exact unsigned/signed types (`UInt8 + UInt8 => UInt8`, `Int16 + Int16 => Int16`).
|
|
440
|
+
- Correctly promotes across sizes and signedness (`UInt16 + Int8 => Int16`, `UInt32 + Int32 => Int32`, `Int32 + Int64 => Int64`).
|
|
441
|
+
- **Floating-Point & Decimal Resolution**:
|
|
442
|
+
- `Int + Float => Float64`
|
|
443
|
+
- `Float32 + Float32 => Float32`
|
|
444
|
+
- `Decimal + Int => Decimal`
|
|
445
|
+
- Evaluates non-integer operation results (e.g. division `10 / 3`) and promotes to `Float64`.
|
|
446
|
+
- **Conditional Branch Widening**: Multi-branch expressions (`when().then().otherwise()`) progressively widen branch types to their common denominator.
|
|
447
|
+
- **Statistical Aggregations**: `.mean()` and `.std()` promote integer columns to `Float64`, while non-numeric `.count()` operations resolve to `Int32`.
|
|
448
|
+
|
|
410
449
|
### Supported Data Types
|
|
411
450
|
- **Integers**: `Int8`, `Int16`, `Int32`, `Int64`, `UInt8`, `UInt16`, `UInt32`, `UInt64`
|
|
412
451
|
- **Floats & Decimals**: `Float32`, `Float64`, `Decimal(precision?, scale?)`
|
package/dist/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataFrame } from "./dataframe";
|
|
2
|
-
import { ColumnExpr, lit, all, exclude, coalesce, when, implode, seq_range, element, struct } from "./columnExpressions";
|
|
2
|
+
import { ColumnExpr, lit, all, exclude, coalesce, when, implode, seq_range, element, struct, duration } from "./columnExpressions";
|
|
3
3
|
import { DataType } from "./datatypes";
|
|
4
4
|
import { concat, read_json, read_csv } from "./functions";
|
|
5
5
|
import type { RowRecord, DataFrameSchema, ColumnDict, InferSchema } from "./types";
|
|
@@ -20,6 +20,7 @@ export declare const $df: {
|
|
|
20
20
|
seq_range: typeof seq_range;
|
|
21
21
|
element: typeof element;
|
|
22
22
|
struct: typeof struct;
|
|
23
|
+
duration: typeof duration;
|
|
23
24
|
DataType: {
|
|
24
25
|
Int8: import("./datatypes").Int8Type;
|
|
25
26
|
Int16: import("./datatypes").Int16Type;
|
|
@@ -11,10 +11,18 @@ export declare class ExprBase implements IExpr {
|
|
|
11
11
|
_isLiteral?: boolean;
|
|
12
12
|
_literalValue?: any;
|
|
13
13
|
_aggFn?: AggFn<any> | null;
|
|
14
|
+
_castType?: RegisteredDataType;
|
|
15
|
+
_binaryMeta?: {
|
|
16
|
+
left: any;
|
|
17
|
+
right: any;
|
|
18
|
+
};
|
|
14
19
|
_groupingOpsIndex?: number;
|
|
15
20
|
_partitionOpsIndex?: number;
|
|
16
21
|
_partitionBy: (string | IExpr)[] | null;
|
|
17
22
|
_evaluateWindow?: (groupPreValues: any[], partitionIndices: number[], currentIndex: number) => any;
|
|
23
|
+
_baseExpr?: IExpr;
|
|
24
|
+
_fieldName?: string;
|
|
25
|
+
_isUnnest?: boolean;
|
|
18
26
|
_evaluatePost(opsIndex: number | undefined, aggregatedArray: any[], columns: ColumnDict): ColumnData;
|
|
19
27
|
_evaluatePre(opsIndex: number | undefined, columns: ColumnDict, height: number): ColumnData;
|
|
20
28
|
_getInitialValue(columns: ColumnDict, height: number): ColumnData;
|
|
@@ -3,3 +3,5 @@ export declare const LITERAL_MARKER = "*literal*";
|
|
|
3
3
|
export declare const COALESCE_MARKER = "*coalesce*";
|
|
4
4
|
export declare const ELEMENT_MARKER = "*element*";
|
|
5
5
|
export declare const STRUCT_MARKER = "*struct*";
|
|
6
|
+
export declare const DURATION_MARKER = "*duration*";
|
|
7
|
+
export declare const WHEN_MARKER = "*when*";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ColumnExpr } from "../ColumnExpr";
|
|
2
|
+
import type { IntoExpr, DatetimeTimeUnit } from "../../types";
|
|
3
|
+
export interface DurationOptions {
|
|
4
|
+
weeks?: IntoExpr | number;
|
|
5
|
+
days?: IntoExpr | number;
|
|
6
|
+
hours?: IntoExpr | number;
|
|
7
|
+
minutes?: IntoExpr | number;
|
|
8
|
+
seconds?: IntoExpr | number;
|
|
9
|
+
milliseconds?: IntoExpr | number;
|
|
10
|
+
microseconds?: IntoExpr | number;
|
|
11
|
+
nanoseconds?: IntoExpr | number;
|
|
12
|
+
timeUnit?: DatetimeTimeUnit;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Constructs a Duration expression column from numeric values, column references, or expressions.
|
|
16
|
+
*
|
|
17
|
+
* @param {DurationOptions} [options] Duration component options (weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, timeUnit).
|
|
18
|
+
* @returns {ColumnExpr<any>} A column expression with the calculated duration values.
|
|
19
|
+
* @namespace $df
|
|
20
|
+
* @category ColumnExpression
|
|
21
|
+
* @syntax $df.duration(options)
|
|
22
|
+
* @example
|
|
23
|
+
* >>> const df = $df.data({ dt: ["2026-01-01"], add: [1, 2] })
|
|
24
|
+
* >>> df.select($df.col("dt").cast($df.DataType.Datetime).add($df.duration({ days: "add" })).alias("add_days"))
|
|
25
|
+
* shape: (2, 1)
|
|
26
|
+
* ββββββββββββββββββββββββββββ
|
|
27
|
+
* β add_days β
|
|
28
|
+
* ββββββββββββββββββββββββββββ€
|
|
29
|
+
* β 2026-01-02T00:00:00.000Z β
|
|
30
|
+
* β 2026-01-03T00:00:00.000Z β
|
|
31
|
+
* ββββββββββββββββββββββββββββ
|
|
32
|
+
*/
|
|
33
|
+
export declare function duration(options?: DurationOptions): ColumnExpr<any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ColumnExpr } from "../ColumnExpr";
|
|
2
2
|
import type { IExpr, ValidScalarTypes } from "../../types";
|
|
3
|
-
type WhenArg = IExpr | ValidScalarTypes;
|
|
3
|
+
type WhenArg = IExpr | ValidScalarTypes | any[];
|
|
4
4
|
export declare class WhenThenChain {
|
|
5
5
|
private _predicates;
|
|
6
6
|
private _values;
|
|
@@ -13,12 +13,14 @@ export declare class When {
|
|
|
13
13
|
then(value: WhenArg): WhenThen;
|
|
14
14
|
}
|
|
15
15
|
export declare class WhenThen extends ColumnExpr<any> {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
_predicates: WhenArg[];
|
|
17
|
+
_values: WhenArg[];
|
|
18
|
+
_otherwise: WhenArg;
|
|
19
|
+
get _otherwiseValue(): WhenArg;
|
|
20
|
+
get _branchOperands(): WhenArg[];
|
|
21
|
+
constructor(predicates?: WhenArg[], values?: WhenArg[], otherwise?: WhenArg);
|
|
20
22
|
when(predicate: WhenArg): WhenThenChain;
|
|
21
|
-
otherwise(value: WhenArg):
|
|
23
|
+
otherwise(value: WhenArg): WhenThen;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Provides conditional branch evaluations inside column expressions.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AggFn, UniqueArrayStatsOptions } from "../../types";
|
|
1
|
+
import type { AggFn, UniqueArrayStatsOptions, SkewOptions, KurtosisOptions, EntropyOptions } from "../../types";
|
|
2
2
|
import { ExprBase } from "../ExprBase";
|
|
3
3
|
/**
|
|
4
4
|
* @namespace $df.col
|
|
@@ -66,6 +66,34 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
66
66
|
* βββββββββ΄βββββββββββ
|
|
67
67
|
*/
|
|
68
68
|
any_null(): this;
|
|
69
|
+
/**
|
|
70
|
+
* Aggregation: Finds the index of the maximum value in the group.
|
|
71
|
+
* @returns ColumnExpression
|
|
72
|
+
* @example
|
|
73
|
+
* >>> const df = $df.data({ val: [10, 50, 20] })
|
|
74
|
+
* >>> df.select($df.col("val").arg_max().alias("max_idx"))
|
|
75
|
+
* shape: (1, 1)
|
|
76
|
+
* βββββββββββ
|
|
77
|
+
* β max_idx β
|
|
78
|
+
* βββββββββββ€
|
|
79
|
+
* β 1 β
|
|
80
|
+
* βββββββββββ
|
|
81
|
+
*/
|
|
82
|
+
arg_max(): this;
|
|
83
|
+
/**
|
|
84
|
+
* Aggregation: Finds the index of the minimum value in the group.
|
|
85
|
+
* @returns ColumnExpression
|
|
86
|
+
* @example
|
|
87
|
+
* >>> const df = $df.data({ val: [10, 50, 20] })
|
|
88
|
+
* >>> df.select($df.col("val").arg_min().alias("min_idx"))
|
|
89
|
+
* shape: (1, 1)
|
|
90
|
+
* βββββββββββ
|
|
91
|
+
* β min_idx β
|
|
92
|
+
* βββββββββββ€
|
|
93
|
+
* β 0 β
|
|
94
|
+
* βββββββββββ
|
|
95
|
+
*/
|
|
96
|
+
arg_min(): this;
|
|
69
97
|
/**
|
|
70
98
|
* Aggregation: Computes the arithmetic mean of the group.
|
|
71
99
|
* @returns ColumnExpression
|
|
@@ -80,6 +108,48 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
80
108
|
* βββββββββ΄βββββββ
|
|
81
109
|
*/
|
|
82
110
|
avg(): this;
|
|
111
|
+
/**
|
|
112
|
+
* Aggregation: Computes bitwise AND across all elements in the group.
|
|
113
|
+
* @returns ColumnExpression
|
|
114
|
+
* @example
|
|
115
|
+
* >>> const df = $df.data({ val: [0b11, 0b10] })
|
|
116
|
+
* >>> df.select($df.col("val").bitwise_and().alias("res"))
|
|
117
|
+
* shape: (1, 1)
|
|
118
|
+
* βββββββ
|
|
119
|
+
* β res β
|
|
120
|
+
* βββββββ€
|
|
121
|
+
* β 2 β
|
|
122
|
+
* βββββββ
|
|
123
|
+
*/
|
|
124
|
+
bitwise_and(): this;
|
|
125
|
+
/**
|
|
126
|
+
* Aggregation: Computes bitwise OR across all elements in the group.
|
|
127
|
+
* @returns ColumnExpression
|
|
128
|
+
* @example
|
|
129
|
+
* >>> const df = $df.data({ val: [0b01, 0b10] })
|
|
130
|
+
* >>> df.select($df.col("val").bitwise_or().alias("res"))
|
|
131
|
+
* shape: (1, 1)
|
|
132
|
+
* βββββββ
|
|
133
|
+
* β res β
|
|
134
|
+
* βββββββ€
|
|
135
|
+
* β 3 β
|
|
136
|
+
* βββββββ
|
|
137
|
+
*/
|
|
138
|
+
bitwise_or(): this;
|
|
139
|
+
/**
|
|
140
|
+
* Aggregation: Computes bitwise XOR across all elements in the group.
|
|
141
|
+
* @returns ColumnExpression
|
|
142
|
+
* @example
|
|
143
|
+
* >>> const df = $df.data({ val: [0b11, 0b10] })
|
|
144
|
+
* >>> df.select($df.col("val").bitwise_xor().alias("res"))
|
|
145
|
+
* shape: (1, 1)
|
|
146
|
+
* βββββββ
|
|
147
|
+
* β res β
|
|
148
|
+
* βββββββ€
|
|
149
|
+
* β 1 β
|
|
150
|
+
* βββββββ
|
|
151
|
+
*/
|
|
152
|
+
bitwise_xor(): this;
|
|
83
153
|
/**
|
|
84
154
|
* Aggregation: Computes the Pearson correlation coefficient between two columns.
|
|
85
155
|
* @param other The target column expression to correlate with.
|
|
@@ -142,6 +212,21 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
142
212
|
* βββββββββββββββ
|
|
143
213
|
*/
|
|
144
214
|
dot(other: any): this;
|
|
215
|
+
/**
|
|
216
|
+
* Aggregation: Computes the Shannon entropy of a column or group.
|
|
217
|
+
* @param options Entropy options ({ base?: number, normalize?: boolean }, default base=Math.E, normalize=true).
|
|
218
|
+
* @returns ColumnExpression
|
|
219
|
+
* @example
|
|
220
|
+
* >>> const df = $df.data({ val: ["a", "b", "a", "c"] })
|
|
221
|
+
* >>> df.select($df.col("val").entropy().alias("h"))
|
|
222
|
+
* shape: (1, 1)
|
|
223
|
+
* ββββββββββββ
|
|
224
|
+
* β h β
|
|
225
|
+
* ββββββββββββ€
|
|
226
|
+
* β 1.039721 β
|
|
227
|
+
* ββββββββββββ
|
|
228
|
+
*/
|
|
229
|
+
entropy(options?: EntropyOptions): this;
|
|
145
230
|
/**
|
|
146
231
|
* Aggregation: Finds the first value in the group.
|
|
147
232
|
* @returns ColumnExpression
|
|
@@ -170,6 +255,21 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
170
255
|
* βββββββββ΄βββββββββββ
|
|
171
256
|
*/
|
|
172
257
|
implode(): this;
|
|
258
|
+
/**
|
|
259
|
+
* Aggregation: Computes the kurtosis (peakedness/tailedness) of a numeric column.
|
|
260
|
+
* @param options Kurtosis calculation options ({ fisher?: boolean, bias?: boolean }, default fisher=true, bias=true).
|
|
261
|
+
* @returns ColumnExpression
|
|
262
|
+
* @example
|
|
263
|
+
* >>> const df = $df.data({ val: [1, 2, 3, 4, 5] })
|
|
264
|
+
* >>> df.select($df.col("val").kurtosis().alias("kurt"))
|
|
265
|
+
* shape: (1, 1)
|
|
266
|
+
* βββββββββ
|
|
267
|
+
* β kurt β
|
|
268
|
+
* βββββββββ€
|
|
269
|
+
* β -1.3 β
|
|
270
|
+
* βββββββββ
|
|
271
|
+
*/
|
|
272
|
+
kurtosis(options?: KurtosisOptions): this;
|
|
173
273
|
/**
|
|
174
274
|
* Aggregation: Finds the last value in the group.
|
|
175
275
|
* @returns ColumnExpression
|
|
@@ -198,6 +298,21 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
198
298
|
* βββββββββ΄ββββββββββ
|
|
199
299
|
*/
|
|
200
300
|
max(): this;
|
|
301
|
+
/**
|
|
302
|
+
* Aggregation: Finds the value in this column corresponding to the maximum value in the `by` expression.
|
|
303
|
+
* @param by Column or expression to order by.
|
|
304
|
+
* @returns ColumnExpression
|
|
305
|
+
* @example
|
|
306
|
+
* >>> const df = $df.data({ name: ["a", "b", "c"], score: [10, 50, 20] })
|
|
307
|
+
* >>> df.select($df.col("name").max_by($df.col("score")).alias("top_scorer"))
|
|
308
|
+
* shape: (1, 1)
|
|
309
|
+
* ββββββββββββββ
|
|
310
|
+
* β top_scorer β
|
|
311
|
+
* ββββββββββββββ€
|
|
312
|
+
* β "b" β
|
|
313
|
+
* ββββββββββββββ
|
|
314
|
+
*/
|
|
315
|
+
max_by(by: any): this;
|
|
201
316
|
/**
|
|
202
317
|
* Aggregation: Computes the arithmetic mean of elements in the group.
|
|
203
318
|
* @returns ColumnExpression
|
|
@@ -240,6 +355,21 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
240
355
|
* βββββββββ΄ββββββββββ
|
|
241
356
|
*/
|
|
242
357
|
min(): this;
|
|
358
|
+
/**
|
|
359
|
+
* Aggregation: Finds the value in this column corresponding to the minimum value in the `by` expression.
|
|
360
|
+
* @param by Column or expression to order by.
|
|
361
|
+
* @returns ColumnExpression
|
|
362
|
+
* @example
|
|
363
|
+
* >>> const df = $df.data({ name: ["a", "b", "c"], score: [10, 50, 20] })
|
|
364
|
+
* >>> df.select($df.col("name").min_by($df.col("score")).alias("lowest_scorer"))
|
|
365
|
+
* shape: (1, 1)
|
|
366
|
+
* ββββββββββββββββ
|
|
367
|
+
* β lowest_scorerβ
|
|
368
|
+
* ββββββββββββββββ€
|
|
369
|
+
* β "a" β
|
|
370
|
+
* ββββββββββββββββ
|
|
371
|
+
*/
|
|
372
|
+
min_by(by: any): this;
|
|
243
373
|
/**
|
|
244
374
|
* Aggregation: Finds the statistical mode (most frequent value).
|
|
245
375
|
* @returns ColumnExpression
|
|
@@ -269,6 +399,34 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
269
399
|
* βββββββββ΄βββββββββββββ
|
|
270
400
|
*/
|
|
271
401
|
n_unique(options?: UniqueArrayStatsOptions): this;
|
|
402
|
+
/**
|
|
403
|
+
* Aggregation: Finds the maximum value in the group, taking NaN values into account (NaN propagates).
|
|
404
|
+
* @returns ColumnExpression
|
|
405
|
+
* @example
|
|
406
|
+
* >>> const df = $df.data({ group: ["A", "A"], val: [10, NaN] })
|
|
407
|
+
* >>> df.group_by("group").agg($df.col("val").nan_max().alias("nan_max_val"))
|
|
408
|
+
* shape: (1, 2)
|
|
409
|
+
* βββββββββ¬ββββββββββββββ
|
|
410
|
+
* β group β nan_max_val β
|
|
411
|
+
* βββββββββΌββββββββββββββ€
|
|
412
|
+
* β "A" β NaN β
|
|
413
|
+
* βββββββββ΄ββββββββββββββ
|
|
414
|
+
*/
|
|
415
|
+
nan_max(): this;
|
|
416
|
+
/**
|
|
417
|
+
* Aggregation: Finds the minimum value in the group, taking NaN values into account (NaN propagates).
|
|
418
|
+
* @returns ColumnExpression
|
|
419
|
+
* @example
|
|
420
|
+
* >>> const df = $df.data({ group: ["A", "A"], val: [10, NaN] })
|
|
421
|
+
* >>> df.group_by("group").agg($df.col("val").nan_min().alias("nan_min_val"))
|
|
422
|
+
* shape: (1, 2)
|
|
423
|
+
* βββββββββ¬ββββββββββββββ
|
|
424
|
+
* β group β nan_min_val β
|
|
425
|
+
* βββββββββΌββββββββββββββ€
|
|
426
|
+
* β "A" β NaN β
|
|
427
|
+
* βββββββββ΄ββββββββββββββ
|
|
428
|
+
*/
|
|
429
|
+
nan_min(): this;
|
|
272
430
|
/**
|
|
273
431
|
* Aggregation: Counts the number of null or missing records.
|
|
274
432
|
* @returns ColumnExpression
|
|
@@ -298,8 +456,38 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
298
456
|
* βββββββ
|
|
299
457
|
*/
|
|
300
458
|
quantile(q: number): this;
|
|
459
|
+
/**
|
|
460
|
+
* Aggregation: Computes the product of all elements in the group.
|
|
461
|
+
* @returns ColumnExpression
|
|
462
|
+
* @example
|
|
463
|
+
* >>> const df = $df.data({ group: ["A", "A"], val: [2, 5] })
|
|
464
|
+
* >>> df.group_by("group").agg($df.col("val").product().alias("p"))
|
|
465
|
+
* shape: (1, 2)
|
|
466
|
+
* βββββββββ¬βββββ
|
|
467
|
+
* β group β p β
|
|
468
|
+
* βββββββββΌβββββ€
|
|
469
|
+
* β "A" β 10 β
|
|
470
|
+
* βββββββββ΄βββββ
|
|
471
|
+
*/
|
|
472
|
+
product(): this;
|
|
473
|
+
/**
|
|
474
|
+
* Aggregation: Computes the sample skewness as the Fisher-Pearson coefficient of skewness.
|
|
475
|
+
* @param options Skew calculation options ({ bias?: boolean }, default bias=true).
|
|
476
|
+
* @returns ColumnExpression
|
|
477
|
+
* @example
|
|
478
|
+
* >>> const df = $df.data({ val: [1, 2, 5, 10, 20] })
|
|
479
|
+
* >>> df.select($df.col("val").skew().alias("skewness"))
|
|
480
|
+
* shape: (1, 1)
|
|
481
|
+
* ββββββββββββ
|
|
482
|
+
* β skewness β
|
|
483
|
+
* ββββββββββββ€
|
|
484
|
+
* β 0.859427 β
|
|
485
|
+
* ββββββββββββ
|
|
486
|
+
*/
|
|
487
|
+
skew(options?: SkewOptions): this;
|
|
301
488
|
/**
|
|
302
489
|
* Aggregation: Computes the Spearman rank correlation coefficient.
|
|
490
|
+
|
|
303
491
|
* @param other The other column expression to correlate with.
|
|
304
492
|
* @returns ColumnExpression
|
|
305
493
|
* @example
|
|
@@ -341,6 +529,20 @@ export declare class AggregationExpr extends ExprBase {
|
|
|
341
529
|
* βββββββββ΄ββββββββ
|
|
342
530
|
*/
|
|
343
531
|
sum(): this;
|
|
532
|
+
/**
|
|
533
|
+
* Aggregation: Computes sample variance.
|
|
534
|
+
* @returns ColumnExpression
|
|
535
|
+
* @example
|
|
536
|
+
* >>> const df = $df.data({ group: ["A", "A", "A"], val: [10, 20, 30] })
|
|
537
|
+
* >>> df.group_by("group").agg($df.col("val").variance().alias("v"))
|
|
538
|
+
* shape: (1, 2)
|
|
539
|
+
* βββββββββ¬ββββββ
|
|
540
|
+
* β group β v β
|
|
541
|
+
* βββββββββΌββββββ€
|
|
542
|
+
* β "A" β 100 β
|
|
543
|
+
* βββββββββ΄ββββββ
|
|
544
|
+
*/
|
|
545
|
+
variance(): this;
|
|
344
546
|
/**
|
|
345
547
|
* Aggregation: Computes weighted average.
|
|
346
548
|
* @param weights The weight values or column expression.
|