df-script 1.7.0 → 1.8.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.
@@ -1,6 +1,6 @@
1
1
  import { GroupedData } from "./grouped/grouped";
2
2
  import type { IExpr, ColumnData, ColumnDict, DataFrameColumns, ConcatOptions, ConcatItem, HorizontalConcatOptions, RowRecord, DataFrameSchema, RegisteredDataType, ExplodeOptions, IntoExpr, FillNullOptions } from "../types";
3
- import type { LimitOptions, SortOptions, PivotOptions, JoinOptions, UnpivotOptions, TransposeOptions, WriteJSONOptions, WriteCSVOptions } from "./types";
3
+ import type { LimitOptions, SortOptions, PivotOptions, JoinOptions, AsofJoinOptions, UnpivotOptions, TransposeOptions, WriteJSONOptions, WriteCSVOptions } from "./types";
4
4
  /**
5
5
  * Two-dimensional columnar tabular data structure supporting expression execution and reshaping.
6
6
  */
@@ -50,11 +50,11 @@ export declare class DataFrame<T extends RowRecord = any> {
50
50
  /**
51
51
  * Concatenates items vertically, horizontally, or diagonally.
52
52
  *
53
- * @param items Single DataFrame or array of DataFrames/rows to concatenate.
54
- * @param [options] Configuration options for concatenation layout and strictness.
55
- * @param [options.how] Layout strategy: `"vertical"` (default, appends rows top-to-bottom), `"horizontal"` (joins unique columns side-by-side), or `"diagonal"` (concatenates mismatched columns with null padding).
56
- * @param [options.horizontal.strict] When `true` (default), throws an error if row counts mismatch in horizontal concatenation. Set `false` to pad shorter DataFrames with `null`.
57
- * @returns DataFrame
53
+ * @param {ConcatItem | ConcatItem[]} items Single DataFrame or array of DataFrames/rows to concatenate.
54
+ * @param {ConcatOptions} [options] Configuration options for concatenation layout and strictness.
55
+ * @param {ConcatHow} [options.how] Layout strategy: `"vertical"` (default, appends rows top-to-bottom), `"horizontal"` (joins unique columns side-by-side), or `"diagonal"` (concatenates mismatched columns with null padding).
56
+ * @param {boolean} [options.horizontal.strict] When `true` (default), throws an error if row counts mismatch in horizontal concatenation. Set `false` to pad shorter DataFrames with `null`.
57
+ * @returns {DataFrame}
58
58
  *
59
59
  * @example
60
60
  * // 1. Vertical Concatenation (default):
@@ -105,8 +105,8 @@ export declare class DataFrame<T extends RowRecord = any> {
105
105
  concat<U extends RowRecord = any>(items: ConcatItem | ConcatItem[], options?: ConcatOptions): DataFrame<U>;
106
106
  /**
107
107
  * Drops specified columns from the DataFrame.
108
- * @param args Column names or arrays of column names to remove.
109
- * @returns DataFrame
108
+ * @param {(K | K[])[]} args Column names or arrays of column names to remove.
109
+ * @returns {DataFrame}
110
110
  * @example
111
111
  * >>> const df = $df.data({ a: [1], b: [2] })
112
112
  * >>> df
@@ -127,8 +127,8 @@ export declare class DataFrame<T extends RowRecord = any> {
127
127
  drop<K extends keyof T>(...args: (K | K[])[]): DataFrame<Omit<T, K>>;
128
128
  /**
129
129
  * Drops rows containing null or undefined values in specified subset columns.
130
- * @param subset Column name or array of column names to check for nulls.
131
- * @returns DataFrame
130
+ * @param {string | string[]} [subset] Column name or array of column names to check for nulls.
131
+ * @returns {DataFrame}
132
132
  * @example
133
133
  * >>> const df = $df.data({ a: [1, null, 3] })
134
134
  * >>> df
@@ -168,11 +168,11 @@ export declare class DataFrame<T extends RowRecord = any> {
168
168
  get dtypes(): RegisteredDataType[];
169
169
  /**
170
170
  * Explodes an array column into multiple rows, replicating non-target row attributes.
171
- * @param columns Target column expression or array column name to explode.
172
- * @param [options] Configuration options for empty array and null handling.
173
- * @param [options.empty_as_null] When `true`, converts empty arrays to `null` rows.
174
- * @param [options.keep_nulls] When `true`, retains `null` array values during explosion.
175
- * @returns DataFrame
171
+ * @param {IntoExpr | IntoExpr[]} columns Target column expression or array column name to explode.
172
+ * @param {ExplodeOptions} [options] Configuration options for empty array and null handling.
173
+ * @param {boolean} [options.empty_as_null] When `true`, converts empty arrays to `null` rows.
174
+ * @param {boolean} [options.keep_nulls] When `true`, retains `null` array values during explosion.
175
+ * @returns {DataFrame}
176
176
  * @example
177
177
  * >>> const df = $df.data({ group: ["A"], values: [[1, 2]] })
178
178
  * >>> df
@@ -194,11 +194,11 @@ export declare class DataFrame<T extends RowRecord = any> {
194
194
  explode(columns: IntoExpr | IntoExpr[], options?: ExplodeOptions): DataFrame<any>;
195
195
  /**
196
196
  * Fills null values across columns using scalar values or statistical strategies.
197
- * @param [options] Configuration options for null replacement.
198
- * @param [options.value] Scalar replacement value or dict mapping column names to values.
199
- * @param [options.strategy] Statistical filling strategy (`"zero"`, `"mean"`, `"min"`, `"max"`, `"forward"`, `"backward"`).
200
- * @param [options.limit] Maximum consecutive nulls to fill when using propagation strategies.
201
- * @returns DataFrame
197
+ * @param {FillNullOptions} [options] Configuration options for null replacement.
198
+ * @param {any} [options.value] Scalar replacement value or dict mapping column names to values.
199
+ * @param {FillNullStrategy} [options.strategy] Statistical filling strategy (`"zero"`, `"mean"`, `"min"`, `"max"`, `"forward"`, `"backward"`).
200
+ * @param {number} [options.limit] Maximum consecutive nulls to fill when using propagation strategies.
201
+ * @returns {DataFrame}
202
202
  * @example
203
203
  * >>> const df = $df.data({ a: [1, null, 3] })
204
204
  * >>> df
@@ -223,8 +223,8 @@ export declare class DataFrame<T extends RowRecord = any> {
223
223
  fill_null(options?: FillNullOptions): DataFrame<T>;
224
224
  /**
225
225
  * Filters rows matching boolean column expressions or predicate callbacks.
226
- * @param exprs Expressions or predicate functions evaluated per row.
227
- * @returns DataFrame
226
+ * @param {(IExpr | ((row: T) => any))[]} exprs Expressions or predicate functions evaluated per row.
227
+ * @returns {DataFrame}
228
228
  * @example
229
229
  * >>> const df = $df.data({ a: [1, 2, 3] })
230
230
  * >>> df
@@ -264,8 +264,8 @@ export declare class DataFrame<T extends RowRecord = any> {
264
264
  get_schema(): DataFrameSchema;
265
265
  /**
266
266
  * Groups rows by key columns to prepare for aggregations.
267
- * @param keys Column name or array of key column names.
268
- * @returns GroupedData
267
+ * @param {K | K[]} keys Column name or array of key column names.
268
+ * @returns {GroupedData}
269
269
  * @example
270
270
  * >>> const df = $df.data({ cat: ["A", "A", "B"], val: [10, 20, 30] })
271
271
  * >>> df
@@ -313,6 +313,35 @@ export declare class DataFrame<T extends RowRecord = any> {
313
313
  * └───┘
314
314
  */
315
315
  head(n?: number): DataFrame<T>;
316
+ /**
317
+ * Creates a deep copy of the current DataFrame instance, duplicating all underlying column data arrays and schema metadata.
318
+ * Modifying columns or values in the cloned DataFrame will not mutate the original.
319
+ * @returns {DataFrame<T>}
320
+ * @example
321
+ * >>> // Example 1: Basic cloning and independence
322
+ * >>> const df1 = $df.data({ a: [10, 20], b: ["x", "y"] })
323
+ * >>> const copy1 = df1.clone()
324
+ * >>> copy1
325
+ * shape: (2, 2)
326
+ * ┌────┬───┐
327
+ * │ a │ b │
328
+ * ├────┼───┤
329
+ * │ 10 │ x │
330
+ * │ 20 │ y │
331
+ * └────┴───┘
332
+ *
333
+ * >>> // Example 2: Verifying mutation isolation
334
+ * >>> copy1._columns.a[0] = 999
335
+ * >>> df1.to_dicts()[0].a
336
+ * 10
337
+ *
338
+ * >>> // Example 3: Cloning empty DataFrames
339
+ * >>> const emptyDf = $df.data({ x: [], y: [] })
340
+ * >>> const emptyCopy = emptyDf.clone()
341
+ * >>> emptyCopy.height
342
+ * 0
343
+ */
344
+ clone(): DataFrame<T>;
316
345
  /**
317
346
  * Gets height (total row count) of the DataFrame.
318
347
  * @returns Number of rows.
@@ -333,10 +362,10 @@ export declare class DataFrame<T extends RowRecord = any> {
333
362
  get height(): number;
334
363
  /**
335
364
  * Concatenates columns horizontally to the current DataFrame.
336
- * @param other DataFrame or array of DataFrames to append side-by-side.
337
- * @param [options] Horizontal concat configuration options.
338
- * @param [options.strict] When `true` (default), throws an error if row counts mismatch. Set `false` to allow null padding.
339
- * @returns DataFrame
365
+ * @param {ConcatItem | ConcatItem[]} other DataFrame or array of DataFrames to append side-by-side.
366
+ * @param {HorizontalConcatOptions} [options] Horizontal concat configuration options.
367
+ * @param {boolean} [options.strict] When `true` (default), throws an error if row counts mismatch. Set `false` to allow null padding.
368
+ * @returns {DataFrame}
340
369
  * @example
341
370
  * >>> const df1 = $df.data({ a: [1, 2] })
342
371
  * >>> df1
@@ -360,10 +389,10 @@ export declare class DataFrame<T extends RowRecord = any> {
360
389
  hstack<U extends RowRecord = any>(other: ConcatItem | ConcatItem[], options?: HorizontalConcatOptions): DataFrame<U>;
361
390
  /**
362
391
  * Inserts a new column at a specific ordinal index position.
363
- * @param index Target column index position.
364
- * @param name Name of the inserted column.
365
- * @param expr Value expression or column definition.
366
- * @returns DataFrame
392
+ * @param {number} index Target column index position.
393
+ * @param {string} name Name of the inserted column.
394
+ * @param {IntoExpr} expr Value expression or column definition.
395
+ * @returns {DataFrame}
367
396
  * @example
368
397
  * >>> const df = $df.data({ a: [1], c: [3] })
369
398
  * >>> df
@@ -384,9 +413,9 @@ export declare class DataFrame<T extends RowRecord = any> {
384
413
  insert_column(index: number, name: string, expr: IntoExpr): DataFrame<any>;
385
414
  /**
386
415
  * Retrieves a single scalar cell value by row and column position or name.
387
- * @param row Row index position.
388
- * @param column Column index or column name string.
389
- * @returns Cell scalar value.
416
+ * @param {number} [row] Row index position.
417
+ * @param {number | string} [column] Column index or column name string.
418
+ * @returns {any} Cell scalar value.
390
419
  * @throws {DataFrameError} If shape is not (1, 1) when called without arguments.
391
420
  * @throws {ShapeError} If row or column index is out of bounds.
392
421
  * @example
@@ -443,13 +472,32 @@ export declare class DataFrame<T extends RowRecord = any> {
443
472
  named?: boolean;
444
473
  }): Generator<any[] | Record<string, any>>;
445
474
  /**
446
- * Joins two DataFrames on key columns using inner, left, right, or outer join strategy.
447
- * @param config Join configuration object.
448
- * @param config.other Right DataFrame to join with left DataFrame.
449
- * @param config.on Join key column name or array of key column names.
450
- * @param [config.how] Join strategy (`"inner"`, `"left"`, `"right"`, or `"outer"`). Default `"inner"`.
451
- * @param [config.suffixes] Custom column name suffix tuple `[leftSuffix, rightSuffix]` for overlapping non-key columns (default `["", "_right"]`).
452
- * @returns DataFrame
475
+ * Joins two DataFrames on key columns using a specified join strategy.
476
+ * @param {JoinOptions} config Join configuration object.
477
+ * @param {DataFrame} config.other Right DataFrame to join with.
478
+ * @param {string | string[]} [config.on] Join key column name or array of key column names that exist in both DataFrames.
479
+ * @param {string | string[]} [config.leftOn] Join key column(s) in the left DataFrame when key names differ.
480
+ * @param {string | string[]} [config.rightOn] Join key column(s) in the right DataFrame when key names differ.
481
+ * @param {JoinType} [config.how] Join strategy. Default `"inner"`.
482
+ * - `"inner"` — Only rows with matching keys in both DataFrames.
483
+ * - `"left"` — All left rows; unmatched right values are `null`.
484
+ * - `"right"` — All right rows; unmatched left values are `null`.
485
+ * - `"outer"` — All rows from both sides; unmatched values are `null`.
486
+ * - `"semi"` — Left rows that have a match in the right DataFrame (only left columns retained).
487
+ * - `"anti"` — Left rows that have **no** match in the right DataFrame (only left columns retained).
488
+ * - `"cross"` — Cartesian product pairing every left row with every right row (keyless).
489
+ * @param {[string, string]} [config.suffixes] Suffix tuple `[leftSuffix, rightSuffix]` appended to overlapping
490
+ * non-key column names (default `["", "_right"]`). Ignored for `"semi"` and `"anti"` joins.
491
+ * @param {boolean} [config.join_nulls] If `true`, null key values are treated as equal and will match each other
492
+ * across DataFrames. Default `false` (SQL-standard: `NULL != NULL`).
493
+ * @param {boolean} [config.coalesce] Coalescing behavior for join key columns. Default `true`. If `true`, coalesces join key values into left key columns and drops right key columns. If `false`, keeps join key columns separate.
494
+ * @param {JoinMaintainOrder | boolean} [config.maintain_order] Row order preservation strategy. Default `"none"`.
495
+ * - `"none"` (or `false`) — No specific ordering is desired.
496
+ * - `"left"` (or `true`) — Preserves the order of the left DataFrame.
497
+ * - `"right"` — Preserves the order of the right DataFrame.
498
+ * - `"left_right"` — Preserves the order of the left DataFrame first, then the right.
499
+ * - `"right_left"` — Preserves the order of the right DataFrame first, then the left.
500
+ * @returns {DataFrame}
453
501
  * @example
454
502
  * >>> const df1 = $df.data({ id: [1, 2], val: ["a", "b"] })
455
503
  * >>> df1
@@ -471,13 +519,85 @@ export declare class DataFrame<T extends RowRecord = any> {
471
519
  * └────┴─────┴─────┘
472
520
  */
473
521
  join<U extends RowRecord = any, R extends RowRecord = any>(config: JoinOptions<T, U>): DataFrame<R>;
522
+ /**
523
+ * Performs an asof (as-of) join for inexact matching on ordered numeric or temporal key columns.
524
+ *
525
+ * Similar to a left join, but instead of exact key equality, matches the nearest key row from the right
526
+ * DataFrame according to the selected `strategy` ("backward", "forward", or "nearest") and optional `tolerance`.
527
+ * Both DataFrames must be sorted in ascending order on their respective `on` / `leftOn` / `rightOn` join keys.
528
+ *
529
+ * @param {AsofJoinOptions} options Asof join configuration options.
530
+ * @param {DataFrame} options.other The right DataFrame to join with.
531
+ * @param {string} [options.on] Column name to join on (must exist in both DataFrames and be sorted ascending).
532
+ * @param {string} [options.leftOn] Left DataFrame join key column name.
533
+ * @param {string} [options.rightOn] Right DataFrame join key column name.
534
+ * @param {string | string[]} [options.by] Optional exact-match group column(s) present in both DataFrames.
535
+ * @param {string | string[]} [options.leftBy] Group column(s) for exact key matching in left DataFrame.
536
+ * @param {string | string[]} [options.rightBy] Group column(s) for exact key matching in right DataFrame.
537
+ * @param {AsofJoinStrategy} [options.strategy] Match search strategy. Default `"backward"`.
538
+ * - `"backward"` — Matches the latest right row where `rightKey <= leftKey`.
539
+ * - `"forward"` — Matches the earliest right row where `rightKey >= leftKey`.
540
+ * - `"nearest"` — Matches the right row with the absolute nearest key value to `leftKey`.
541
+ * @param {number | string} [options.tolerance] Maximum allowed distance between left key and right key.
542
+ * @param {boolean} [options.allow_exact_matches] Whether exact key matches are permitted. Default `true`.
543
+ * @param {[string, string]} [options.suffixes] Column name suffixes `[leftSuffix, rightSuffix]` to resolve name collisions. Default `["", "_right"]`.
544
+ * @param {boolean} [options.coalesce] Coalescing behavior for join key columns. Default `true`.
545
+ * @param {boolean} [options.check_sorted] Whether to verify that join keys are sorted ascending prior to matching. Default `true`.
546
+ * @returns A new DataFrame containing the joined results.
547
+ *
548
+ * @namespace df
549
+ * @category DataFrame
550
+ * @syntax
551
+ * df.join_asof({
552
+ * other,
553
+ * on,
554
+ * leftOn,
555
+ * rightOn,
556
+ * by,
557
+ * leftBy,
558
+ * rightBy,
559
+ * strategy,
560
+ * tolerance,
561
+ * allow_exact_matches,
562
+ * suffixes,
563
+ * coalesce,
564
+ * check_sorted
565
+ * })
566
+ * @example
567
+ * >>> const trades = new DataFrame([
568
+ * ... { time: 1000, ticker: "AAPL", price: 150.0 },
569
+ * ... { time: 1005, ticker: "AAPL", price: 150.5 },
570
+ * ... { time: 1015, ticker: "AAPL", price: 151.0 }
571
+ * ... ]);
572
+ * >>> const quotes = new DataFrame([
573
+ * ... { time: 998, ticker: "AAPL", bid: 149.9 },
574
+ * ... { time: 1004, ticker: "AAPL", bid: 150.4 },
575
+ * ... { time: 1010, ticker: "AAPL", bid: 150.8 }
576
+ * ... ]);
577
+ * >>> const joined = trades.join_asof({
578
+ * ... other: quotes,
579
+ * ... on: "time",
580
+ * ... by: "ticker",
581
+ * ... strategy: "backward"
582
+ * ... });
583
+ * >>> joined
584
+ * shape: (3, 4)
585
+ * ┌──────┬────────┬───────┬──────┐
586
+ * │ time │ ticker │ price │ bid │
587
+ * ├──────┼────────┼───────┼──────┤
588
+ * │ 1000 │ AAPL │ 150.0 │ 149.9│
589
+ * │ 1005 │ AAPL │ 150.5 │ 150.4│
590
+ * │ 1015 │ AAPL │ 151.0 │ 150.8│
591
+ * └──────┴────────┴───────┴──────┘
592
+ */
593
+ join_asof<U extends RowRecord = any, R extends RowRecord = any>(options: AsofJoinOptions<T, U>): DataFrame<R>;
474
594
  /**
475
595
  * Limits the output to N rows starting from offset.
476
- * @param n Maximum number of rows to take.
477
- * @param [options] Offset and slice direction options.
478
- * @param [options.offset] Number of rows to skip before taking `n` rows (default 0).
479
- * @param [options.from] Slice direction starting point (`"start"` or `"end"`). Default `"start"`.
480
- * @returns DataFrame
596
+ * @param {number} n Maximum number of rows to take.
597
+ * @param {LimitOptions} [options] Offset and slice direction options.
598
+ * @param {number} [options.offset] Number of rows to skip before taking `n` rows (default 0).
599
+ * @param {LimitPosition} [options.from] Slice direction starting point (`"start"` or `"end"`). Default `"start"`.
600
+ * @returns {DataFrame}
481
601
  * @example
482
602
  * >>> const df = $df.data({ a: [10, 20, 30, 40] })
483
603
  * >>> df
@@ -536,8 +656,8 @@ export declare class DataFrame<T extends RowRecord = any> {
536
656
  pivot<U extends RowRecord = any>(config: PivotOptions<T>): DataFrame<U>;
537
657
  /**
538
658
  * Renames columns based on a key-value mapping dictionary.
539
- * @param mapping Dictionary mapping old column names to new names.
540
- * @returns DataFrame
659
+ * @param {Partial<Record<keyof T, string>>} [mapping] Dictionary mapping old column names to new names.
660
+ * @returns {DataFrame}
541
661
  * @example
542
662
  * >>> const df = $df.data({ old_name: [1] })
543
663
  * >>> df
@@ -599,8 +719,8 @@ export declare class DataFrame<T extends RowRecord = any> {
599
719
  get schema(): DataFrameSchema;
600
720
  /**
601
721
  * Selects specific columns or evaluates column expressions.
602
- * @param args Column names, column expressions, or object maps to evaluate.
603
- * @returns DataFrame
722
+ * @param {(string | IExpr | Record<string, any> | (string | IExpr | Record<string, any>)[])[]} args Column names, column expressions, or object maps to evaluate.
723
+ * @returns {DataFrame}
604
724
  * @example
605
725
  * >>> const df = $df.data({ a: [1, 2], b: [10, 20] })
606
726
  * >>> df
@@ -640,9 +760,9 @@ export declare class DataFrame<T extends RowRecord = any> {
640
760
  get shape(): [number, number];
641
761
  /**
642
762
  * Slices a subset range of rows between start and end index.
643
- * @param start Starting row index.
644
- * @param end Optional ending row index (exclusive).
645
- * @returns DataFrame
763
+ * @param {number} start Starting row index.
764
+ * @param {number} [end] Optional ending row index (exclusive).
765
+ * @returns {DataFrame}
646
766
  * @example
647
767
  * >>> const df = $df.data({ a: [10, 20, 30, 40] })
648
768
  * >>> df
@@ -667,12 +787,12 @@ export declare class DataFrame<T extends RowRecord = any> {
667
787
  slice(start: number, end?: number): DataFrame<T>;
668
788
  /**
669
789
  * Sorts DataFrame rows by one or more column expressions or custom sorters.
670
- * @param config Sort configuration options.
671
- * @param config.by Column name(s) or expression(s) to sort by.
672
- * @param [config.descending] Sort order boolean or array of booleans per key (default `false`).
673
- * @param [config.nullsLast] When `true` (default), places nulls at the end of sorted output.
674
- * @param [config.custom] Optional dictionary mapping column names to custom comparator functions.
675
- * @returns DataFrame
790
+ * @param {SortOptions<T>} [config] Sort configuration options.
791
+ * @param {keyof T | (keyof T)[] | IExpr | IExpr[]} config.by Column name(s) or expression(s) to sort by.
792
+ * @param {boolean | boolean[]} [config.descending] Sort order boolean or array of booleans per key (default `false`).
793
+ * @param {boolean} [config.nullsLast] When `true` (default), places nulls at the end of sorted output.
794
+ * @param {Partial<Record<keyof T, (a: any, b: any) => number>>} [config.custom] Optional dictionary mapping column names to custom comparator functions.
795
+ * @returns {DataFrame}
676
796
  * @example
677
797
  * >>> const df = $df.data({ val: [3, 1, 2] })
678
798
  * >>> df
@@ -756,8 +876,8 @@ export declare class DataFrame<T extends RowRecord = any> {
756
876
  to_dicts(): T[];
757
877
  /**
758
878
  * Evaluates a column expression or retrieves column values as a raw JavaScript array.
759
- * @param nameOrExpr Target column name or column expression.
760
- * @returns Array of column scalar values.
879
+ * @param {K | IExpr} nameOrExpr Target column name or column expression.
880
+ * @returns {any[]} Array of column scalar values.
761
881
  * @example
762
882
  * >>> const df = $df.data({ a: [10, 20] })
763
883
  * >>> df
@@ -774,11 +894,11 @@ export declare class DataFrame<T extends RowRecord = any> {
774
894
  to_array<K extends keyof T>(nameOrExpr: K | IExpr): any[];
775
895
  /**
776
896
  * Transposes rows into columns and columns into rows.
777
- * @param [options] Transpose layout options.
778
- * @param [options.include_header] When `true`, includes original column names as a new header column (default `false`).
779
- * @param [options.header_name] Name of the header column when `include_header` is `true` (default `"column"`).
780
- * @param [options.column_names] Column name or iterable of strings to use as transposed column headers.
781
- * @returns DataFrame
897
+ * @param {TransposeOptions} [options] Transpose layout options.
898
+ * @param {boolean} [options.include_header] When `true`, includes original column names as a new header column (default `false`).
899
+ * @param {string} [options.header_name] Name of the header column when `include_header` is `true` (default `"column"`).
900
+ * @param {string | Iterable<string>} [options.column_names] Column name or iterable of strings to use as transposed column headers.
901
+ * @returns {DataFrame}
782
902
  * @example
783
903
  * >>> const df = $df.data({ metric: ["sales", "clicks"], q1: [100, 500], q2: [120, 600] })
784
904
  * >>> df
@@ -801,8 +921,8 @@ export declare class DataFrame<T extends RowRecord = any> {
801
921
  transpose({ include_header: includeHeader, header_name: headerName, column_names: colNamesOpt }?: TransposeOptions): DataFrame<any>;
802
922
  /**
803
923
  * Filters distinct unique rows matching target key columns.
804
- * @param columns Target column or array of column names to evaluate uniqueness.
805
- * @returns DataFrame
924
+ * @param {K | K[]} [columns] Target column or array of column names to evaluate uniqueness.
925
+ * @returns {DataFrame}
806
926
  * @example
807
927
  * >>> const df = $df.data({ a: [1, 2, 2], b: ["x", "y", "y"] })
808
928
  * >>> df
@@ -826,12 +946,12 @@ export declare class DataFrame<T extends RowRecord = any> {
826
946
  unique<K extends keyof T>(columns?: K | K[]): DataFrame<T>;
827
947
  /**
828
948
  * Unpivots a wide DataFrame into a long format structure.
829
- * @param config Unpivot configuration options.
830
- * @param config.idVars Key column(s) to retain as identifier variables.
831
- * @param config.valueVars Column(s) to unpivot into variable-value pairs.
832
- * @param [config.varName] Name for the new variable column holding old column headers (default `"variable"`).
833
- * @param [config.valueName] Name for the new value column holding cell values (default `"value"`).
834
- * @returns DataFrame
949
+ * @param {UnpivotOptions<T>} config Unpivot configuration options.
950
+ * @param {keyof T | (keyof T)[]} config.idVars Key column(s) to retain as identifier variables.
951
+ * @param {keyof T | (keyof T)[]} config.valueVars Column(s) to unpivot into variable-value pairs.
952
+ * @param {string} [config.varName] Name for the new variable column holding old column headers (default `"variable"`).
953
+ * @param {string} [config.valueName] Name for the new value column holding cell values (default `"value"`).
954
+ * @returns {DataFrame}
835
955
  * @example
836
956
  * >>> const df = $df.data({ year: [2020], Jan: [100], Feb: [150] })
837
957
  * >>> df
@@ -853,8 +973,8 @@ export declare class DataFrame<T extends RowRecord = any> {
853
973
  unpivot<U extends RowRecord = any>(config: UnpivotOptions<T>): DataFrame<U>;
854
974
  /**
855
975
  * Concatenates DataFrames vertically. Alias for concat({ how: "vertical" }).
856
- * @param other Single DataFrame or array of DataFrames to append vertically.
857
- * @returns DataFrame
976
+ * @param {ConcatItem | ConcatItem[]} other Single DataFrame or array of DataFrames to append vertically.
977
+ * @returns {DataFrame}
858
978
  * @example
859
979
  * >>> const df1 = $df.data({ a: [1] })
860
980
  * >>> df1
@@ -894,8 +1014,8 @@ export declare class DataFrame<T extends RowRecord = any> {
894
1014
  private _normalizeArgs;
895
1015
  /**
896
1016
  * Adds new columns or updates existing ones using column expressions.
897
- * @param args Expressions or field objects defining column calculations.
898
- * @returns DataFrame
1017
+ * @param {(string | IExpr | Record<string, any> | (string | IExpr | Record<string, any>)[])[]} args Expressions or field objects defining column calculations.
1018
+ * @returns {DataFrame}
899
1019
  * @example
900
1020
  * >>> const df = $df.data({ a: [1, 2] })
901
1021
  * >>> df
@@ -918,9 +1038,9 @@ export declare class DataFrame<T extends RowRecord = any> {
918
1038
  with_columns(...args: (string | IExpr | Record<string, any> | (string | IExpr | Record<string, any>)[])[]): DataFrame<any>;
919
1039
  /**
920
1040
  * Appends an incremental index column.
921
- * @param name Name of index column (default "index").
922
- * @param offset Starting numeric index offset (default 0).
923
- * @returns DataFrame
1041
+ * @param {string} [name] Name of index column (default "index").
1042
+ * @param {number} [offset] Starting numeric index offset (default 0).
1043
+ * @returns {DataFrame}
924
1044
  * @example
925
1045
  * >>> const df = $df.data({ val: ["a", "b"] })
926
1046
  * >>> df
@@ -943,11 +1063,31 @@ export declare class DataFrame<T extends RowRecord = any> {
943
1063
  with_row_index(name?: string, offset?: number): DataFrame<any>;
944
1064
  /**
945
1065
  * Writes DataFrame rows to JSON format string or file/stream target.
946
- * @param [file] Target file path or writable stream target (optional).
947
- * @param [options] JSON formatting and replacer options.
948
- * @param [options.format] JSON output format structure (`"json"` or `"ndjson"`). Default `"json"`.
949
- * @param [options.replacerOptions] Serialization options including custom `replacer` function or replacer array.
950
- * @returns JSON string representation.
1066
+ * @param {string | { write: (str: string) => void }} [file] Target file path or writable stream target (optional).
1067
+ * @param {WriteJSONOptions} [options] JSON formatting and replacer options.
1068
+ * @param {JSONFormat} [options.format] JSON output format structure (`"json"` or `"ndjson"`). Default `"json"`.
1069
+ * @param {SafeJsonReplacerOptions} [options.replacerOptions] Serialization options for custom type handling.
1070
+ * @param {(v: Date) => string} [options.replacerOptions.formatDate] Custom formatter function for Date objects. Ignored if `onDate` is specified.
1071
+ * @param {"string" | "number"} [options.replacerOptions.bigintStrategy] Convert BigInts to numeric strings or numbers if safe. Default `"string"`.
1072
+ * @param {(v: bigint) => any} [options.replacerOptions.onBigInt] Custom serialization override for BigInt values.
1073
+ * @param {(v: any) => any} [options.replacerOptions.onTypedArray] Custom serialization override for TypedArray values.
1074
+ * @param {(v: Set<any>) => any} [options.replacerOptions.onSet] Custom serialization override for Set objects.
1075
+ * @param {(v: Map<any, any>) => any} [options.replacerOptions.onMap] Custom serialization override for Map objects.
1076
+ * @param {(v: RegExp) => any} [options.replacerOptions.onRegExp] Custom serialization override for RegExp objects.
1077
+ * @param {(v: Date) => any} [options.replacerOptions.onDate] Custom serialization override for Date objects. Takes precedence over `formatDate`.
1078
+ * @param {(v: Error) => any} [options.replacerOptions.onError] Custom serialization override for Error objects. Prevents empty `{}` output.
1079
+ * @param {(v: URLSearchParams) => any} [options.replacerOptions.onURLSearchParams] Custom serialization override for URLSearchParams objects.
1080
+ * @param {(this: any, k: string, v: any) => any} [options.replacerOptions.onCustom] Catch-all serialization override for custom types. Runs after native type checks.
1081
+ * @param {boolean} [options.replacerOptions.handleCircular] If `true`, handles circular references by replacing them instead of throwing.
1082
+ * @param {(this: any, k: string, v: any) => any} [options.replacerOptions.onCircular] Custom fallback when a circular reference is found. Default `"[Circular]"`.
1083
+ * @param {boolean} [options.replacerOptions.voidBigIntReplacement] If `true`, disables the default safe serialization for BigInt values.
1084
+ * @param {boolean} [options.replacerOptions.voidTypedArrayReplacement] If `true`, disables the default safe serialization for TypedArray values.
1085
+ * @param {boolean} [options.replacerOptions.voidSetReplacement] If `true`, disables the default safe serialization for Set objects.
1086
+ * @param {boolean} [options.replacerOptions.voidMapReplacement] If `true`, disables the default safe serialization for Map objects.
1087
+ * @param {boolean} [options.replacerOptions.voidRegExpReplacement] If `true`, disables the default safe serialization for RegExp objects.
1088
+ * @param {boolean} [options.replacerOptions.voidDateReplacement] If `true`, disables the default safe serialization for Date objects.
1089
+ * @param {((this: any, k: string, v: any) => any) | (string | number)[] | null} [options.replacerOptions.replacer] Custom replacer function or array whitelist that runs first for pre-processing.
1090
+ * @returns {string} JSON string representation.
951
1091
  * @example
952
1092
  * >>> const df = $df.data({ a: [1], b: ["x"] })
953
1093
  * >>> df
@@ -965,12 +1105,12 @@ export declare class DataFrame<T extends RowRecord = any> {
965
1105
  }, { format, replacerOptions }?: WriteJSONOptions): string;
966
1106
  /**
967
1107
  * Writes DataFrame to CSV format string or file/stream target.
968
- * @param [file] Target file path or writable stream target (optional).
969
- * @param [options] CSV formatting options.
970
- * @param [options.delimiter] Column delimiter character (default `","`).
971
- * @param [options.header] When `true` (default), includes column header row.
972
- * @param [options.quoteChar] Character used to enclose fields containing special characters (default `'"'`).
973
- * @returns CSV string output.
1108
+ * @param {string | { write: (str: string) => void }} [file] Target file path or writable stream target (optional).
1109
+ * @param {WriteCSVOptions} [options] CSV formatting options.
1110
+ * @param {string} [options.delimiter] Column delimiter character (default `","`).
1111
+ * @param {boolean} [options.header] When `true` (default), includes column header row.
1112
+ * @param {string} [options.quoteChar] Character used to enclose fields containing special characters (default `'"'`).
1113
+ * @returns {string} CSV string output.
974
1114
  * @example
975
1115
  * >>> const df = $df.data({ a: [1], b: ["x"] })
976
1116
  * >>> df
@@ -3,7 +3,8 @@ import type { IExpr, AggFn, RowRecord, DataFrameSchema, JSONFormat } from "../ty
3
3
  import type { DataFrame } from "./dataframe";
4
4
  import type { JSONParseOptions, SafeJsonReplacerOptions, NDJSONParseOptions } from "../utils";
5
5
  export type { JSONParseOptions, SafeJsonReplacerOptions, NDJSONParseOptions };
6
- export type JoinType = "inner" | "left" | "outer" | "right";
6
+ export type JoinType = "inner" | "outer" | "left" | "right" | "semi" | "anti" | "cross";
7
+ export type JoinMaintainOrder = "none" | "left" | "right" | "left_right" | "right_left";
7
8
  export type LimitPosition = "start" | "end";
8
9
  export type GroupMap = Map<string, number[]>;
9
10
  export interface LimitOptions {
@@ -22,11 +23,32 @@ export interface PivotOptions<T> {
22
23
  values: keyof T;
23
24
  agg?: AggFn<any> | string;
24
25
  }
25
- export interface JoinOptions<T, U extends RowRecord = any> {
26
+ export interface JoinOptions<T = any, U extends RowRecord = any> {
26
27
  other: DataFrame<U>;
27
- on: (keyof T & keyof U) | (keyof T & keyof U)[];
28
+ on?: (keyof T & keyof U) | (keyof T & keyof U)[];
29
+ leftOn?: (keyof T) | (keyof T)[];
30
+ rightOn?: (keyof U) | (keyof U)[];
28
31
  how?: JoinType;
29
32
  suffixes?: [string, string];
33
+ join_nulls?: boolean;
34
+ coalesce?: boolean;
35
+ maintain_order?: JoinMaintainOrder | boolean;
36
+ }
37
+ export type AsofJoinStrategy = "backward" | "forward" | "nearest";
38
+ export interface AsofJoinOptions<T = any, U extends RowRecord = any> {
39
+ other: DataFrame<U>;
40
+ on?: (keyof T & keyof U);
41
+ leftOn?: (keyof T);
42
+ rightOn?: (keyof U);
43
+ by?: (keyof T & keyof U) | (keyof T & keyof U)[];
44
+ leftBy?: (keyof T) | (keyof T)[];
45
+ rightBy?: (keyof U) | (keyof U)[];
46
+ strategy?: AsofJoinStrategy;
47
+ tolerance?: number | string;
48
+ allow_exact_matches?: boolean;
49
+ suffixes?: [string, string];
50
+ coalesce?: boolean;
51
+ check_sorted?: boolean;
30
52
  }
31
53
  export interface UnpivotOptions<T> {
32
54
  idVars: (keyof T) | (keyof T)[];
@@ -1,5 +1,7 @@
1
1
  /** @internalfile */
2
- import type { IExpr, ColumnData, ColumnDict, RegisteredDataType } from "../types";
2
+ import type { IExpr, ColumnData, ColumnDict, RegisteredDataType, DataFrameSchema, RowRecord } from "../types";
3
+ import type { JoinOptions, AsofJoinOptions } from "./types";
4
+ import { DataFrame } from "./dataframe";
3
5
  export declare function resolveWindowExpr(expr: IExpr, columns: ColumnDict, height: number): ColumnData;
4
6
  export declare function rowsToColumns(rows: any[]): {
5
7
  columns: ColumnDict;
@@ -18,3 +20,21 @@ export declare function coerceColumn(col: ColumnData, type: RegisteredDataType,
18
20
  export declare function writeStringToFileOrStream(file: string | {
19
21
  write: (str: string) => void;
20
22
  } | undefined, content: string): void;
23
+ /**
24
+ * Generic key-alignment engine computing positional row index mappings (leftIndex <-> rightIndex)
25
+ * between two columnar datasets based on key hashing.
26
+ * Reusable for Joins, Set Operations (Intersect/Difference), Upserts, and Alignments.
27
+ */
28
+ export declare function alignKeyIndices(leftCols: ColumnDict, rightCols: ColumnDict, leftHeight: number, rightHeight: number, leftKeys: string[], rightKeys: string[], options?: Partial<JoinOptions>): {
29
+ leftIndices: number[];
30
+ rightIndices: (number | null)[];
31
+ };
32
+ export declare function alignAsofIndices(leftCols: ColumnDict, rightCols: ColumnDict, leftHeight: number, rightHeight: number, leftOnKey: string, rightOnKey: string, leftByKeys: string[], rightByKeys: string[], options?: AsofJoinOptions): {
33
+ leftIndices: number[];
34
+ rightIndices: (number | null)[];
35
+ };
36
+ export declare function materializeJoinedDataFrame<R extends RowRecord = any>(leftCols: ColumnDict, rightCols: ColumnDict, leftSchema: DataFrameSchema, rightSchema: DataFrameSchema, leftIndices: number[], rightIndices: (number | null)[], leftKeysStr: string[], rightKeysStr: string[], options?: {
37
+ suffixes?: [string, string];
38
+ coalesce?: boolean;
39
+ how?: string;
40
+ }): DataFrame<R>;
@@ -1,6 +1,6 @@
1
1
  /** @typefile */
2
2
  import { DataType, SignedIntegerType, UnsignedIntegerType, FloatDataType, TemporalDataType, NestedDataType, NumericDataType } from "./DataType";
3
- import type { RowRecord } from "../types";
3
+ import type { RowRecord, DatetimeTimeUnit } from "../types";
4
4
  export declare class Int8Type extends SignedIntegerType {
5
5
  readonly name = "Int8";
6
6
  coerce(val: unknown): number | null;
@@ -159,11 +159,14 @@ export declare class DateType extends TemporalDataType<Date | null> {
159
159
  }
160
160
  export declare const DateDataType: DateType;
161
161
  /**
162
- * Date and time type (year, month, day, hour, minute, second, millisecond).
163
- *
162
+ * Date and time type (year, month, day, hour, minute, second, millisecond)
163
+ * with timeUnit precision and optional timezone awareness.
164
164
  */
165
165
  export declare class DatetimeType extends TemporalDataType<Date | null> {
166
166
  readonly name = "Datetime";
167
+ readonly timeUnit: DatetimeTimeUnit;
168
+ readonly timeZone: string | null;
169
+ constructor(timeUnit?: DatetimeTimeUnit, timeZone?: string | null);
167
170
  coerce(val: unknown): Date | null;
168
171
  equals(other: DataType): boolean;
169
172
  allocate(size: number): (Date | null)[];
@@ -178,6 +181,8 @@ export declare class TimeType extends TemporalDataType<string | null> {
178
181
  export declare const Time: TimeType;
179
182
  export declare class DurationType extends TemporalDataType<number | null> {
180
183
  readonly name = "Duration";
184
+ readonly timeUnit: DatetimeTimeUnit;
185
+ constructor(timeUnit?: DatetimeTimeUnit);
181
186
  coerce(val: unknown): number | null;
182
187
  equals(other: DataType): boolean;
183
188
  allocate(size: number): (number | null)[];
@@ -35,4 +35,14 @@ export declare class ComputeError extends DFScriptError {
35
35
  */
36
36
  export declare class ShapeError extends DFScriptError {
37
37
  }
38
+ /**
39
+ * Error thrown when a parameter or argument provided to a function is invalid.
40
+ */
41
+ export declare class InvalidArgumentError extends DFScriptError {
42
+ }
43
+ /**
44
+ * Error thrown during file I/O or streaming operations.
45
+ */
46
+ export declare class IOStreamError extends DFScriptError {
47
+ }
38
48
  export * from "./utils";
@@ -1,3 +1,5 @@
1
1
  import type { ColumnDict } from "../types";
2
2
  export declare function assertColumnExists(columnName: string, columns: ColumnDict, context: string, suffix?: string): void;
3
3
  export declare function assertHeight(columns: ColumnDict, height?: number): number;
4
+ export declare function assertNotNull<T>(value: T | null | undefined, message?: string): T;
5
+ export declare function assertValidArgument(condition: boolean, message: string): void;