df-script 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +1 -1
  2. package/dist/api.d.ts +2 -1
  3. package/dist/assets/index-DBhGK6Tp.css +1 -0
  4. package/dist/assets/index-DEJEV_tU.js +195 -0
  5. package/dist/columnExpressions/ColumnExpr.d.ts +12 -5
  6. package/dist/columnExpressions/ExprBase.d.ts +26 -12
  7. package/dist/columnExpressions/constants.d.ts +1 -0
  8. package/dist/columnExpressions/functions/all.d.ts +23 -0
  9. package/dist/columnExpressions/functions/coalesce.d.ts +29 -0
  10. package/dist/columnExpressions/functions/element.d.ts +25 -0
  11. package/dist/columnExpressions/functions/exclude.d.ts +24 -0
  12. package/dist/columnExpressions/functions/implode.d.ts +28 -0
  13. package/dist/columnExpressions/functions/lit.d.ts +27 -0
  14. package/dist/columnExpressions/functions/seq_range.d.ts +36 -0
  15. package/dist/columnExpressions/functions/struct.d.ts +31 -0
  16. package/dist/columnExpressions/functions/when.d.ts +36 -6
  17. package/dist/columnExpressions/index.d.ts +1 -0
  18. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +334 -0
  19. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +609 -0
  20. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +533 -5
  21. package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +353 -0
  22. package/dist/columnExpressions/mixins/LogicalExpr.d.ts +82 -0
  23. package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +40 -0
  24. package/dist/columnExpressions/mixins/StringExpr.d.ts +656 -3
  25. package/dist/columnExpressions/mixins/StructExpr.d.ts +70 -0
  26. package/dist/columnExpressions/mixins/TemporalExpr.d.ts +530 -4
  27. package/dist/columnExpressions/mixins/WindowExpr.d.ts +313 -2
  28. package/dist/columnExpressions/types.d.ts +1 -0
  29. package/dist/dataframe/dataframe.d.ts +932 -2
  30. package/dist/dataframe/grouped/grouped.d.ts +41 -6
  31. package/dist/dataframe/types.d.ts +1 -0
  32. package/dist/dataframe/utils.d.ts +1 -0
  33. package/dist/datatypes/types.d.ts +45 -0
  34. package/dist/exceptions/index.d.ts +23 -0
  35. package/dist/functions/concat.d.ts +50 -0
  36. package/dist/functions/read_csv.d.ts +9 -0
  37. package/dist/functions/read_json.d.ts +7 -2
  38. package/dist/index.html +17 -0
  39. package/dist/index.js +5 -5
  40. package/dist/index.mjs +6 -0
  41. package/dist/types.d.ts +47 -14
  42. package/dist/utils/array.d.ts +32 -1
  43. package/dist/utils/csv.d.ts +1 -0
  44. package/dist/utils/date.d.ts +10 -27
  45. package/dist/utils/json.d.ts +1 -0
  46. package/dist/utils/number.d.ts +1 -0
  47. package/dist/utils/object.d.ts +1 -0
  48. package/dist/utils/string.d.ts +12 -0
  49. package/package.json +18 -4
  50. package/dist/columnExpressions/mixins/ListExpr.d.ts +0 -39
  51. package/dist/utils/guards.d.ts +0 -13
  52. package/dist/utils/list.d.ts +0 -217
@@ -1,14 +1,49 @@
1
1
  import { DataFrame } from "../dataframe";
2
2
  import type { GroupMap } from "../types";
3
3
  import type { IExpr, ColumnDict, RowRecord, DataFrameSchema } from "../../types";
4
+ /**
5
+ * Represents a DataFrame grouped by key columns, supporting aggregation operations.
6
+ * @namespace df
7
+ * @category DataFrame
8
+ * @syntax df.groupby(...).{symbol}(...)
9
+ */
4
10
  export declare class GroupedData<T, K extends keyof T> {
5
- private groups;
6
- private keys;
7
- private allKeys;
8
- private parentColumns;
9
- private parentHeight;
10
- private parentSchema;
11
+ private _groups;
12
+ private _keys;
13
+ private _allKeys;
14
+ private _parentColumns;
15
+ private _parentHeight;
16
+ private _parentSchema;
11
17
  constructor(groups: GroupMap, keys: K[], allKeys: (keyof T)[], parentColumns: ColumnDict, parentHeight: number, parentSchema: DataFrameSchema);
18
+ /**
19
+ * Converts group keys back into a single distinct DataFrame without aggregations.
20
+ * @returns DataFrame
21
+ * @example
22
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [1, 2, 3] })
23
+ * >>> df.groupby("group").to_dataframe()
24
+ * shape: (2, 1)
25
+ * ┌───────┐
26
+ * │ group │
27
+ * ├───────┤
28
+ * │ A │
29
+ * │ B │
30
+ * └───────┘
31
+ */
12
32
  to_dataframe<U extends RowRecord = any>(): DataFrame<U>;
33
+ /**
34
+ * Aggregates grouped partitions using aggregation column expressions.
35
+ * @param exprs One or more aggregation column expressions.
36
+ * @returns DataFrame
37
+ * @example
38
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
39
+ * >>> df.groupby("group").agg($df.col("val").sum().alias("sum_val"))
40
+ * shape: (2, 2)
41
+ * ┌───────┬─────────┐
42
+ * │ group │ sum_val │
43
+ * ├───────┼─────────┤
44
+ * │ A │ 30 │
45
+ * │ B │ 30 │
46
+ * └───────┴─────────┘
47
+ */
13
48
  agg<U extends RowRecord = any>(...exprs: (IExpr | any)[]): DataFrame<U>;
14
49
  }
@@ -1,3 +1,4 @@
1
+ /** @typefile */
1
2
  import type { IExpr, AggFn, RowRecord, DataFrameSchema, JSONFormat } from "../types";
2
3
  import type { DataFrame } from "./dataframe";
3
4
  import type { JSONParseOptions, SafeJsonReplacerOptions, NDJSONParseOptions } from "../utils";
@@ -1,3 +1,4 @@
1
+ /** @internalfile */
1
2
  import type { IExpr, ColumnData, ColumnDict, RegisteredDataType } from "../types";
2
3
  export declare function resolveWindowExpr(expr: IExpr, columns: ColumnDict, height: number): ColumnData;
3
4
  export declare function rowsToColumns(rows: any[]): {
@@ -1,3 +1,4 @@
1
+ /** @typefile */
1
2
  import { DataType, SignedIntegerType, UnsignedIntegerType, FloatDataType, TemporalDataType, NestedDataType, NumericDataType } from "./DataType";
2
3
  import type { RowRecord } from "../types";
3
4
  export declare class Int8Type extends SignedIntegerType {
@@ -14,6 +15,10 @@ export declare class Int16Type extends SignedIntegerType {
14
15
  allocate(size: number): Int16Array;
15
16
  }
16
17
  export declare const Int16: Int16Type;
18
+ /**
19
+ * 32-bit signed integer type (values from -2,147,483,648 to 2,147,483,647).
20
+ *
21
+ */
17
22
  export declare class Int32Type extends SignedIntegerType {
18
23
  readonly name = "Int32";
19
24
  coerce(val: unknown): number | null;
@@ -21,6 +26,10 @@ export declare class Int32Type extends SignedIntegerType {
21
26
  allocate(size: number): Int32Array;
22
27
  }
23
28
  export declare const Int32: Int32Type;
29
+ /**
30
+ * 64-bit signed integer type (represented as JavaScript BigInt).
31
+ *
32
+ */
24
33
  export declare class Int64Type extends SignedIntegerType<bigint | null> {
25
34
  readonly name = "Int64";
26
35
  coerce(val: unknown): bigint | null;
@@ -63,6 +72,10 @@ export declare class Float32Type extends FloatDataType {
63
72
  allocate(size: number): Float32Array;
64
73
  }
65
74
  export declare const Float32: Float32Type;
75
+ /**
76
+ * 64-bit double precision floating point number type.
77
+ *
78
+ */
66
79
  export declare class Float64Type extends FloatDataType {
67
80
  readonly name = "Float64";
68
81
  coerce(val: unknown): number | null;
@@ -70,6 +83,12 @@ export declare class Float64Type extends FloatDataType {
70
83
  allocate(size: number): Float64Array;
71
84
  }
72
85
  export declare const Float64: Float64Type;
86
+ /**
87
+ * Fixed point decimal type with optional precision and scale arguments.
88
+ *
89
+ * @param precision Precision level (total number of digits)
90
+ * @param scale Scale level (number of decimal place digits)
91
+ */
73
92
  export declare class DecimalType extends NumericDataType {
74
93
  readonly precision?: number | undefined;
75
94
  readonly scale?: number | undefined;
@@ -79,6 +98,10 @@ export declare class DecimalType extends NumericDataType {
79
98
  equals(other: DataType): boolean;
80
99
  allocate(size: number): (number | null)[];
81
100
  }
101
+ /**
102
+ * Boolean datatype representing binary values (true or false).
103
+ *
104
+ */
82
105
  export declare class BooleanType extends DataType<boolean | null> {
83
106
  readonly name = "Boolean";
84
107
  get isBoolean(): boolean;
@@ -87,6 +110,10 @@ export declare class BooleanType extends DataType<boolean | null> {
87
110
  allocate(size: number): (boolean | null)[];
88
111
  }
89
112
  export declare const BooleanDataType: BooleanType;
113
+ /**
114
+ * Unicode UTF-8 string datatype.
115
+ *
116
+ */
90
117
  export declare class Utf8Type extends DataType<string | null> {
91
118
  readonly name = "Utf8";
92
119
  get isString(): boolean;
@@ -120,6 +147,10 @@ export declare class ObjectType extends DataType {
120
147
  allocate(size: number): any[];
121
148
  }
122
149
  export declare const ObjectDataType: ObjectType;
150
+ /**
151
+ * Calendar date type storing UTC year, month, and day.
152
+ *
153
+ */
123
154
  export declare class DateType extends TemporalDataType<Date | null> {
124
155
  readonly name = "Date";
125
156
  coerce(val: unknown): Date | null;
@@ -127,6 +158,10 @@ export declare class DateType extends TemporalDataType<Date | null> {
127
158
  allocate(size: number): (Date | null)[];
128
159
  }
129
160
  export declare const DateDataType: DateType;
161
+ /**
162
+ * Date and time type (year, month, day, hour, minute, second, millisecond).
163
+ *
164
+ */
130
165
  export declare class DatetimeType extends TemporalDataType<Date | null> {
131
166
  readonly name = "Datetime";
132
167
  coerce(val: unknown): Date | null;
@@ -148,6 +183,11 @@ export declare class DurationType extends TemporalDataType<number | null> {
148
183
  allocate(size: number): (number | null)[];
149
184
  }
150
185
  export declare const Duration: DurationType;
186
+ /**
187
+ * Nested array list datatype wrapping an inner element type.
188
+ *
189
+ * @param innerType The child elements datatype
190
+ */
151
191
  export declare class ArrayType<TInner = any> extends NestedDataType<TInner[] | null> {
152
192
  readonly innerType: RegisteredDataType & DataType<TInner>;
153
193
  readonly name = "Array";
@@ -157,6 +197,11 @@ export declare class ArrayType<TInner = any> extends NestedDataType<TInner[] | n
157
197
  allocate(size: number): (TInner[] | null)[];
158
198
  }
159
199
  export declare const ArrayDataType: <TInner>(inner: RegisteredDataType & DataType<TInner>) => ArrayType<TInner>;
200
+ /**
201
+ * Keyed struct object datatype wrapping sub-field schemas.
202
+ *
203
+ * @param fields Schema mapping of field names to Datatypes
204
+ */
160
205
  export declare class StructType<TFields extends RowRecord = any> extends NestedDataType<TFields | null> {
161
206
  readonly fields: {
162
207
  [K in keyof TFields]: RegisteredDataType & DataType<TFields[K]>;
@@ -1,15 +1,38 @@
1
+ /**
2
+ * @namespace Exception
3
+ * @category Exception
4
+ * @syntax throw new {symbol}("message")
5
+ */
6
+ /**
7
+ * Base exception class for all df-script errors.
8
+ */
1
9
  export declare class DFScriptError extends Error {
2
10
  constructor(message: string);
3
11
  }
12
+ /**
13
+ * General error thrown during DataFrame instantiation or execution.
14
+ */
4
15
  export declare class DataFrameError extends DFScriptError {
5
16
  }
17
+ /**
18
+ * Error thrown when a specified column name does not exist in the DataFrame schema.
19
+ */
6
20
  export declare class ColumnNotFoundError extends DataFrameError {
7
21
  constructor(columnName: string, message?: string);
8
22
  }
23
+ /**
24
+ * Error thrown when schema definitions, coercions, or data types are invalid.
25
+ */
9
26
  export declare class SchemaError extends DFScriptError {
10
27
  }
28
+ /**
29
+ * Error thrown during expression evaluation or element-wise calculations.
30
+ */
11
31
  export declare class ComputeError extends DFScriptError {
12
32
  }
33
+ /**
34
+ * Error thrown when shape dimensions or column heights mismatch.
35
+ */
13
36
  export declare class ShapeError extends DFScriptError {
14
37
  }
15
38
  export * from "./utils";
@@ -1,3 +1,53 @@
1
1
  import { DataFrame } from "../dataframe/dataframe";
2
2
  import type { ConcatOptions, ConcatItem, RowRecord } from "../types";
3
+ /**
4
+ * Concatenates items vertically, horizontally, or diagonally.
5
+ * @namespace $df
6
+ * @category ColumnExpression
7
+ * @syntax $df.{symbol}(...)
8
+ * @param rawItems Single DataFrame or array of DataFrames/rows to concatenate.
9
+ * @param [options] Configuration options for concatenation layout and strictness.
10
+ * @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).
11
+ * @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`.
12
+ * @returns DataFrame
13
+ *
14
+ * @example
15
+ * // 1. Vertical Concatenation (default):
16
+ * >>> const df1 = $df.data({ a: [1] })
17
+ * >>> const df2 = $df.data({ a: [2] })
18
+ * >>> $df.concat([df1, df2], { how: "vertical" })
19
+ * shape: (2, 1)
20
+ * ┌───┐
21
+ * │ a │
22
+ * ├───┤
23
+ * │ 1 │
24
+ * │ 2 │
25
+ * └───┘
26
+ *
27
+ * @example
28
+ * // 2. Horizontal Concatenation:
29
+ * >>> const df1 = $df.data({ a: [1] })
30
+ * >>> const df2 = $df.data({ b: [2] })
31
+ * >>> $df.concat([df1, df2], { how: "horizontal" })
32
+ * shape: (1, 2)
33
+ * ┌───┬───┐
34
+ * │ a │ b │
35
+ * ├───┼───┤
36
+ * │ 1 │ 2 │
37
+ * └───┴───┘
38
+ *
39
+ * @example
40
+ * // 3. Diagonal Concatenation (mismatched columns):
41
+ * >>> const df1 = $df.data({ a: [1] })
42
+ * >>> const df2 = $df.data({ b: [2] })
43
+ * >>> $df.concat([df1, df2], { how: "diagonal" })
44
+ * shape: (2, 2)
45
+ * ┌──────┬──────┐
46
+ * │ a │ b │
47
+ * ├──────┼──────┤
48
+ * │ 1 │ null │
49
+ * │ null │ 2 │
50
+ * └──────┴──────┘
51
+ *
52
+ */
3
53
  export declare function concat<U extends RowRecord = any>(rawItems: ConcatItem | ConcatItem[], { how, horizontal }?: ConcatOptions): DataFrame<U>;
@@ -4,5 +4,14 @@ import type { RowRecord } from "../types";
4
4
  /**
5
5
  * Reads a CSV string and constructs a DataFrame.
6
6
  * Automatically infers column data types unless an explicit schema is provided.
7
+ * @namespace $df
8
+ * @category ColumnExpression
9
+ * @syntax $df.{symbol}(...)
10
+ * @param content The CSV content string.
11
+ * @param [options] Parse and configuration options.
12
+ * @param [options.hasHeader] Whether the first row is a header row (default `true`).
13
+ * @param [options.schema] Optional column schema to coerce types.
14
+ * @param [options.inferSchema] When `true` (default), automatically infers column types.
15
+ * @returns DataFrame
7
16
  */
8
17
  export declare function read_csv<T extends RowRecord = any>(content: string, options?: ReadCSVOptions): DataFrame<T>;
@@ -2,9 +2,14 @@ import { DataFrame } from "../dataframe/dataframe";
2
2
  import type { ReadJSONOptions } from "../dataframe/types";
3
3
  /**
4
4
  * Parses JSON content (JSON or NDJSON) and loads it into a new DataFrame.
5
- *
5
+ * @namespace $df
6
+ * @category ColumnExpression
7
+ * @syntax $df.{symbol}(...)
6
8
  * @param content The JSON or NDJSON content string.
7
- * @param options Parse and configuration options.
9
+ * @param [options] Parse and configuration options.
10
+ * @param [options.format] Input format (`"json"` or `"ndjson"`). Default `"json"`.
11
+ * @param [options.trimBeforeParse] When `true` (default), trims whitespace before parsing.
12
+ * @param [options.schema] Optional column schema to coerce types.
8
13
  * @returns A new DataFrame instance populated with the parsed records.
9
14
  */
10
15
  export declare function read_json(content: string, { format, trimBeforeParse, schema, ...parseOpts }?: ReadJSONOptions): DataFrame<any>;
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>🚀 DFScript Interactive Playground</title>
7
+ <!-- Google Fonts: Outfit (headings) & Inter (body) & Fira Code (monocode) -->
8
+ <link rel="preconnect" href="https://fonts.googleapis.com">
9
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
+ <link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&family=Inter:wght@300;400;500;600&family=Outfit:wght@400;500;600;700;800&display=swap" rel="stylesheet">
11
+ <script type="module" crossorigin src="/assets/index-DEJEV_tU.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index-DBhGK6Tp.css">
13
+ </head>
14
+ <body>
15
+ <div id="root"></div>
16
+ </body>
17
+ </html>