@nshiab/simple-data-analysis-core 2.1.2 → 2.1.4
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/esm/_dnt.polyfills.d.ts +11 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +14 -0
- package/esm/class/SimpleDB.d.ts.map +1 -1
- package/esm/class/SimpleDB.js +23 -14
- package/esm/class/SimpleTable.d.ts +41 -12
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +40 -13
- package/esm/helpers/cleanCache.d.ts +1 -1
- package/esm/helpers/cleanCache.d.ts.map +1 -1
- package/esm/helpers/cleanCache.js +2 -2
- package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -1
- package/esm/helpers/updateColumnsWithJS.js +14 -12
- package/esm/methods/similarityMahalanobis.d.ts +7 -0
- package/esm/methods/similarityMahalanobis.d.ts.map +1 -0
- package/esm/methods/{mahalanobis.js → similarityMahalanobis.js} +36 -14
- package/esm/methods/updateWithJS.js +24 -5
- package/llm.md +42 -18
- package/llms.txt +1 -1
- package/package.json +2 -2
- package/script/_dnt.polyfills.d.ts +11 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +14 -0
- package/script/class/SimpleDB.d.ts.map +1 -1
- package/script/class/SimpleDB.js +23 -14
- package/script/class/SimpleTable.d.ts +41 -12
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +40 -13
- package/script/helpers/cleanCache.d.ts +1 -1
- package/script/helpers/cleanCache.d.ts.map +1 -1
- package/script/helpers/cleanCache.js +2 -2
- package/script/helpers/updateColumnsWithJS.d.ts.map +1 -1
- package/script/helpers/updateColumnsWithJS.js +13 -11
- package/script/methods/similarityMahalanobis.d.ts +7 -0
- package/script/methods/similarityMahalanobis.d.ts.map +1 -0
- package/script/methods/{mahalanobis.js → similarityMahalanobis.js} +37 -15
- package/script/methods/updateWithJS.js +24 -5
- package/esm/methods/mahalanobis.d.ts +0 -5
- package/esm/methods/mahalanobis.d.ts.map +0 -1
- package/script/methods/mahalanobis.d.ts +0 -5
- package/script/methods/mahalanobis.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"similarityMahalanobis.d.ts","sourceRoot":"","sources":["../../src/methods/similarityMahalanobis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AASvD,KAAK,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhF,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,cAAc,EAAE,MAAM,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EACrD,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,OAAY,GACpB,IAAI,CAsDN"}
|
|
@@ -5,17 +5,34 @@ import prepareNumericFeatures from "../helpers/prepareNumericFeatures.js";
|
|
|
5
5
|
import publishPreparedColumns from "../helpers/publishPreparedColumns.js";
|
|
6
6
|
import queueOp from "../helpers/queueOp.js";
|
|
7
7
|
import quoteIdentifier from "../helpers/quoteIdentifier.js";
|
|
8
|
-
export default function
|
|
8
|
+
export default function similarityMahalanobis(table, columns, referencePoint, newColumn, options = {}) {
|
|
9
|
+
const selected = typeof columns === "string" ? columns : [...columns];
|
|
10
|
+
if (!Array.isArray(referencePoint) && referencePoint !== null &&
|
|
11
|
+
typeof referencePoint === "object") {
|
|
12
|
+
if (typeof selected === "string") {
|
|
13
|
+
throw new Error("similarityMahalanobis() an object referencePoint requires an array of scalar feature column names; use a numeric array for a vector column.");
|
|
14
|
+
}
|
|
15
|
+
const referenceObject = referencePoint;
|
|
16
|
+
referencePoint = selected.map((column) => {
|
|
17
|
+
if (!Object.hasOwn(referenceObject, column)) {
|
|
18
|
+
throw new Error(`similarityMahalanobis() referencePoint is missing its own value for feature ${quoteIdentifier(column)}.`);
|
|
19
|
+
}
|
|
20
|
+
const value = referenceObject[column];
|
|
21
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
22
|
+
throw new Error(`similarityMahalanobis() referencePoint feature ${quoteIdentifier(column)} must be a finite number.`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
9
27
|
if (!Array.isArray(referencePoint) || referencePoint.length === 0 ||
|
|
10
28
|
Array.from(referencePoint).some((value) => typeof value !== "number" || !Number.isFinite(value))) {
|
|
11
|
-
throw new Error("
|
|
29
|
+
throw new Error("similarityMahalanobis() referencePoint must be a nonempty array of finite numbers in feature-dimension order.");
|
|
12
30
|
}
|
|
13
|
-
const selected = typeof columns === "string" ? columns : [...columns];
|
|
14
31
|
const reference = [...referencePoint];
|
|
15
32
|
const settings = { ...options };
|
|
16
33
|
queueOp(table, {
|
|
17
34
|
kind: "barrier",
|
|
18
|
-
method: "
|
|
35
|
+
method: "similarityMahalanobis()",
|
|
19
36
|
parameters: {
|
|
20
37
|
columns: selected,
|
|
21
38
|
referencePoint: reference,
|
|
@@ -27,29 +44,34 @@ export default function mahalanobis(table, columns, referencePoint, newColumn, o
|
|
|
27
44
|
}
|
|
28
45
|
async function execute(table, columns, referencePoint, newColumn, options) {
|
|
29
46
|
const sourceColumns = Object.keys(await table.getTypes());
|
|
30
|
-
const
|
|
47
|
+
const scoreColumn = options.similarityScoreColumn === true
|
|
48
|
+
? "similarity"
|
|
49
|
+
: options.similarityScoreColumn === false
|
|
50
|
+
? undefined
|
|
51
|
+
: options.similarityScoreColumn;
|
|
52
|
+
const outputNames = scoreColumn === undefined
|
|
31
53
|
? [newColumn]
|
|
32
|
-
: [newColumn,
|
|
54
|
+
: [newColumn, scoreColumn];
|
|
33
55
|
const seen = new Set();
|
|
34
56
|
for (const name of outputNames) {
|
|
35
57
|
if (typeof name !== "string" || name.length === 0 || name.includes("\0")) {
|
|
36
|
-
throw new Error("
|
|
58
|
+
throw new Error("similarityMahalanobis() output column names must be nonempty strings without null characters.");
|
|
37
59
|
}
|
|
38
60
|
const folded = foldIdentifier(name);
|
|
39
61
|
if (seen.has(folded)) {
|
|
40
|
-
throw new Error("
|
|
62
|
+
throw new Error("similarityMahalanobis() distance and similarity score columns must have different names (case-insensitive).");
|
|
41
63
|
}
|
|
42
64
|
seen.add(folded);
|
|
43
65
|
if (sourceColumns.some((column) => foldIdentifier(column) === folded)) {
|
|
44
|
-
throw new Error(`
|
|
66
|
+
throw new Error(`similarityMahalanobis() cannot create ${quoteIdentifier(name)} because that column already exists. Remove it first or choose a different name.`);
|
|
45
67
|
}
|
|
46
68
|
}
|
|
47
69
|
const prepared = await prepareNumericFeatures(table, typeof columns === "string"
|
|
48
70
|
? { kind: "vector", column: columns }
|
|
49
|
-
: { kind: "scalars", columns }, { method: "
|
|
71
|
+
: { kind: "scalars", columns }, { method: "similarityMahalanobis()" });
|
|
50
72
|
try {
|
|
51
73
|
if (referencePoint.length !== prepared.dimensions) {
|
|
52
|
-
throw new Error(`
|
|
74
|
+
throw new Error(`similarityMahalanobis() referencePoint must contain ${prepared.dimensions} values in feature-dimension order; received ${referencePoint.length}.`);
|
|
53
75
|
}
|
|
54
76
|
const model = await computeCovariance(table.connection, {
|
|
55
77
|
relation: prepared.relation,
|
|
@@ -66,14 +88,14 @@ async function execute(table, columns, referencePoint, newColumn, options) {
|
|
|
66
88
|
try {
|
|
67
89
|
const distance = `r.${quoteIdentifier(distances.distanceColumn)}`;
|
|
68
90
|
const outputs = [{ name: newColumn, expression: distance }];
|
|
69
|
-
if (
|
|
91
|
+
if (scoreColumn !== undefined) {
|
|
70
92
|
outputs.push({
|
|
71
|
-
name:
|
|
93
|
+
name: scoreColumn,
|
|
72
94
|
expression: `CASE WHEN max(${distance}) OVER () = 0 THEN 1::DOUBLE ELSE 1 - ${distance} / max(${distance}) OVER () END`,
|
|
73
95
|
});
|
|
74
96
|
}
|
|
75
97
|
await publishPreparedColumns(table, prepared, {
|
|
76
|
-
method: "
|
|
98
|
+
method: "similarityMahalanobis()",
|
|
77
99
|
parameters: { columns, referencePoint, newColumn, options },
|
|
78
100
|
result: {
|
|
79
101
|
relation: distances.relation,
|
|
@@ -60,6 +60,7 @@ async function executeUpdateWithJS(simpleTable, dataModifier, options) {
|
|
|
60
60
|
const accumulator = `updateWithJS_accumulator_${suffix}`;
|
|
61
61
|
try {
|
|
62
62
|
let first = true;
|
|
63
|
+
let accumulatorSchema;
|
|
63
64
|
let lastRowid = null;
|
|
64
65
|
let sawRows = false;
|
|
65
66
|
let outputOffset = 0;
|
|
@@ -131,9 +132,17 @@ async function executeUpdateWithJS(simpleTable, dataModifier, options) {
|
|
|
131
132
|
? parseDuckDBType("VARCHAR")
|
|
132
133
|
: source.types.get(key) ??
|
|
133
134
|
parseDuckDBType(added.types[newKeys.indexOf(key)]));
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
const schema = JSON.stringify(keys.map((key, i) => [key, columnTypes[i].toString()]));
|
|
136
|
+
// Append matching native batches directly. SQL still handles conversion
|
|
137
|
+
// and BY NAME alignment when a callback changes the batch schema.
|
|
138
|
+
const direct = outputGeometry.length === 0 && outputJSON.length === 0 &&
|
|
139
|
+
(first || schema === accumulatorSchema);
|
|
140
|
+
const destination = direct ? accumulator : scratch.name;
|
|
141
|
+
if (!direct || first) {
|
|
142
|
+
await simpleTable.sdb.customQuery(`CREATE OR REPLACE TABLE ${quoteIdentifier(destination)} (${keys.map((key, i) => `${quoteIdentifier(key)} ${columnTypes[i]}`)
|
|
143
|
+
.join(", ")})`);
|
|
144
|
+
}
|
|
145
|
+
await appendColumnBatches(simpleTable.connection, destination, columnTypes, modified.length, (column, start, end) => {
|
|
137
146
|
const key = keys[column];
|
|
138
147
|
return outputGeometry.includes(key)
|
|
139
148
|
? geometryData.get(key).slice(start, end)
|
|
@@ -146,7 +155,11 @@ async function executeUpdateWithJS(simpleTable, dataModifier, options) {
|
|
|
146
155
|
: outputJSON.includes(key)
|
|
147
156
|
? `${quoteIdentifier(key)}::JSON AS ${quoteIdentifier(key)}`
|
|
148
157
|
: quoteIdentifier(key)).join(", ");
|
|
149
|
-
if (
|
|
158
|
+
if (direct) {
|
|
159
|
+
accumulatorSchema = schema;
|
|
160
|
+
first = false;
|
|
161
|
+
}
|
|
162
|
+
else if (first) {
|
|
150
163
|
await simpleTable.sdb.customQuery(`CREATE OR REPLACE TABLE ${quoteIdentifier(accumulator)} AS SELECT ${projection} FROM ${quoteIdentifier(scratch.name)}`);
|
|
151
164
|
first = false;
|
|
152
165
|
}
|
|
@@ -159,7 +172,13 @@ async function executeUpdateWithJS(simpleTable, dataModifier, options) {
|
|
|
159
172
|
if (first) {
|
|
160
173
|
throw new Error("The dataModifier returned no rows. updateWithJS can't infer the table schema from zero rows.");
|
|
161
174
|
}
|
|
162
|
-
|
|
175
|
+
// Publish the completed ordinary table without copying its rows again.
|
|
176
|
+
// Qualify the creation namespace: a temporary table or a later search-path
|
|
177
|
+
// schema can shadow the name without being the destination of replacement.
|
|
178
|
+
const namespace = await simpleTable.connection.runAndReadAll("SELECT current_database(), current_schema()");
|
|
179
|
+
const prefix = namespace.getRows()[0].map((name) => quoteIdentifier(String(name))).join(".");
|
|
180
|
+
await simpleTable.sdb.customQuery(`DROP TABLE IF EXISTS ${prefix}.${quoteIdentifier(simpleTable.name)};
|
|
181
|
+
ALTER TABLE ${prefix}.${quoteIdentifier(accumulator)} RENAME TO ${quoteIdentifier(simpleTable.name)};`);
|
|
163
182
|
}
|
|
164
183
|
finally {
|
|
165
184
|
await simpleTable.sdb.customQuery(`DROP TABLE IF EXISTS ${quoteIdentifier(accumulator)};
|
package/llm.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# The Simple Data Analysis (Core) Library
|
|
2
2
|
|
|
3
3
|
- Package: `@nshiab/simple-data-analysis-core`
|
|
4
|
-
- Version: `2.1.
|
|
4
|
+
- Version: `2.1.4`
|
|
5
5
|
|
|
6
6
|
To install the library with Deno, use:
|
|
7
7
|
|
|
@@ -781,7 +781,9 @@ await table.setTypes({
|
|
|
781
781
|
Loads an array of JavaScript objects into the table. Types are inferred for
|
|
782
782
|
numbers, bigints, strings, booleans, and Date values. Array and object cells
|
|
783
783
|
require an explicit supported type in columnTypes. Types can also be specified
|
|
784
|
-
for scalar columns instead of inferred from their values.
|
|
784
|
+
for scalar columns instead of inferred from their values. Inferred bigints use
|
|
785
|
+
signed 64-bit `BIGINT`; values outside that range throw when written instead of
|
|
786
|
+
wrapping.
|
|
785
787
|
|
|
786
788
|
JavaScript `Date` values are inferred as DuckDB `TIMESTAMP` values. Their
|
|
787
789
|
instant is preserved, but JavaScript `Date` does not retain the timezone or
|
|
@@ -5714,16 +5716,23 @@ await table
|
|
|
5714
5716
|
.log();
|
|
5715
5717
|
```
|
|
5716
5718
|
|
|
5717
|
-
#### `
|
|
5719
|
+
#### `similarityMahalanobis`
|
|
5718
5720
|
|
|
5719
|
-
|
|
5720
|
-
stores it in a new DOUBLE column.
|
|
5721
|
-
|
|
5721
|
+
Measures numeric profile similarity using each row's Mahalanobis distance from a
|
|
5722
|
+
supplied reference point and stores it in a new DOUBLE column. Smaller distances
|
|
5723
|
+
indicate more similar profiles. Optionally adds a dataset-relative similarity
|
|
5724
|
+
score, where larger values mean more similar. Sample covariance (`n - 1`) is
|
|
5725
|
+
estimated from the dataset, independently of the reference point.
|
|
5726
|
+
|
|
5727
|
+
Accounts for differences in feature scales and correlations between features,
|
|
5728
|
+
making it useful for comparing profiles with measurements in different units.
|
|
5722
5729
|
|
|
5723
5730
|
Pass one numeric LIST or ARRAY column, or an array of numeric scalar columns.
|
|
5724
|
-
Reference
|
|
5725
|
-
|
|
5726
|
-
|
|
5731
|
+
Reference arrays follow the same dimension order. For scalar columns, a
|
|
5732
|
+
reference object supplies its own finite numeric values by column name; extra
|
|
5733
|
+
fields are ignored. Reference values are captured when this method is called.
|
|
5734
|
+
Inputs are converted privately to DOUBLE, which can lose precision for large
|
|
5735
|
+
integers and exact decimals; source columns and types remain unchanged.
|
|
5727
5736
|
|
|
5728
5737
|
Requires more rows than dimensions and finite, non-null, consistent features
|
|
5729
5738
|
with invertible, numerically stable covariance. Invalid inputs leave the source
|
|
@@ -5732,20 +5741,22 @@ unchanged.
|
|
|
5732
5741
|
##### Signature
|
|
5733
5742
|
|
|
5734
5743
|
```typescript
|
|
5735
|
-
|
|
5744
|
+
similarityMahalanobis(columns: string | string[], referencePoint: number[] | Record<string, unknown>, newColumn: string, options?: { similarityScoreColumn?: string | boolean }): this;
|
|
5736
5745
|
```
|
|
5737
5746
|
|
|
5738
5747
|
##### Parameters
|
|
5739
5748
|
|
|
5740
5749
|
- **`columns`**: A numeric vector column, or numeric scalar columns in feature
|
|
5741
5750
|
order.
|
|
5742
|
-
- **`referencePoint`**:
|
|
5743
|
-
|
|
5751
|
+
- **`referencePoint`**: An array of finite numbers in feature order, or an
|
|
5752
|
+
object with an own finite numeric value for each scalar feature column; may be
|
|
5753
|
+
outside the dataset.
|
|
5744
5754
|
- **`newColumn`**: The name of the new DOUBLE distance column.
|
|
5745
5755
|
- **`options`**: Optional output settings.
|
|
5746
|
-
- **`options.similarityScoreColumn`**: A
|
|
5747
|
-
|
|
5748
|
-
|
|
5756
|
+
- **`options.similarityScoreColumn`**: A custom name, or true for a new DOUBLE
|
|
5757
|
+
column named "similarity"; false or omitted adds no score. The
|
|
5758
|
+
dataset-relative score is `1 - distance / maxDistance`. Exact matches score 1
|
|
5759
|
+
and the farthest rows score 0; if all distances are zero, every score is 1.
|
|
5749
5760
|
|
|
5750
5761
|
##### Returns
|
|
5751
5762
|
|
|
@@ -5756,19 +5767,30 @@ The table, so methods can be chained.
|
|
|
5756
5767
|
```ts
|
|
5757
5768
|
// Measure distance from a reference height and weight.
|
|
5758
5769
|
await table
|
|
5759
|
-
.
|
|
5770
|
+
.similarityMahalanobis(["height", "weight"], [175, 70], "distance")
|
|
5760
5771
|
.log();
|
|
5761
5772
|
```
|
|
5762
5773
|
|
|
5763
5774
|
```ts
|
|
5764
5775
|
// Compare feature vectors and add a dataset-relative similarity score.
|
|
5765
5776
|
await table
|
|
5766
|
-
.
|
|
5777
|
+
.similarityMahalanobis("features", [175, 70], "distance", {
|
|
5767
5778
|
similarityScoreColumn: "similarity",
|
|
5768
5779
|
})
|
|
5769
5780
|
.log();
|
|
5770
5781
|
```
|
|
5771
5782
|
|
|
5783
|
+
```ts
|
|
5784
|
+
// Compare profiles directly with a row and use the default score column.
|
|
5785
|
+
const reference = await table.getFirstRow();
|
|
5786
|
+
if (!reference) throw new Error("The table is empty.");
|
|
5787
|
+
await table
|
|
5788
|
+
.similarityMahalanobis(["height", "weight"], reference, "distance", {
|
|
5789
|
+
similarityScoreColumn: true,
|
|
5790
|
+
})
|
|
5791
|
+
.log();
|
|
5792
|
+
```
|
|
5793
|
+
|
|
5772
5794
|
#### `unnest`
|
|
5773
5795
|
|
|
5774
5796
|
Unnests (expands) rows by splitting a column's string values into multiple rows
|
|
@@ -7028,7 +7050,9 @@ array of objects. This method offers high flexibility for data manipulation but
|
|
|
7028
7050
|
can be slow for large tables as it involves transferring data between DuckDB and
|
|
7029
7051
|
JavaScript. Before writing a JavaScript callback, check for an existing SDA
|
|
7030
7052
|
method that performs the same operation; it will usually be faster and more
|
|
7031
|
-
efficient.
|
|
7053
|
+
efficient. Existing integer and enum columns retain their types. Fractional or
|
|
7054
|
+
out-of-range integers and unknown enum members throw when written. The original
|
|
7055
|
+
table is replaced after all callback results have been converted successfully.
|
|
7032
7056
|
|
|
7033
7057
|
If the table has geometry columns, the callback can read and modify their
|
|
7034
7058
|
GeoJSON geometry objects directly. Extra properties added to these objects are
|
package/llms.txt
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> Lightweight DuckDB-powered TypeScript library for tabular, SQL, CSV, Parquet, and geospatial data analysis on Deno, Node.js, and Bun.
|
|
4
4
|
|
|
5
5
|
- Package: `@nshiab/simple-data-analysis-core`
|
|
6
|
-
- Version: `2.1.
|
|
6
|
+
- Version: `2.1.4`
|
|
7
7
|
|
|
8
8
|
Install with Deno: `deno add jsr:@nshiab/simple-data-analysis-core`
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nshiab/simple-data-analysis-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "Lightweight DuckDB-powered TypeScript library for tabular, SQL, CSV, Parquet, and geospatial data analysis on Deno, Node.js, and Bun.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-analysis",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@duckdb/node-api": "1.5.5-r.
|
|
42
|
+
"@duckdb/node-api": "1.5.5-r.5"
|
|
43
43
|
},
|
|
44
44
|
"_generatedBy": "dnt@dev"
|
|
45
45
|
}
|
|
@@ -4,4 +4,15 @@ declare global {
|
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
export {};
|
|
7
|
+
declare global {
|
|
8
|
+
interface Object {
|
|
9
|
+
/**
|
|
10
|
+
* Determines whether an object has a property with the specified name.
|
|
11
|
+
* @param o An object.
|
|
12
|
+
* @param v A property name.
|
|
13
|
+
*/
|
|
14
|
+
hasOwn(o: object, v: PropertyKey): boolean;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
7
18
|
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AAgBV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC"}
|
package/script/_dnt.polyfills.js
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
4
|
+
if (!Object.hasOwn) {
|
|
5
|
+
Object.defineProperty(Object, "hasOwn", {
|
|
6
|
+
value: function (object, property) {
|
|
7
|
+
if (object == null) {
|
|
8
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
9
|
+
}
|
|
10
|
+
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
11
|
+
},
|
|
12
|
+
configurable: true,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
writable: true,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimpleDB.d.ts","sourceRoot":"","sources":["../../src/class/SimpleDB.ts"],"names":[],"mappings":"AAGA,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAG3C,OAAO,MAAM,MAAM,aAAa,CAAC;AA6BjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,MAAM,CAAC,OAAO,OAAO,QAAQ,CAAC,KAAK,SAAS,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MvD;;;;;;;;;;;;OAYG;IACG,aAAa,IAAI,OAAO,CAC5B;QACE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,EAAE,CACJ;IAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,WAAW,CACf,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QACP,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;KACX,GACL,OAAO,CACN;QACA,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,EAAE,GACD,IAAI,CACP;IAaD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IACG,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAO,GACxD,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;IAU9B;;;;;;;;;;;;;;;OAeG;IACG,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC;CA8GjC"}
|
package/script/class/SimpleDB.js
CHANGED
|
@@ -1102,6 +1102,7 @@ _SimpleDB_closePromise = new WeakMap(), _SimpleDB_startPromise = new WeakMap(),
|
|
|
1102
1102
|
(0, queueOp_js_1.discardAllPending)(this);
|
|
1103
1103
|
}
|
|
1104
1104
|
const cleanupErrors = [];
|
|
1105
|
+
const cacheCleanupMessages = [];
|
|
1105
1106
|
if (this.db instanceof node_api_1.DuckDBInstance) {
|
|
1106
1107
|
try {
|
|
1107
1108
|
this.connection.closeSync();
|
|
@@ -1122,25 +1123,15 @@ _SimpleDB_closePromise = new WeakMap(), _SimpleDB_startPromise = new WeakMap(),
|
|
|
1122
1123
|
if ((0, node_fs_1.existsSync)(tmpDir)) {
|
|
1123
1124
|
(0, node_fs_1.rmSync)(tmpDir, { recursive: true });
|
|
1124
1125
|
}
|
|
1125
|
-
|
|
1126
|
+
// Defer cache logs until after the summary, while timing cleanup too.
|
|
1127
|
+
(0, cleanCache_js_1.default)(this, (message) => cacheCleanupMessages.push(message));
|
|
1126
1128
|
}
|
|
1127
1129
|
catch (error) {
|
|
1128
1130
|
cleanupErrors.push(error);
|
|
1129
1131
|
}
|
|
1130
1132
|
this.lifecycleState = "closed";
|
|
1131
|
-
if (operationError
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
if (operationError !== undefined) {
|
|
1135
|
-
throw operationError;
|
|
1136
|
-
}
|
|
1137
|
-
if (cleanupErrors.length === 1) {
|
|
1138
|
-
throw cleanupErrors[0];
|
|
1139
|
-
}
|
|
1140
|
-
if (cleanupErrors.length > 1) {
|
|
1141
|
-
throw new AggregateError(cleanupErrors, "Multiple errors occurred while cleaning up the database.", { cause: cleanupErrors[0] });
|
|
1142
|
-
}
|
|
1143
|
-
if (typeof this.durationStart === "number") {
|
|
1133
|
+
if (operationError === undefined && cleanupErrors.length === 0 &&
|
|
1134
|
+
typeof this.durationStart === "number") {
|
|
1144
1135
|
let string = (0, prettyDuration_js_1.default)(this.durationStart, {
|
|
1145
1136
|
prefix: "\n\nSimpleDB ran for ",
|
|
1146
1137
|
});
|
|
@@ -1156,6 +1147,24 @@ _SimpleDB_closePromise = new WeakMap(), _SimpleDB_startPromise = new WeakMap(),
|
|
|
1156
1147
|
}
|
|
1157
1148
|
console.log(`${string}\n`);
|
|
1158
1149
|
}
|
|
1150
|
+
for (const message of cacheCleanupMessages) {
|
|
1151
|
+
console.log(message);
|
|
1152
|
+
}
|
|
1153
|
+
if (cacheCleanupMessages.length > 0) {
|
|
1154
|
+
console.log();
|
|
1155
|
+
}
|
|
1156
|
+
if (operationError !== undefined && cleanupErrors.length > 0) {
|
|
1157
|
+
throw new AggregateError([operationError, ...cleanupErrors], "Pending execution and database cleanup both failed.", { cause: operationError });
|
|
1158
|
+
}
|
|
1159
|
+
if (operationError !== undefined) {
|
|
1160
|
+
throw operationError;
|
|
1161
|
+
}
|
|
1162
|
+
if (cleanupErrors.length === 1) {
|
|
1163
|
+
throw cleanupErrors[0];
|
|
1164
|
+
}
|
|
1165
|
+
if (cleanupErrors.length > 1) {
|
|
1166
|
+
throw new AggregateError(cleanupErrors, "Multiple errors occurred while cleaning up the database.", { cause: cleanupErrors[0] });
|
|
1167
|
+
}
|
|
1159
1168
|
return await this;
|
|
1160
1169
|
};
|
|
1161
1170
|
exports.default = SimpleDB;
|
|
@@ -193,6 +193,8 @@ export default class SimpleTable extends Simple {
|
|
|
193
193
|
* numbers, bigints, strings, booleans, and Date values. Array and object cells
|
|
194
194
|
* require an explicit supported type in columnTypes. Types can also be
|
|
195
195
|
* specified for scalar columns instead of inferred from their values.
|
|
196
|
+
* Inferred bigints use signed 64-bit `BIGINT`; values outside that range throw
|
|
197
|
+
* when written instead of wrapping.
|
|
196
198
|
*
|
|
197
199
|
* JavaScript `Date` values are inferred as DuckDB `TIMESTAMP` values. Their
|
|
198
200
|
* instant is preserved, but JavaScript `Date` does not retain the timezone or
|
|
@@ -4233,13 +4235,22 @@ export default class SimpleTable extends Simple {
|
|
|
4233
4235
|
normalization?: "dimensionMinMax" | "rowL2";
|
|
4234
4236
|
}): this;
|
|
4235
4237
|
/**
|
|
4236
|
-
*
|
|
4237
|
-
* and stores it in a new DOUBLE column.
|
|
4238
|
-
*
|
|
4238
|
+
* Measures numeric profile similarity using each row's Mahalanobis distance
|
|
4239
|
+
* from a supplied reference point and stores it in a new DOUBLE column.
|
|
4240
|
+
* Smaller distances indicate more similar profiles. Optionally adds a
|
|
4241
|
+
* dataset-relative similarity score, where larger values mean more similar.
|
|
4242
|
+
* Sample covariance (`n - 1`) is estimated from the dataset, independently
|
|
4243
|
+
* of the reference point.
|
|
4244
|
+
*
|
|
4245
|
+
* Accounts for differences in feature scales and correlations between features,
|
|
4246
|
+
* making it useful for comparing profiles with measurements in different units.
|
|
4239
4247
|
*
|
|
4240
4248
|
* Pass one numeric LIST or ARRAY column, or an array of numeric scalar columns.
|
|
4241
|
-
* Reference
|
|
4242
|
-
*
|
|
4249
|
+
* Reference arrays follow the same dimension order. For scalar columns, a
|
|
4250
|
+
* reference object supplies its own finite numeric values by column name; extra
|
|
4251
|
+
* fields are ignored. Reference values are captured when this method is called.
|
|
4252
|
+
* Inputs are converted privately to DOUBLE, which can lose precision for large
|
|
4253
|
+
* integers and exact
|
|
4243
4254
|
* decimals; source columns and types remain unchanged.
|
|
4244
4255
|
*
|
|
4245
4256
|
* Requires more rows than dimensions and finite, non-null, consistent features
|
|
@@ -4250,7 +4261,7 @@ export default class SimpleTable extends Simple {
|
|
|
4250
4261
|
* ```ts
|
|
4251
4262
|
* // Measure distance from a reference height and weight.
|
|
4252
4263
|
* await table
|
|
4253
|
-
* .
|
|
4264
|
+
* .similarityMahalanobis(["height", "weight"], [175, 70], "distance")
|
|
4254
4265
|
* .log();
|
|
4255
4266
|
* ```
|
|
4256
4267
|
*
|
|
@@ -4258,23 +4269,37 @@ export default class SimpleTable extends Simple {
|
|
|
4258
4269
|
* ```ts
|
|
4259
4270
|
* // Compare feature vectors and add a dataset-relative similarity score.
|
|
4260
4271
|
* await table
|
|
4261
|
-
* .
|
|
4272
|
+
* .similarityMahalanobis("features", [175, 70], "distance", {
|
|
4262
4273
|
* similarityScoreColumn: "similarity",
|
|
4263
4274
|
* })
|
|
4264
4275
|
* .log();
|
|
4265
4276
|
* ```
|
|
4277
|
+
*
|
|
4278
|
+
* @example
|
|
4279
|
+
* ```ts
|
|
4280
|
+
* // Compare profiles directly with a row and use the default score column.
|
|
4281
|
+
* const reference = await table.getFirstRow();
|
|
4282
|
+
* if (!reference) throw new Error("The table is empty.");
|
|
4283
|
+
* await table
|
|
4284
|
+
* .similarityMahalanobis(["height", "weight"], reference, "distance", {
|
|
4285
|
+
* similarityScoreColumn: true,
|
|
4286
|
+
* })
|
|
4287
|
+
* .log();
|
|
4288
|
+
* ```
|
|
4266
4289
|
* @param columns - A numeric vector column, or numeric scalar columns in feature order.
|
|
4267
|
-
* @param referencePoint -
|
|
4290
|
+
* @param referencePoint - An array of finite numbers in feature order, or an object with an own finite numeric value for each scalar feature column; may be outside the dataset.
|
|
4268
4291
|
* @param newColumn - The name of the new DOUBLE distance column.
|
|
4269
4292
|
* @param options - Optional output settings.
|
|
4270
|
-
* @param options.similarityScoreColumn - A new DOUBLE column
|
|
4271
|
-
* score `1 - distance / maxDistance`. Exact matches score 1 and the farthest
|
|
4293
|
+
* @param options.similarityScoreColumn - A custom name, or true for a new DOUBLE column named "similarity"; false or omitted adds no score. The dataset-relative
|
|
4294
|
+
* score is `1 - distance / maxDistance`. Exact matches score 1 and the farthest
|
|
4272
4295
|
* rows score 0; if all distances are zero, every score is 1.
|
|
4273
4296
|
* @returns The table, so methods can be chained.
|
|
4274
4297
|
* @category Analyzing Data
|
|
4275
4298
|
*/
|
|
4276
|
-
|
|
4277
|
-
|
|
4299
|
+
similarityMahalanobis(columns: string | string[], referencePoint: number[] | {
|
|
4300
|
+
[key: string]: unknown;
|
|
4301
|
+
}, newColumn: string, options?: {
|
|
4302
|
+
similarityScoreColumn?: string | boolean;
|
|
4278
4303
|
}): this;
|
|
4279
4304
|
/**
|
|
4280
4305
|
* Unnests (expands) rows by splitting a column's string values into multiple rows based on a separator.
|
|
@@ -5278,6 +5303,10 @@ export default class SimpleTable extends Simple {
|
|
|
5278
5303
|
* This method offers high flexibility for data manipulation but can be slow for large tables as it involves transferring data between DuckDB and JavaScript.
|
|
5279
5304
|
* Before writing a JavaScript callback, check for an existing SDA method that
|
|
5280
5305
|
* performs the same operation; it will usually be faster and more efficient.
|
|
5306
|
+
* Existing integer and enum columns retain their types. Fractional or
|
|
5307
|
+
* out-of-range integers and unknown enum members throw when written. The
|
|
5308
|
+
* original table is replaced after all callback results have been converted
|
|
5309
|
+
* successfully.
|
|
5281
5310
|
*
|
|
5282
5311
|
* If the table has geometry columns, the callback can read and modify their
|
|
5283
5312
|
* GeoJSON geometry objects directly. Extra properties added to these objects
|