databonk 0.0.4 → 0.2.1

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 (45) hide show
  1. package/README.md +491 -96
  2. package/dist/dataframe-Bz1B7bIr.d.cts +1001 -0
  3. package/dist/dataframe-Bz1B7bIr.d.ts +1001 -0
  4. package/dist/index.cjs +5 -0
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.cts +366 -0
  7. package/dist/index.d.ts +354 -31
  8. package/dist/index.js +4 -40
  9. package/dist/index.js.map +1 -1
  10. package/dist/parallel-fv5h4BkA.d.cts +152 -0
  11. package/dist/parallel-fv5h4BkA.d.ts +152 -0
  12. package/dist/parquet.cjs +3 -0
  13. package/dist/parquet.cjs.map +1 -0
  14. package/dist/parquet.d.cts +57 -0
  15. package/dist/parquet.d.ts +57 -0
  16. package/dist/parquet.js +3 -0
  17. package/dist/parquet.js.map +1 -0
  18. package/dist/scalar.wasm +0 -0
  19. package/dist/simd-threads.wasm +0 -0
  20. package/dist/simd.wasm +0 -0
  21. package/dist/workers.cjs +102 -0
  22. package/dist/workers.cjs.map +1 -0
  23. package/dist/workers.d.cts +74 -0
  24. package/dist/workers.d.ts +74 -0
  25. package/dist/workers.js +102 -0
  26. package/dist/workers.js.map +1 -0
  27. package/package.json +93 -32
  28. package/build/release.d.ts +0 -719
  29. package/build/release.js +0 -774
  30. package/build/release.wasm +0 -0
  31. package/build/release.wasm.map +0 -1
  32. package/build/release.wat +0 -22633
  33. package/dist/dataframe.d.ts +0 -82
  34. package/dist/dataframe.d.ts.map +0 -1
  35. package/dist/dataframe.js +0 -318
  36. package/dist/dataframe.js.map +0 -1
  37. package/dist/index.d.ts.map +0 -1
  38. package/dist/loader.d.ts +0 -86
  39. package/dist/loader.d.ts.map +0 -1
  40. package/dist/loader.js +0 -147
  41. package/dist/loader.js.map +0 -1
  42. package/dist/shared-memory.d.ts +0 -64
  43. package/dist/shared-memory.d.ts.map +0 -1
  44. package/dist/shared-memory.js +0 -113
  45. package/dist/shared-memory.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,41 +1,5 @@
1
- /**
2
- * Databonk - High-performance DataFrame library
3
- *
4
- * A DataFrame library built with AssemblyScript and WASM,
5
- * featuring SIMD acceleration and SharedArrayBuffer support
6
- * for zero-copy data access.
7
- */
8
- export { loadDatabonk, isSharedArrayBufferSupported } from './loader';
9
- export { DatabonkDataFrame, GroupByBuilder } from './dataframe';
10
- export { ColumnType, ColumnView, getColumnTypeSize, createTypedArrayView, allocateAndCopy, copyToWasm, createSharedView } from './shared-memory';
11
- /**
12
- * Quick start example:
13
- *
14
- * ```typescript
15
- * import { loadDatabonk, DatabonkDataFrame } from 'databonk';
16
- *
17
- * // Load the WASM module
18
- * const module = await loadDatabonk();
19
- *
20
- * // Create a DataFrame from typed arrays
21
- * const df = await DatabonkDataFrame.fromTypedArrays(module, [
22
- * { name: 'id', data: new Int32Array([1, 2, 3, 4, 5]) },
23
- * { name: 'value', data: new Float32Array([1.5, 2.5, 3.5, 4.5, 5.5]) },
24
- * ]);
25
- *
26
- * // Aggregations
27
- * console.log('Sum:', df.sum('value'));
28
- * console.log('Mean:', df.mean('value'));
29
- *
30
- * // Column math
31
- * df.scalarMul('value', 2.0, 'doubled');
32
- *
33
- * // Zero-copy column access
34
- * const view = df.getColumnView('value');
35
- * console.log('First value:', view?.get(0));
36
- *
37
- * // Cleanup
38
- * df.free();
39
- * ```
40
- */
1
+ var Hn=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]);function Vt(){try{return WebAssembly.validate(Hn)}catch{return false}}var Kn=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;async function Yn(e,t){if(Kn){let[{readFile:i},{fileURLToPath:s}]=await Promise.all([import('fs/promises'),import('url')]),a;if(t===void 0)a=s(new URL(e,import.meta.url));else if(t instanceof URL)a=s(new URL(e,t));else if(t.startsWith("file:"))a=s(new URL(e,t));else {let{join:l}=await import('path');a=l(t,e);}return await i(a)}let n=t??new URL(".",import.meta.url),r=new URL(e,n),o=await fetch(r);if(!o.ok)throw new Error(`Failed to fetch wasm at ${r.toString()}: ${o.status}`);return await o.arrayBuffer()}async function Jn(e={}){let t=e.simd??Vt(),r=await Yn(t?"simd.wasm":"scalar.wasm",e.wasmDir),{instance:o}=await WebAssembly.instantiate(r,{}),i=o.exports;return {memory:i.memory,alloc:i.alloc,free:i.free,realloc:i.realloc,mem_generation:i.mem_generation,simd:t}}function Gn(e){switch(e){case "f64":return Float64Array;case "f32":return Float32Array;case "i32":return Int32Array;case "u32":return Uint32Array;case "i64":return BigInt64Array;case "u8":case "bool":return Uint8Array}}function Ne(e){return `${e.dtype}:${e.ptr}:${e.length}`}function ae(e){let t=-1,n=null,r=new Map,o=new Map;function i(l){let u=Gn(l.dtype);return new u(e.memory.buffer,l.ptr,l.length)}function s(){let l=e.mem_generation();if(l!==t||n!==e.memory.buffer){t=l,n=e.memory.buffer,o.clear();for(let[u,c]of r)o.set(u,i(c));}}let a=(l=>{let u=Ne(l);r.has(u)||r.set(u,l),s();let c=o.get(u);return c===void 0&&(c=i(l),o.set(u,c)),c});return a.generation=()=>t,a.forget=l=>{let u=Ne(l);r.delete(u),o.delete(u);},a.clear=()=>{r.clear(),o.clear(),t=-1,n=null;},a}function le(e){return {mod:e,viewOf:ae(e)}}var C={f64:{name:"f64",size:8,view:"f64",ctor:Float64Array,wasm:"f64",float:true},f32:{name:"f32",size:4,view:"f32",ctor:Float32Array,wasm:"f32",float:true},i32:{name:"i32",size:4,view:"i32",ctor:Int32Array,wasm:"i32",float:false},u32:{name:"u32",size:4,view:"u32",ctor:Uint32Array,wasm:"u32",float:false},bool:{name:"bool",size:1,view:"bool",ctor:Uint8Array,wasm:"bool",float:false},utf8:{name:"utf8",size:4,view:"i32",ctor:Int32Array,wasm:"utf8",float:false},i64:{name:"i64",size:8,view:"i64",ctor:BigInt64Array,wasm:"i64",float:false},date32:{name:"date32",size:4,view:"i32",ctor:Int32Array,wasm:"i32",float:false},timestamp:{name:"timestamp",size:8,view:"i64",ctor:BigInt64Array,wasm:"i64",float:false}};function Zn(e){let t=C[e];if(t===void 0)throw new Error(`unknown dtype: ${String(e)}`);return t}function v(e){return e+7>>3}function T(e,t){return (e[t>>3]&1<<(t&7))!==0}function S(e,t){let n=t>>3;e[n]=(e[n]??0)|1<<(t&7);}function Qn(e,t){let n=t>>3;e[n]=(e[n]??0)&~(1<<(t&7));}var Xn=new TextEncoder,tr=new TextDecoder,ue=new WeakMap;function er(e){let t=ue.get(e);return t===void 0&&(t={slots:new Array(e.count),stats:{hits:0,misses:0}},ue.set(e,t)),t}function ct(e,t){let n=t.length,r=t.map(c=>Xn.encode(c)),o=0;for(let c of r)o+=c.length;let i=e.mod.alloc((n+1)*4),s=e.mod.alloc(o),a=e.viewOf({ptr:i,length:n+1,dtype:"i32"}),l=e.viewOf({ptr:s,length:o,dtype:"u8"});a[0]=0;let u=0;for(let c=0;c<n;c++){let f=r[c];l.set(f,u),u+=f.length,a[c+1]=u;}return {count:n,offsetsPtr:i,bytesPtr:s,bytesLen:o}}function Nt(e,t,n,r){let o=r>0?n[r]??0:0,i=e.mod.alloc((r+1)*4),s=e.mod.alloc(o);return e.viewOf({ptr:i,length:r+1,dtype:"i32"}).set(n.subarray(0,r+1)),o>0&&e.viewOf({ptr:s,length:o,dtype:"u8"}).set(t.subarray(0,o)),{count:r,offsetsPtr:i,bytesPtr:s,bytesLen:o}}function q(e,t,n){let r=er(t),o=r.slots[n];if(o!==void 0)return r.stats.hits++,o;r.stats.misses++;let i=e.viewOf({ptr:t.offsetsPtr,length:t.count+1,dtype:"i32"}),s=i[n],a=i[n+1],l;if(a<=s)l="";else {let u=e.viewOf({ptr:t.bytesPtr,length:t.bytesLen,dtype:"u8"});l=tr.decode(u.subarray(s,a));}return r.slots[n]=l,l}function W(e,t){let n=new Array(t.count);for(let r=0;r<t.count;r++)n[r]=q(e,t,r);return n}function nr(e){let t=ue.get(e);return t===void 0?{hits:0,misses:0}:{...t.stats}}function rr(e,t,n){let r=W(e,t),o=W(e,n),i=[],s=new Map,a=c=>{let f=s.get(c);return f===void 0&&(f=i.length,i.push(c),s.set(c,f)),f},l=new Int32Array(r.length),u=new Int32Array(o.length);for(let c=0;c<r.length;c++)l[c]=a(r[c]);for(let c=0;c<o.length;c++)u[c]=a(o[c]);return {merged:i,remapA:l,remapB:u}}function ce(e,t){e.viewOf.forget({ptr:t.offsetsPtr,length:t.count+1,dtype:"i32"}),e.viewOf.forget({ptr:t.bytesPtr,length:t.bytesLen,dtype:"u8"}),e.mod.free(t.offsetsPtr),e.mod.free(t.bytesPtr);}function Q(e){return e==null}function X(e,t,n,r,o,i){return {dtype:e,length:t,dataPtr:n,validityPtr:r,validityBitOffset:0,dict:o,owned:true,...i!==void 0?{tz:i}:{}}}function P(e,t,n,r){return t==="utf8"?ur(e,n):t==="bool"?sr(e,n):t==="i64"?ar(e,n):t==="timestamp"||t==="date32"?lr(e,t,n,r):ir(e,t,n)}function or(e,t){switch(e){case "f64":return t instanceof Float64Array;case "f32":return t instanceof Float32Array;case "i32":return t instanceof Int32Array;case "u32":return t instanceof Uint32Array;default:return false}}function ir(e,t,n){let r=C[t],o=n.length;if(or(t,n)){let c=e.mod.alloc(o*r.size);return e.viewOf({ptr:c,length:o,dtype:r.view}).set(n),X(t,o,c,0,null)}let i=0;for(let c=0;c<o;c++)Q(n[c])&&i++;let s=e.mod.alloc(o*r.size),a=i>0?e.mod.alloc(v(o)):0,l=e.viewOf({ptr:s,length:o,dtype:r.view}),u=null;a!==0&&(u=e.viewOf({ptr:a,length:v(o),dtype:"u8"}),u.fill(0));for(let c=0;c<o;c++){let f=n[c];Q(f)?l[c]=0:(l[c]=f,u&&S(u,c));}return X(t,o,s,a,null)}function sr(e,t){let n=t.length;if(t instanceof Uint8Array){let l=e.mod.alloc(n);return e.viewOf({ptr:l,length:n,dtype:"bool"}).set(t),X("bool",n,l,0,null)}let r=0;for(let l=0;l<n;l++)Q(t[l])&&r++;let o=e.mod.alloc(n),i=r>0?e.mod.alloc(v(n)):0,s=e.viewOf({ptr:o,length:n,dtype:"bool"}),a=null;i!==0&&(a=e.viewOf({ptr:i,length:v(n),dtype:"u8"}),a.fill(0));for(let l=0;l<n;l++){let u=t[l];Q(u)?s[l]=0:(s[l]=u?1:0,a&&S(a,l));}return X("bool",n,o,i,null)}function ar(e,t){let n=t.length;if(t instanceof BigInt64Array){let l=e.mod.alloc(n*8);return e.viewOf({ptr:l,length:n,dtype:"i64"}).set(t),X("i64",n,l,0,null)}let r=0;for(let l=0;l<n;l++){let u=t[l];if(Q(u)){r++;continue}if(typeof u=="number"){if(!Number.isInteger(u))throw new RangeError(`i64 column: non-integer number ${u} at index ${l} \u2014 use BigInt or null`);if(!Number.isSafeInteger(u))throw new RangeError(`i64 column: unsafe integer ${u} at index ${l} \u2014 use BigInt (e.g. ${u}n)`)}}let o=e.mod.alloc(n*8),i=r>0?e.mod.alloc(v(n)):0,s=e.viewOf({ptr:o,length:n,dtype:"i64"}),a=null;i!==0&&(a=e.viewOf({ptr:i,length:v(n),dtype:"u8"}),a.fill(0));for(let l=0;l<n;l++){let u=t[l];Q(u)?s[l]=0n:(s[l]=typeof u=="bigint"?u:BigInt(u),a&&S(a,l));}return X("i64",n,o,i,null)}function lr(e,t,n,r){let o=t==="timestamp",i=o?8:4,s=n.length,a=o?"i64":"i32";if(o?n instanceof BigInt64Array:n instanceof Int32Array){let d=e.mod.alloc(Math.max(s*i,1));return e.viewOf({ptr:d,length:s,dtype:a}).set(n),X(t,s,d,0,null,r)}let l=0;for(let d=0;d<s;d++)Q(n[d])&&l++;let u=e.mod.alloc(Math.max(s*i,1)),c=l>0?e.mod.alloc(v(s)):0,f=e.viewOf({ptr:u,length:s,dtype:a}),m=null;c&&(m=e.viewOf({ptr:c,length:v(s),dtype:"u8"}),m.fill(0));for(let d=0;d<s;d++){let p=n[d];Q(p)?f[d]=o?0n:0:(f[d]=o?typeof p=="bigint"?p:BigInt(p):p,m&&S(m,d));}return X(t,s,u,c,null,r)}function ur(e,t){let n=t.length,r=new Map,o=[],i=new Int32Array(n),s=new Uint8Array(n),a=0;for(let m=0;m<n;m++){let d=t[m];if(Q(d))a++,s[m]=1,i[m]=0;else {let p=d,h=r.get(p);h===void 0&&(h=o.length,o.push(p),r.set(p,h)),i[m]=h;}}let l=e.mod.alloc(n*4),u=a>0?e.mod.alloc(v(n)):0,c=ct(e,o);if(e.viewOf({ptr:l,length:n,dtype:"i32"}).set(i),u!==0){let m=e.viewOf({ptr:u,length:v(n),dtype:"u8"});m.fill(0);for(let d=0;d<n;d++)s[d]===0&&S(m,d);}return X("utf8",n,l,u,c)}function K(e,t){let{length:n,validityPtr:r,validityBitOffset:o}=t,i=r===0?null:e.viewOf({ptr:r,length:v(o+n),dtype:"u8"}),s=new Array(n);if(t.dtype==="utf8"){let c=e.viewOf({ptr:t.dataPtr,length:n,dtype:"i32"}),f=t.dict;for(let m=0;m<n;m++)s[m]=i&&!T(i,o+m)?null:q(e,f,c[m]);return s}if(t.dtype==="i64"||t.dtype==="timestamp"){let c=e.viewOf({ptr:t.dataPtr,length:n,dtype:"i64"});for(let f=0;f<n;f++)s[f]=i&&!T(i,o+f)?null:c[f];return s}if(t.dtype==="date32"){let c=e.viewOf({ptr:t.dataPtr,length:n,dtype:"i32"});for(let f=0;f<n;f++)s[f]=i&&!T(i,o+f)?null:c[f];return s}let a=C[t.dtype],l=e.viewOf({ptr:t.dataPtr,length:n,dtype:a.view}),u=t.dtype==="bool";for(let c=0;c<n;c++)i&&!T(i,o+c)?s[c]=null:s[c]=u?l[c]!==0:l[c];return s}function $t(e,t,n){let r=Math.max(0,Math.min(t,e.length)),i=Math.max(r,Math.min(n,e.length))-r,s=C[e.dtype].size;return {dtype:e.dtype,length:i,dataPtr:e.dataPtr+r*s,validityPtr:e.validityPtr,validityBitOffset:e.validityBitOffset+r,dict:e.dict,owned:false,...e.tz!==void 0?{tz:e.tz}:{}}}function Y(e,t){if(!t.owned)return;let n=C[t.dtype];e.viewOf.forget({ptr:t.dataPtr,length:t.length,dtype:n.view}),e.mod.free(t.dataPtr),t.validityPtr!==0&&(e.viewOf.forget({ptr:t.validityPtr,length:v(t.validityBitOffset+t.length),dtype:"u8"}),e.mod.free(t.validityPtr)),t.dict!==null&&ce(e,t.dict);}function At(e){return e instanceof _?e:$e(e)}var _=class e{node;constructor(t){this.node=Object.freeze(t),Object.freeze(this);}add(t){return vt("add",this,t)}sub(t){return vt("sub",this,t)}mul(t){return vt("mul",this,t)}div(t){return vt("div",this,t)}mod(t){return vt("mod",this,t)}neg(){return new e({kind:"neg",operand:this})}gt(t){return ft("gt",this,t)}ge(t){return ft("ge",this,t)}lt(t){return ft("lt",this,t)}le(t){return ft("le",this,t)}eq(t){return ft("eq",this,t)}ne(t){return ft("ne",this,t)}and(t){return new e({kind:"bool",op:"and",left:this,right:At(t)})}or(t){return new e({kind:"bool",op:"or",left:this,right:At(t)})}not(){return new e({kind:"not",operand:this})}isNull(){return new e({kind:"isNull",operand:this})}notNull(){return this.isNull().not()}fillNull(t){return new e({kind:"fillNull",operand:this,value:t})}cast(t){return new e({kind:"cast",operand:this,to:t})}sum(){return J("sum",this)}mean(){return J("mean",this)}min(){return J("min",this)}max(){return J("max",this)}count(){return J("count",this)}nunique(){return J("nunique",this)}std(){return J("std",this)}var(){return J("var",this)}first(){return J("first",this)}last(){return J("last",this)}get dt(){return new Lt(this)}get str(){return new jt(this)}toString(){return M(this.node)}},Lt=class{constructor(t){this.operand=t;}operand;year(){return G("year",this.operand)}month(){return G("month",this.operand)}day(){return G("day",this.operand)}hour(){return G("hour",this.operand)}minute(){return G("minute",this.operand)}second(){return G("second",this.operand)}millisecond(){return G("millisecond",this.operand)}weekday(){return G("weekday",this.operand)}dayOfYear(){return G("dayOfYear",this.operand)}quarter(){return G("quarter",this.operand)}},jt=class{constructor(t){this.operand=t;}operand;slice(t,n){return new _({kind:"strSlice",operand:this.operand,start:t,end:n})}};function cr(e){return new _({kind:"col",name:e})}function $e(e,t){return new _({kind:"lit",value:e,dtype:t??null})}function vt(e,t,n){return new _({kind:"arith",op:e,left:t,right:At(n)})}function ft(e,t,n){return new _({kind:"compare",op:e,left:t,right:At(n)})}function J(e,t){return new _({kind:"agg",op:e,operand:t})}function G(e,t){return new _({kind:"dt",component:e,operand:t})}var fr={add:"+",sub:"-",mul:"*",div:"/",mod:"%"};function fe(e){return typeof e=="string"?JSON.stringify(e):String(e)}function M(e){switch(e.kind){case "col":return `col(${JSON.stringify(e.name)})`;case "lit":return e.dtype?`lit(${fe(e.value)}, ${e.dtype})`:`lit(${fe(e.value)})`;case "arith":return `(${M(e.left.node)} ${fr[e.op]} ${M(e.right.node)})`;case "neg":return `(-${M(e.operand.node)})`;case "compare":return `${M(e.left.node)}.${e.op}(${M(e.right.node)})`;case "bool":return `${M(e.left.node)}.${e.op}(${M(e.right.node)})`;case "not":return `${M(e.operand.node)}.not()`;case "isNull":return `${M(e.operand.node)}.isNull()`;case "fillNull":return `${M(e.operand.node)}.fillNull(${fe(e.value)})`;case "cast":return `${M(e.operand.node)}.cast(${e.to})`;case "agg":return `${M(e.operand.node)}.${e.op}()`;case "dt":return `${M(e.operand.node)}.dt.${e.component}()`;case "strSlice":return e.end===void 0?`${M(e.operand.node)}.str.slice(${e.start})`:`${M(e.operand.node)}.str.slice(${e.start}, ${e.end})`}}var U=class extends Error{constructor(t){super(t),this.name="ExprError";}};function rt(e,t,n,r){let o=r?` ${r}`:"";return new U(`dtype mismatch in '${e}': cannot combine ${t} and ${n}.${o}`)}function R(e,t,n){let r=n?` ${n}`:"";return new U(`operation '${e}' is not supported for dtype ${t}.${r}`)}function me(e,t){return new U(`cast from ${e} to ${t} is not supported in v1`+(e==="utf8"||t==="utf8"?" (numeric\u2194utf8 conversion is not a kernel cast; use CSV inference / toString).":"."))}function de(e,t){let n=zt(e,t),r=n?` Did you mean '${n}'?`:"",o=t.length?` Known columns: ${t.map(i=>`'${i}'`).join(", ")}.`:"";return new U(`unknown column '${e}'.${r}${o}`)}function nt(e,t,n){return new U(`literal ${JSON.stringify(e)} is not a valid ${t} value for '${n}'.`)}function zt(e,t){let n=null,r=1/0;for(let i of t){let s=mr(e,i);s<r&&(r=s,n=i);}let o=Math.max(2,Math.ceil(e.length/3));return n!==null&&r<=o?n:null}function mr(e,t){let n=e.length,r=t.length;if(n===0)return r;if(r===0)return n;let o=new Array(r+1),i=new Array(r+1);for(let s=0;s<=r;s++)o[s]=s;for(let s=1;s<=n;s++){i[0]=s;let a=e.charCodeAt(s-1);for(let l=1;l<=r;l++){let u=a===t.charCodeAt(l-1)?0:1;i[l]=Math.min(o[l]+1,i[l-1]+1,o[l-1]+u);}[o,i]=[i,o];}return o[r]}function dr(e){let t=Object.keys(e);return {dtypeOf:n=>e[n],columnNames:()=>t}}var pr=new Set(["f64","f32","i32","u32","i64"]),Le=new Set(["i32","u32","i64"]),Ot=new Set(["f64","f32"]),mt=new Set(["date32","timestamp"]);function tt(e){return pr.has(e)}function pe(e,t){return Number.isInteger(e)?t==="i32"?e>=-2147483648&&e<=2147483647:e>=0&&e<=4294967295:false}function qt(e){let t=e.node;return t.kind==="lit"&&t.dtype===null&&typeof t.value=="number"?t.value:null}function V(e,t){return {kind:"lit",value:e,dtype:t}}function Wt(e,t){return e.dtype===t?e:{kind:"cast",dtype:t,from:e.dtype,operand:e}}function It(e,t){return B(e,t)}function ye(e,t){return It(e,t).dtype}function B(e,t){let n=e.node;switch(n.kind){case "col":{let r=t.dtypeOf(n.name);if(r===void 0)throw de(n.name,t.columnNames());return {kind:"col",name:n.name,dtype:r}}case "lit":return n.dtype!==null?V(n.value,n.dtype):typeof n.value=="bigint"?V(n.value,"i64"):typeof n.value=="number"?V(n.value,Number.isInteger(n.value)?"i32":"f64"):V(n.value,typeof n.value=="string"?"utf8":"bool");case "arith":return yr(n.op,n.left,n.right,t);case "neg":return wr(n.operand,t);case "compare":return Ar(n.op,n.left,n.right,t);case "bool":return Cr(n.op,n.left,n.right,t);case "not":return Or(n.operand,t);case "isNull":return {kind:"isNull",dtype:"bool",operand:B(n.operand,t)};case "fillNull":return Ir(n.operand,n.value,t);case "cast":return kr(n.operand,n.to,t);case "agg":return Er(n.op,n.operand,t);case "dt":return xr(n.component,n.operand,t);case "strSlice":return vr(n.operand,n.start,n.end,t)}}function yr(e,t,n,r){let o=qt(t),i=qt(n);if(o!==null&&i!==null){let u=Number.isInteger(o)?"i32":"f64",c=Number.isInteger(i)?"i32":"f64",f=u===c?u:"f64";return {kind:"arith",op:e,dtype:f,left:V(o,f),right:V(i,f)}}if(o!==null||i!==null){let u=o??i,c=B(o!==null?n:t,r),{opDtype:f,colTarget:m}=hr(e,u,c.dtype),d=Wt(c,m),p=V(u,f);return {kind:"arith",op:e,dtype:f,left:o!==null?p:d,right:o!==null?d:p}}let s=B(t,r),a=B(n,r),l=gr(e,s.dtype,a.dtype);return {kind:"arith",op:e,dtype:l,left:Wt(s,l),right:Wt(a,l)}}function hr(e,t,n){if(n==="timestamp")return {opDtype:"timestamp",colTarget:"timestamp"};if(n==="date32")return {opDtype:"date32",colTarget:"date32"};if(!tt(n))throw R(e,n,"arithmetic");return Ot.has(n)?{opDtype:n,colTarget:n}:n==="i64"?Number.isSafeInteger(t)?{opDtype:"i64",colTarget:"i64"}:{opDtype:"f64",colTarget:"f64"}:pe(t,n)?{opDtype:n,colTarget:n}:{opDtype:"f64",colTarget:"f64"}}function gr(e,t,n){if(mt.has(t)||mt.has(n))return br(e,t,n);if(!tt(t))throw R(e,t,"arithmetic");if(!tt(n))throw R(e,n,"arithmetic");if(t===n)return t;if(t==="i64"&&(n==="i32"||n==="u32")||n==="i64"&&(t==="i32"||t==="u32"))return "i64";if(t==="i64"&&Ot.has(n)||n==="i64"&&Ot.has(t)||(t==="i32"||t==="u32")&&n==="f64"||(n==="i32"||n==="u32")&&t==="f64")return "f64";if((t==="i32"||t==="u32")&&n==="f32"||(n==="i32"||n==="u32")&&t==="f32")return "f32";throw rt(e,t,n,"insert an explicit .cast() (only int\u2192float widening is implicit).")}function br(e,t,n){if(e==="sub"&&t==="timestamp"&&n==="timestamp")return "i64";if((e==="add"||e==="sub")&&t==="timestamp"&&Le.has(n)||e==="add"&&Le.has(t)&&n==="timestamp")return "timestamp";if(e==="sub"&&t==="date32"&&n==="date32")return "i32";if((e==="add"||e==="sub")&&t==="date32"&&(n==="i32"||n==="u32")||e==="add"&&(t==="i32"||t==="u32")&&n==="date32")return "date32";throw new U(`${e}(${t},${n})`)}function wr(e,t){let n=B(e,t);if(!tt(n.dtype))throw R("neg",n.dtype);return {kind:"neg",dtype:n.dtype,operand:n}}function xr(e,t,n){let r=B(t,n);if(!mt.has(r.dtype))throw R("dt",r.dtype);return {kind:"dt",component:e,dtype:"i32",operand:r}}function vr(e,t,n,r){let o=B(e,r);if(o.dtype!=="utf8")throw R("str.slice",o.dtype,`str namespace requires a utf8 column; got ${o.dtype}`);return {kind:"strSlice",dtype:"utf8",operand:o,start:t,end:n}}function Ar(e,t,n,r){let o=e==="eq"||e==="ne",i=Dt(t)??Dt(n),s=Ct(t)??Ct(n),a=qt(t),l=qt(n);if(a!==null&&l!==null){let m=Number.isInteger(a)&&Number.isInteger(l)?"i32":"f64";return ot(e,m,V(a,m),V(l,m))}if(a!==null||l!==null){let m=a??l,d=B(a!==null?n:t,r);if(d.dtype==="date32"){let g=V(m,"date32");return ot(e,"date32",a!==null?g:d,a!==null?d:g)}if(d.dtype==="timestamp"){let g=V(m,"timestamp");return ot(e,"timestamp",a!==null?g:d,a!==null?d:g)}if(!tt(d.dtype))throw rt(e,a!==null?"f64":d.dtype,a!==null?d.dtype:"f64","cannot compare a number to a non-numeric column.");let p=Dr(m,d.dtype),h=Wt(d,p),y=V(m,p);return ot(e,p,a!==null?y:h,a!==null?h:y)}if(i!==null){let m=B(Dt(t)!==null?n:t,r);if(m.dtype!=="utf8")throw rt(e,"utf8",m.dtype,"cannot compare a string to a non-utf8 column.");if(!o)throw R(e,"utf8","string ordering");let d=V(i,"utf8");return ot(e,"utf8",Dt(t)!==null?d:m,Dt(t)!==null?m:d)}if(s!==null){let m=B(Ct(t)!==null?n:t,r);if(m.dtype!=="bool")throw rt(e,"bool",m.dtype,"cannot compare a boolean to a non-bool column.");if(!o)throw R(e,"bool");let d=V(s,"bool");return ot(e,"bool",Ct(t)!==null?d:m,Ct(t)!==null?m:d)}let u=B(t,r),c=B(n,r);if(u.dtype!==c.dtype)throw rt(e,u.dtype,c.dtype,"cast");let f=u.dtype;if(f==="utf8"||f==="bool")throw R(e,f,"column-vs-column");return ot(e,f,u,c)}function ot(e,t,n,r){return {kind:"compare",op:e,dtype:"bool",operandDtype:t,left:n,right:r}}function Dr(e,t){return Ot.has(t)?t:t==="i64"?Number.isSafeInteger(e)?"i64":"f64":pe(e,t)?t:"f64"}function Dt(e){let t=e.node;return t.kind==="lit"&&typeof t.value=="string"?t.value:null}function Ct(e){let t=e.node;return t.kind==="lit"&&typeof t.value=="boolean"?t.value:null}function Cr(e,t,n,r){let o=B(t,r),i=B(n,r);if(o.dtype!=="bool")throw R(e,o.dtype,"boolean");if(i.dtype!=="bool")throw R(e,i.dtype,"boolean");return {kind:"bool",op:e,dtype:"bool",left:o,right:i}}function Or(e,t){let n=B(e,t);if(n.dtype!=="bool")throw R("not",n.dtype,"boolean");return {kind:"not",dtype:"bool",operand:n}}function Ir(e,t,n){let r=B(e,n);return Tr(t,r.dtype),{kind:"fillNull",dtype:r.dtype,operand:r,value:t}}function Tr(e,t){if(t==="utf8"){if(typeof e!="string")throw nt(e,t,"fillNull");return}if(t==="bool"){if(typeof e!="boolean")throw nt(e,t,"fillNull");return}if(t==="i64"||t==="timestamp"){if(typeof e!="bigint"&&typeof e!="number")throw nt(e,t,"fillNull");if(typeof e=="number"&&!Number.isSafeInteger(e))throw nt(e,t,"fillNull");return}if(typeof e!="number")throw nt(e,t,"fillNull");if((t==="i32"||t==="u32")&&!pe(e,t))throw nt(e,t,"fillNull")}var Pr={f64:new Set(["f64","f32","i32","u32","bool","i64"]),f32:new Set(["f64","f32","i32","u32","bool","i64"]),i32:new Set(["f64","f32","i32","u32","bool","i64","date32"]),u32:new Set(["f64","f32","i32","u32","bool","i64"]),bool:new Set(["f64","f32","i32","u32","bool","i64"]),utf8:new Set(["utf8"]),i64:new Set(["f64","f32","i32","u32","bool","i64","timestamp"]),date32:new Set(["i32","timestamp","date32"]),timestamp:new Set(["i64","date32","timestamp"])};function kr(e,t,n){let r=B(e,n),o=r.dtype;if(!Pr[o]?.has(t))throw me(o,t);return {kind:"cast",dtype:t,from:o,operand:r}}function Er(e,t,n){let r=B(t,n),o=Tt(e,r.dtype);return {kind:"agg",op:e,dtype:o,operandDtype:r.dtype,operand:r}}function Tt(e,t){switch(e){case "count":return "i32";case "nunique":if(tt(t)||t==="utf8"||mt.has(t))return "i32";throw R("nunique",t);case "sum":if(Ot.has(t))return t;if(t==="i64")return "i64";if(t==="i32"||t==="u32")return "f64";throw R("sum",t);case "mean":case "std":case "var":if(tt(t))return "f64";throw R(e,t);case "min":case "max":if(tt(t)||mt.has(t))return t;throw R(e,t);case "first":case "last":if(tt(t)||t==="utf8"||mt.has(t))return t;throw R(e,t)}}function he(e,t,n){let r=e[t];if(typeof r!="function")throw new Error(`kernel export not found: ${t}`);return r(...n)}function je(e,t,n){let r=e[t];if(typeof r!="function")throw new Error(`kernel export not found: ${t}`);return r(...n)}function Ht(e){let t=0,n=0;for(let r of e.allocs)r.purpose==="data"?t++:r.purpose==="mask"&&n++;return {kernelCalls:e.kernels.length,kernels:e.kernels.slice(),allocations:e.allocs.length,dataAllocations:t,maskAllocations:n,frees:e.frees}}var Pt=class{ctx;wasm;len;owned=new Set;trace={kernels:[],allocs:[],frees:0};viewed=[];constructor(t){this.ctx=t.ctx,this.wasm=t.wasm,this.len=t.length;}get validityBytes(){return v(this.len)}alloc(t,n){let r=this.ctx.mod.alloc(t);if(r===0)throw new Error(`out of wasm memory allocating ${t} bytes`);return this.owned.add(r),this.trace.allocs.push({bytes:t,purpose:n}),r}track(t,n,r){t!==0&&(this.owned.add(t),this.trace.allocs.push({bytes:n,purpose:r}));}free(t){t!==0&&this.owned.delete(t)&&(this.forgetViews(t),this.ctx.mod.free(t),this.trace.frees++);}transfer(t){this.owned.delete(t),this.forgetViews(t);}freeAll(){for(let t of this.viewed)this.ctx.viewOf.forget(t);this.viewed.length=0;for(let t of this.owned)this.ctx.mod.free(t),this.trace.frees++;this.owned.clear();}call(t,...n){return this.trace.kernels.push(t),he(this.wasm,t,n)}callBigInt(t,...n){return this.trace.kernels.push(t),je(this.wasm,t,n)}view(t,n,r){let o={ptr:t,length:n,dtype:r};return this.viewed.push(o),this.ctx.viewOf(o)}forgetViews(t){for(let n=this.viewed.length-1;n>=0;n--){let r=this.viewed[n];r.ptr===t&&(this.ctx.viewOf.forget(r),this.viewed.splice(n,1));}}},N={ptr:0,owns:false};function F(e,t){t.owns&&e.free(t.ptr);}function ze(e,t,n){if(t===0)return N;if((n&7)===0)return {ptr:t+(n>>3),owns:false};let r=e.validityBytes,o=e.alloc(r,"validity"),i=e.view(t,v(n+e.len),"u8"),s=e.view(o,r,"u8");s.fill(0);for(let a=0;a<e.len;a++)T(i,n+a)&&S(s,a);return {ptr:o,owns:true}}function We(e,t,n){if(n===0)return 0;let r=e.view(t,v(n),"u8"),o=0;for(let i=0;i<n;i++)r[i>>3]>>(i&7)&1&&o++;return o}var ge=86400000n,Rr=[0,31,59,90,120,151,181,212,243,273,304,334];function qe(e){let t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),i=o+n*400,s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),a=Math.floor((5*s+2)/153),l=s-Math.floor((153*a+2)/5)+1,u=a<10?a+3:a-9;return {year:i+(u<=2?1:0),month:u,day:l}}function Kt(e,t,n){let r=e-(t<=2?1:0),o=Math.floor(r/400),i=r-o*400,s=Math.floor((153*(t>2?t-3:t+9)+2)/5)+n-1,a=i*365+Math.floor(i/4)-Math.floor(i/100)+s;return o*146097+a-719468}function Br(e){return e%4===0&&e%100!==0||e%400===0}function Yt(e,t,n){let r=(Rr[t-1]??0)+n;return t>2&&Br(e)?r+1:r}function Jt(e){return ((e+3)%7+7)%7+1}function Sr(e){let t=e/ge;return e%ge!==0n&&e<0n&&(t-=1n),Number(t)}function He(e){let{year:t,month:n,day:r}=qe(e);return {year:t,month:n,day:r,hour:0,minute:0,second:0,millisecond:0,weekday:Jt(e),dayOfYear:Yt(t,n,r),quarter:Math.ceil(n/3)}}function Ke(e){let t=typeof e=="bigint"?e:BigInt(Math.trunc(e)),n=Sr(t),r=Number(t-BigInt(n)*ge),{year:o,month:i,day:s}=qe(n),a=Math.floor(r/36e5),l=r%36e5,u=Math.floor(l/6e4),c=l%6e4,f=Math.floor(c/1e3),m=c%1e3;return {year:o,month:i,day:s,hour:a,minute:u,second:f,millisecond:m,weekday:Jt(n),dayOfYear:Yt(o,i,s),quarter:Math.ceil(i/3)}}var Ye=new Map;function Fr(e){let t=Ye.get(e);if(t!==void 0)return t;let n;try{n=new Intl.DateTimeFormat("en",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hourCycle:"h23"});}catch(r){throw new RangeError(`Invalid IANA timezone: "${e}". ${r instanceof Error?r.message:String(r)}`)}return Ye.set(e,n),n}function Je(e,t){let r=Fr(t).formatToParts(e),o=0,i=0,s=0,a=0,l=0,u=0;for(let m of r)switch(m.type){case "year":o=parseInt(m.value,10);break;case "month":i=parseInt(m.value,10);break;case "day":s=parseInt(m.value,10);break;case "hour":a=parseInt(m.value,10);break;case "minute":l=parseInt(m.value,10);break;case "second":u=parseInt(m.value,10);break}let c=(e%1e3+1e3)%1e3,f=Kt(o,i,s);return {year:o,month:i,day:s,hour:a,minute:l,second:u,millisecond:c,weekday:Jt(f),dayOfYear:Yt(o,i,s),quarter:Math.ceil(i/3)}}function Mr(e,t){return ((e[t>>3]??0)&1<<(t&7))!==0}function dt(e,t,n,r){let o=e.length,i=new Int32Array(o),s=e instanceof Int32Array,a=typeof r=="string"&&r.length>0;for(let l=0;l<o;l++){if(t!==null&&!Mr(t,l))continue;let u;if(s)u=He(e[l]??0);else if(a){let c=Number(e[l]??0n);u=Je(c,r);}else {let c=e[l]??0n;u=Ke(c);}i[l]=u[n];}return {data:i,validity:t}}function Et(e,t){let n=It(e,t),r=n.kind==="agg"?"scalar":"column";return {dtype:n.dtype,resultKind:r,execute(){let o=new Pt(t);try{if(n.kind==="agg")return {kind:"scalar",scalar:Ae(o,t,n),stats:Ht(o.trace)};let i=H(o,t,n);return {kind:"column",column:en(o,i),stats:Ht(o.trace)}}finally{o.freeAll();}}}}function ve(e,t){let n=It(e,t);if(n.dtype!=="bool")throw new U(`filter predicate must be boolean, got ${n.dtype}. Use a comparison / boolean expression.`);return {execute(){let r=new Pt(t),o=ro(r,H(r,t,n)),i;if(o.validity.ptr===0)i=o.maskPtr;else if(o.ownsMask)r.call("validity_and",o.maskPtr,o.validity.ptr,o.maskPtr,r.len),F(r,o.validity),i=o.maskPtr;else {let a=r.alloc(r.validityBytes,"mask");r.call("validity_and",o.maskPtr,o.validity.ptr,a,r.len),F(r,o.validity),i=a;}let s=We(r,i,r.len);return _r(r,t,i,s)}}}function _r(e,t,n,r){let o=null,i=()=>{if(o)return o;let s=new Int32Array(r),a=e.view(n,v(e.len),"u8"),l=0;for(let u=0;u<e.len;u++)a[u>>3]>>(u&7)&1&&(s[l++]=u);return o=s,s};return {count:r,compact(s){let a=C[s.dtype],l=t.ctx.mod.alloc(Math.max(r*a.size,1)),u=e.call(`filter_${oo(s.dtype)}`,s.dataPtr,n,l,e.len);if(u!==r)throw new Error(`filter count mismatch: kernel ${u}, expected ${r}`);let c=0;if(s.validityPtr!==0){let m=i(),d=e.view(s.validityPtr,v(s.validityBitOffset+e.len),"u8"),p=0,h=v(r),y=t.ctx.mod.alloc(Math.max(h,1)),g=e.view(y,h,"u8");g.fill(0);for(let b=0;b<r;b++)T(d,s.validityBitOffset+m[b])?S(g,b):p++;p===0?(t.ctx.viewOf.forget({ptr:y,length:h,dtype:"u8"}),t.ctx.mod.free(y)):c=y;}let f=s.dict?nn(t.ctx,s.dict):null;return {dtype:s.dtype,length:r,dataPtr:l,validityPtr:c,validityBitOffset:0,dict:f,owned:true}},free(){e.freeAll();},get stats(){return Ht(e.trace)}}}var Ur={gt:"lt",lt:"gt",ge:"le",le:"ge",eq:"eq",ne:"ne"},Vr=new Set(["add","mul"]),Nr=new Set(["f64_i32","f64_u32","f64_bool","f32_i32","f32_u32","f32_bool","i32_u32","u32_i32","f64_i64","f32_i64"]),be=86400000n;function H(e,t,n){switch(n.kind){case "col":return $r(e,t,n.name,n.dtype);case "lit":return Gt(e,n.value,n.dtype);case "arith":return Lr(e,t,n);case "neg":return zr(e,t,n.dtype,n.operand);case "compare":return Wr(e,t,n);case "bool":return Kr(e,t,n.op,n.left,n.right);case "not":return Yr(e,t,n.operand);case "isNull":return Jr(e,t,n.operand);case "fillNull":return Gr(e,t,n.dtype,n.operand,n.value);case "cast":return Xr(e,t,n.from,n.dtype,n.operand);case "agg":{let r=Ae(e,t,n);return Gt(e,r.value,n.dtype)}case "dt":return to(e,t,n.component,n.operand);case "strSlice":return eo(e,t,n.operand,n.start,n.end)}}function $r(e,t,n,r){let o=t.getColumn(n);if(!o)throw new U(`column '${n}' vanished during execution`);let i=ze(e,o.validityPtr,o.validityBitOffset);return r==="bool"?{rep:"boolcol",dataPtr:o.dataPtr,ownsData:false,validity:i}:{rep:"column",dtype:r,dataPtr:o.dataPtr,ownsData:false,validity:i,dict:o.dict,ownsDict:false}}function $(e,t,n){let r=H(e,t,n);if(r.rep!=="column")throw new Error(`internal: expected numeric column, got ${r.rep}`);return r}function kt(e){return e.kind==="lit"||e.kind==="agg"||e.kind==="cast"&&kt(e.operand)}function Lr(e,t,n){let r=n.dtype,o=kt(n.left),i=kt(n.right);if(o&&i){let l=Gt(e,Z(e,t,n.left),r);return we(e,t,n.op,l,Z(e,t,n.right),r)}if(i){let l=$(e,t,n.left);return we(e,t,n.op,l,Z(e,t,n.right),r)}if(o){let l=$(e,t,n.right);return jr(e,t,n.op,Z(e,t,n.left),l,r)}let s=$(e,t,n.left),a=$(e,t,n.right);return Qe(e,t,n.op,s,a,r)}function we(e,t,n,r,o,i){let s=C[i].size,a=r.ownsData?r.dataPtr:e.alloc(e.len*s,"data");if(o===null||(n==="div"||n==="mod")&&((i==="i32"||i==="u32")&&o===0||i==="i64"&&o===0n))return F(e,r.validity),lo(e,a,e.len*s),L(i,a,it(e),null,false);let u=C[i].wasm;if(u==="i64"){let c=typeof o=="bigint"?o:BigInt(o);e.callBigInt(`${n}_i64_scalar`,r.dataPtr,c,a,e.len);}else e.call(`${n}_${u}_scalar`,r.dataPtr,o,a,e.len);return L(i,a,r.validity,null,false)}function jr(e,t,n,r,o,i){if(Vr.has(n))return we(e,t,n,o,r,i);let s=Gt(e,r,i);return Qe(e,t,n,s,o,i)}function Qe(e,t,n,r,o,i){let s=C[i].size,a=(n==="div"||n==="mod")&&(i==="i32"||i==="u32"||i==="i64"),l=N;if(a){let m=e.alloc(e.validityBytes,"mask");i==="i64"?e.callBigInt("ne_i64_scalar_mask",o.dataPtr,0n,m,e.len):e.call(`ne_${i}_scalar_mask`,o.dataPtr,0,m,e.len),l={ptr:m,owns:true};}let u=r.ownsData?r.dataPtr:o.ownsData?o.dataPtr:e.alloc(e.len*s,"data"),c=C[i].wasm;e.call(`${n}_${c}`,r.dataPtr,o.dataPtr,u,e.len),u!==r.dataPtr&&r.ownsData&&e.free(r.dataPtr),u!==o.dataPtr&&o.ownsData&&e.free(o.dataPtr);let f=xe(e,r.validity,o.validity);return a&&(f=xe(e,f,l)),L(i,u,f,null,false)}function zr(e,t,n,r){let o=$(e,t,r),i=C[n].size,s=o.ownsData?o.dataPtr:e.alloc(e.len*i,"data");return e.call(`neg_${n}`,o.dataPtr,s,e.len),L(n,s,o.validity,null,false)}function Wr(e,t,n){let r=n.operandDtype,o=kt(n.left),i=kt(n.right);if(o&&i){let c=Z(e,t,n.left),f=Z(e,t,n.right);return ao(e,so(n.op,c,f))}if(r==="bool")return Hr(e,t,n,o);if(r==="utf8")return qr(e,t,n,o);let s=C[r].wasm,a=e.alloc(e.validityBytes,"mask");if(o||i){let c=$(e,t,o?n.right:n.left),f=Z(e,t,o?n.left:n.right);if(f===null)return F(e,c.validity),e.free(c.ownsData?c.dataPtr:0),e.view(a,e.validityBytes,"u8").fill(0),{rep:"mask",maskPtr:a,ownsMask:true,validity:it(e)};let m=o?Ur[n.op]:n.op;if(s==="i64"){let d=typeof f=="bigint"?f:BigInt(f);e.callBigInt(`${m}_i64_scalar_mask`,c.dataPtr,d,a,e.len);}else e.call(`${m}_${s}_scalar_mask`,c.dataPtr,f,a,e.len);return c.ownsData&&e.free(c.dataPtr),{rep:"mask",maskPtr:a,ownsMask:true,validity:c.validity}}let l=$(e,t,n.left),u=$(e,t,n.right);return e.call(`${n.op}_${s}_mask`,l.dataPtr,u.dataPtr,a,e.len),l.ownsData&&e.free(l.dataPtr),u.ownsData&&e.free(u.dataPtr),{rep:"mask",maskPtr:a,ownsMask:true,validity:xe(e,l.validity,u.validity)}}function qr(e,t,n,r){let o=$(e,t,r?n.right:n.left),i=Z(e,t,r?n.left:n.right),s=e.alloc(e.validityBytes,"mask"),a=e.view(s,e.validityBytes,"u8");if(i===null)return a.fill(0),o.ownsData&&e.free(o.dataPtr),F(e,o.validity),o.ownsDict&&yt(t,o.dict),{rep:"mask",maskPtr:s,ownsMask:true,validity:it(e)};let u=(o.dict?W(t.ctx,o.dict):[]).indexOf(i);return u>=0?e.call(`${n.op}_i32_scalar_mask`,o.dataPtr,u,s,e.len):a.fill(n.op==="ne"?255:0),o.ownsData&&e.free(o.dataPtr),o.ownsDict&&yt(t,o.dict),{rep:"mask",maskPtr:s,ownsMask:true,validity:o.validity}}function Hr(e,t,n,r){let o=Z(e,t,r?n.left:n.right),i=pt(e,H(e,t,r?n.right:n.left));return (n.op==="eq"?o===false:o===true)?Xe(e,i):i}function Kr(e,t,n,r,o){let i=pt(e,H(e,t,r)),s=pt(e,H(e,t,o)),a=n==="and"?"and_kleene":"or_kleene",l=i.ownsData?i.dataPtr:s.ownsData?s.dataPtr:e.alloc(e.len,"data"),u=i.validity.ptr===0&&s.validity.ptr===0,c;if(u){let f=e.alloc(e.validityBytes,"scratch");e.call(a,i.dataPtr,0,s.dataPtr,0,l,f,e.len),e.free(f),c=N;}else {let f=e.alloc(e.validityBytes,"validity");e.call(a,i.dataPtr,i.validity.ptr,s.dataPtr,s.validity.ptr,l,f,e.len),F(e,i.validity),F(e,s.validity),c={ptr:f,owns:true};}return l!==i.dataPtr&&i.ownsData&&e.free(i.dataPtr),l!==s.dataPtr&&s.ownsData&&e.free(s.dataPtr),{rep:"boolcol",dataPtr:l,ownsData:true,validity:c}}function Yr(e,t,n){return Xe(e,pt(e,H(e,t,n)))}function Xe(e,t){let n=t.ownsData?t.dataPtr:e.alloc(e.len,"data"),r;if(t.validity.ptr===0){let o=e.alloc(e.validityBytes,"scratch");e.call("not_bool",t.dataPtr,0,n,o,e.len),e.free(o),r=N;}else {let o=e.alloc(e.validityBytes,"validity");e.call("not_bool",t.dataPtr,t.validity.ptr,n,o,e.len),F(e,t.validity),r={ptr:o,owns:true};}return n!==t.dataPtr&&t.ownsData&&e.free(t.dataPtr),{rep:"boolcol",dataPtr:n,ownsData:true,validity:r}}function Jr(e,t,n){let r=H(e,t,n),o=De(r),i=e.alloc(e.len,"data");return e.call("is_null",o.ptr,i,e.len),tn(e,t,r),{rep:"boolcol",dataPtr:i,ownsData:true,validity:N}}function Gr(e,t,n,r,o){if(n==="bool")return Zr(e,t,r,o);if(n==="utf8")return Qr(e,t,r,o);let i=$(e,t,r);if(i.validity.ptr===0)return i;let s=C[n].size,a=i.ownsData?i.dataPtr:e.alloc(e.len*s,"data"),l=C[n].wasm;if(l==="i64"){let u=typeof o=="bigint"?o:BigInt(o);e.callBigInt("fill_null_i64",i.dataPtr,i.validity.ptr,u,a,e.len);}else e.call(`fill_null_${l}`,i.dataPtr,i.validity.ptr,o,a,e.len);return F(e,i.validity),L(n,a,N,null,false)}function Zr(e,t,n,r){let o=pt(e,H(e,t,n));if(o.validity.ptr===0)return o;let i=o.ownsData?o.dataPtr:e.alloc(e.len,"data"),s=e.view(o.dataPtr,e.len,"u8"),a=e.view(o.validity.ptr,e.validityBytes,"u8"),l=e.view(i,e.len,"u8"),u=r?1:0;for(let c=0;c<e.len;c++)l[c]=T(a,c)?s[c]:u;return F(e,o.validity),{rep:"boolcol",dataPtr:i,ownsData:true,validity:N}}function Qr(e,t,n,r){let o=$(e,t,n);if(o.validity.ptr===0)return o;let i=o.dict?W(t.ctx,o.dict):[],s=i.indexOf(r),a=o.dict,l=o.ownsDict;s<0&&(s=i.length,a=ct(t.ctx,[...i,r]),e.track(a.offsetsPtr,(a.count+1)*4,"dict"),e.track(a.bytesPtr,Math.max(a.bytesLen,1),"dict"),o.ownsDict&&yt(t,o.dict),l=true);let u=o.ownsData?o.dataPtr:e.alloc(e.len*4,"data"),c=e.view(o.dataPtr,e.len,"i32"),f=e.view(o.validity.ptr,e.validityBytes,"u8"),m=e.view(u,e.len,"i32");for(let d=0;d<e.len;d++)m[d]=T(f,d)?c[d]:s;return F(e,o.validity),L("utf8",u,N,a,l)}function Xr(e,t,n,r,o){let i=H(e,t,o);if(n===r)return i;let s=(i.rep==="boolcol",i.dataPtr),a=(i.rep==="boolcol",i.ownsData),l=De(i);if(n==="date32"&&r==="i32"||n==="i32"&&r==="date32"||n==="timestamp"&&r==="i64"||n==="i64"&&r==="timestamp")return {...i,dtype:r};if(n==="date32"&&r==="timestamp"){let p=e.alloc(e.len*8,"data"),h=e.alloc(e.validityBytes,"scratch");return e.call("cast_i32_i64",s,l.ptr,p,h,e.len),e.free(h),e.callBigInt("mul_i64_scalar",p,be,p,e.len),a&&e.free(s),L("timestamp",p,l,null,false)}if(n==="timestamp"&&r==="date32"){let p=e.view(s,e.len,"i64"),h=e.alloc(e.len*4,"data"),y=e.view(h,e.len,"i32");for(let g=0;g<e.len;g++){let b=p[g],w=b/be;b%be!==0n&&b<0n&&(w-=1n),y[g]=Number(w);}return a&&e.free(s),L("date32",h,l,null,false)}let u=C[r].size,f=a&&C[n].size===u?s:e.alloc(e.len*u,"data"),m=Nr.has(`${n}_${r}`),d;if(m){let p=e.alloc(e.validityBytes,"validity");e.call(`cast_${n}_${r}`,s,l.ptr,f,p,e.len),F(e,l),d={ptr:p,owns:true};}else {let p=e.alloc(e.validityBytes,"scratch");e.call(`cast_${n}_${r}`,s,l.ptr,f,p,e.len),e.free(p),d=l;}return f!==s&&a&&e.free(s),r==="bool"?{rep:"boolcol",dataPtr:f,ownsData:true,validity:d}:L(r,f,d,null,false)}function to(e,t,n,r){let o=$(e,t,r),i=e.len,s;if(r.kind==="col"){let f=t.getColumn(r.name);f?.tz&&(s=f.tz);}let a=null;o.validity.ptr!==0&&(a=e.view(o.validity.ptr,e.validityBytes,"u8"));let l;if(o.dtype==="date32"){let f=e.view(o.dataPtr,i,"i32");l=dt(f,a,n);}else {let f=e.view(o.dataPtr,i,"i64");l=dt(f,a,n,s);}let u=e.alloc(i*4,"data");return e.view(u,i,"i32").set(l.data),o.ownsData&&e.free(o.dataPtr),o.ownsDict&&o.dict&&yt(t,o.dict),L("i32",u,o.validity,null,false)}function eo(e,t,n,r,o){let i=$(e,t,n),s=e.len,a=i.dict?W(t.ctx,i.dict):[],l=a.length,u=new Int32Array(l),c=[],f=new Map;for(let y=0;y<l;y++){let g=o===void 0?a[y].slice(r):a[y].slice(r,o),b=f.get(g);b===void 0&&(b=c.length,c.push(g),f.set(g,b)),u[y]=b;}let m=ct(t.ctx,c);e.track(m.offsetsPtr,(m.count+1)*4,"dict"),e.track(m.bytesPtr,Math.max(m.bytesLen,1),"dict");let d=i.ownsData?i.dataPtr:e.alloc(s*4,"data"),p=e.view(i.dataPtr,s,"i32"),h=e.view(d,s,"i32");for(let y=0;y<s;y++)h[y]=u[p[y]];return d!==i.dataPtr&&i.ownsData&&e.free(i.dataPtr),i.ownsDict&&yt(t,i.dict),L("utf8",d,i.validity,m,true)}function Ae(e,t,n){let r=H(e,t,n.operand),o=De(r),i=r.rep==="mask"?0:(r.rep==="boolcol",r.dataPtr),s=r.rep==="column"?r.dict:null,a=n.operandDtype,l=a==="utf8"?"i32":a,u=e.len,c=o.ptr===0?u:e.call("count_null",o.ptr,u),f=no(e,t,n.op,a,l,i,o.ptr,u,c,s);return tn(e,t,r),{value:f,dtype:n.dtype}}function no(e,t,n,r,o,i,s,a,l,u){let c=r==="utf8"?"i32":C[r].wasm,f=m=>o==="u32"?m>>>0:m;switch(n){case "count":return l;case "nunique":return e.call(`nunique_${c}_null`,i,s,a);case "sum":return c==="i64"?e.callBigInt("sum_i64_null",i,s,a):e.call(`sum_${r}_null`,i,s,a);case "mean":return l>=1?e.call(`mean_${r}_null`,i,s,a):null;case "std":return l>=2?e.call(`std_${r}_null`,i,s,a):null;case "var":return l>=2?e.call(`var_${r}_null`,i,s,a):null;case "min":case "max":return l?c==="i64"?e.callBigInt(`${n}_i64_null`,i,s,a):f(e.call(`${n}_${c}_null`,i,s,a)):null;case "first":case "last":{let m=e.alloc(4,"scratch");e.view(m,1,"i32")[0]=0;let d;c==="i64"?d=e.callBigInt(`${n}_i64_null`,i,s,a,m):d=e.call(`${n}_${c}_null`,i,s,a,m);let p=e.view(m,1,"i32")[0]!==0;return e.free(m),p?c==="i64"?d:r==="utf8"?q(t.ctx,u,d):f(d):null}}}function pt(e,t){if(t.rep==="boolcol")return t;if(t.rep==="mask"){let n=e.alloc(e.len,"data");return e.call("expand_mask_bool",t.maskPtr,n,e.len),t.ownsMask&&e.free(t.maskPtr),{rep:"boolcol",dataPtr:n,ownsData:true,validity:t.validity}}throw new Error("internal: expected a boolean value")}function ro(e,t){if(t.rep==="mask")return t;if(t.rep==="boolcol"){let n=e.alloc(e.validityBytes,"mask"),r=e.view(t.dataPtr,e.len,"u8"),o=e.view(n,e.validityBytes,"u8");o.fill(0);for(let i=0;i<e.len;i++)r[i]&&S(o,i);return t.ownsData&&e.free(t.dataPtr),{rep:"mask",maskPtr:n,ownsMask:true,validity:t.validity}}throw new Error("internal: expected a boolean value")}function De(e){return e.validity}function oo(e){return e==="bool"?"u8":e==="utf8"?"i32":C[e].wasm}function Z(e,t,n){if(n.kind==="lit")return n.dtype==="i64"&&typeof n.value=="number"?BigInt(n.value):n.value;if(n.kind==="agg")return Ae(e,t,n).value;if(n.kind==="cast")return io(Z(e,t,n.operand),n.from,n.dtype);throw new Error(`internal: ${n.kind} is not a scalar operand`)}var Ge=9223372036854776e3;function io(e,t,n){if(e===null)return null;if(t===n)return e;if(t==="i64"){let i=e;return n==="f64"?Number(i):n==="f32"?Math.fround(Number(i)):n==="i32"?Number(BigInt.asIntN(32,i)):n==="u32"?Number(BigInt.asUintN(32,i)):n==="bool"?i!==0n:null}if(n==="i64"){if(typeof e=="boolean")return e?1n:0n;let i=e;if(!Number.isFinite(i))return null;let s=Math.trunc(i);return s>=Ge||s<-Ge?null:BigInt(s)}if(n==="bool")return typeof e=="number"&&Number.isNaN(e)?null:e!==0&&e!==false;let r=typeof e=="boolean"?e?1:0:e;if(n==="f64")return r;if(n==="f32")return Math.fround(r);if(!Number.isFinite(r))return null;let o=Math.trunc(r);return n==="i32"?o>=-2147483648&&o<=2147483647?o:null:r<0?null:o<=4294967295?o:null}function so(e,t,n){if(t===null||n===null)return null;let r=t,o=n;switch(e){case "gt":return r>o;case "ge":return r>=o;case "lt":return r<o;case "le":return r<=o;case "eq":return r===o;case "ne":return r!==o}}function Gt(e,t,n){if(n==="utf8")throw new U("broadcasting a utf8 scalar to a column is not supported in P3.1.");if(n==="bool"){let a=e.alloc(e.len,"data");return e.view(a,e.len,"u8").fill(t===null?0:t?1:0),{rep:"boolcol",dataPtr:a,ownsData:true,validity:t===null?it(e):N}}let r=C[n].size,o=e.alloc(e.len*r,"data");if(n==="i64"||n==="timestamp"){let a=e.view(o,e.len,"i64"),l=t===null?0n:typeof t=="bigint"?t:BigInt(t);for(let u=0;u<e.len;u++)a[u]=l;return L(n,o,t===null?it(e):N,null,false)}let i=e.view(o,e.len,C[n].view),s=t===null?0:t;for(let a=0;a<e.len;a++)i[a]=s;return L(n,o,t===null?it(e):N,null,false)}function ao(e,t){let n=e.alloc(e.validityBytes,"mask");return e.view(n,e.validityBytes,"u8").fill(t===true?255:0),{rep:"mask",maskPtr:n,ownsMask:true,validity:t===null?it(e):N}}function xe(e,t,n){if(t.ptr===0&&n.ptr===0)return N;if(n.ptr===0)return t;if(t.ptr===0)return n;let r=e.alloc(e.validityBytes,"validity");return e.call("validity_and",t.ptr,n.ptr,r,e.len),F(e,t),F(e,n),{ptr:r,owns:true}}function it(e){let t=e.alloc(e.validityBytes,"validity");return e.view(t,e.validityBytes,"u8").fill(0),{ptr:t,owns:true}}function lo(e,t,n){e.view(t,n,"u8").fill(0);}function L(e,t,n,r,o){return {rep:"column",dtype:e,dataPtr:t,ownsData:true,validity:n,dict:r,ownsDict:o}}function tn(e,t,n){if(n.rep==="mask"){n.ownsMask&&e.free(n.maskPtr),F(e,n.validity);return}if(n.rep==="boolcol"){n.ownsData&&e.free(n.dataPtr),F(e,n.validity);return}n.ownsData&&e.free(n.dataPtr),F(e,n.validity),n.ownsDict&&yt(t,n.dict);}function yt(e,t){t&&(e.ctx.viewOf.forget({ptr:t.offsetsPtr,length:t.count+1,dtype:"i32"}),e.ctx.viewOf.forget({ptr:t.bytesPtr,length:t.bytesLen,dtype:"u8"}),e.ctx.mod.free(t.offsetsPtr),e.ctx.mod.free(t.bytesPtr));}function en(e,t){if(t.rep==="mask")return en(e,pt(e,t));let n=e.ctx,r=t.rep==="boolcol"?"bool":t.dtype,o=C[r],i;t.ownsData?(i=t.dataPtr,e.transfer(t.dataPtr)):(i=n.mod.alloc(Math.max(e.len*o.size,1)),Ze(e,t.dataPtr,i,e.len*o.size));let s=t.validity,a=0;s.ptr!==0&&(s.owns?(a=s.ptr,e.transfer(s.ptr)):(a=n.mod.alloc(Math.max(e.validityBytes,1)),Ze(e,s.ptr,a,e.validityBytes)));let l=null;return t.rep==="column"&&t.dict&&(t.ownsDict?(l=t.dict,e.transfer(t.dict.offsetsPtr),e.transfer(t.dict.bytesPtr)):l=nn(n,t.dict)),{dtype:r,length:e.len,dataPtr:i,validityPtr:a,validityBitOffset:0,dict:l,owned:true}}function Ze(e,t,n,r){if(r<=0)return;let o=e.view(t,r,"u8");e.view(n,r,"u8").set(o);}function nn(e,t){let n=(t.count+1)*4,r=e.mod.alloc(Math.max(n,1)),o=e.mod.alloc(Math.max(t.bytesLen,1));return e.viewOf({ptr:r,length:t.count+1,dtype:"i32"}).set(e.viewOf({ptr:t.offsetsPtr,length:t.count+1,dtype:"i32"})),t.bytesLen>0&&e.viewOf({ptr:o,length:t.bytesLen,dtype:"u8"}).set(e.viewOf({ptr:t.bytesPtr,length:t.bytesLen,dtype:"u8"})),{count:t.count,offsetsPtr:r,bytesPtr:o,bytesLen:t.bytesLen}}var E=class extends Error{constructor(t){super(t),this.name="FrameError";}};function et(e,t){let n=zt(e,t),r=n?` Did you mean '${n}'?`:"",o=t.length?` Available columns: ${t.map(i=>`'${i}'`).join(", ")}.`:"";return new E(`unknown column '${e}'.${r}${o}`)}function rn(e,t,n,r){let o=r?` ${r}`:"";return new E(`dtype mismatch in '${e}': ${t} vs ${n}.${o}`)}function k(e,t){let n=e[t];if(typeof n!="function")throw new E(`kernel export not found: ${t}`);return n}var uo=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;async function co(e,t){if(uo){let[{readFile:i},{fileURLToPath:s}]=await Promise.all([import('fs/promises'),import('url')]),a;if(t===void 0)a=s(new URL(e,import.meta.url));else if(t instanceof URL)a=s(new URL(e,t));else if(t.startsWith("file:"))a=s(new URL(e,t));else {let{join:l}=await import('path');a=l(t,e);}return i(a)}let n=t??new URL(".",import.meta.url),r=new URL(e,n),o=await fetch(r);if(!o.ok)throw new E(`failed to fetch wasm at ${r.toString()}: ${o.status}`);return o.arrayBuffer()}function on(e,t){let n=e,r={memory:n.memory,alloc:n.alloc,free:n.free,realloc:n.realloc,mem_generation:n.mem_generation,simd:t};return {ctx:le(r),wasm:n}}async function sn(e={}){let t=e.simd??Vt(),n=await co(t?"simd.wasm":"scalar.wasm",e.wasmDir),{instance:r}=await WebAssembly.instantiate(n,{});return on(r.exports,t)}var Rt=null;async function fo(e){return Rt=await sn(e),Rt}function mo(e){Rt=e;}function Zt(){if(Rt===null)throw new E("no DataFrame runtime is loaded \u2014 call `await init()` first (or pass a runtime).");return Rt}var Bt=class{col;ctx;refs;constructor(t,n){this.ctx=t,this.col=n,this.refs=1;}retain(){return this.refs++,this}release(){this.refs<=0||--this.refs===0&&Y(this.ctx,this.col);}};function Ce(e){if(e instanceof BigInt64Array)return "i64";if(e instanceof Float64Array)return "f64";if(e instanceof Float32Array)return "f32";if(e instanceof Int32Array)return "i32";if(e instanceof Uint32Array)return "u32";if(e instanceof Uint8Array)return "bool";let t=e;for(let n=0;n<t.length;n++){let r=t[n];if(r!=null){if(typeof r=="bigint")return "i64";if(typeof r=="number")return "f64";if(typeof r=="boolean")return "bool";if(typeof r=="string")return "utf8"}}return "f64"}var po=new Set(["year","month","day","weekday","dayOfYear","quarter"]),Oe=class{constructor(t){this.series=t;}series;extract(t){let{dtype:n}=this.series;if(n==="date32"){if(!po.has(t))throw new TypeError(`dt.${t} is not supported for date32 columns (time-of-day fields are always 0 for date32; use year/month/day/weekday/dayOfYear/quarter, or cast to timestamp first).`)}else if(n!=="timestamp")throw new TypeError(`dt accessor requires a date32 or timestamp column, got ${n}.`);let r=this.series.col,o=this.series.ctx,i=r.length,s=n==="timestamp"&&r.tz?r.tz:void 0,a=null;if(r.validityPtr!==0){let f=r.validityBitOffset,m=Math.ceil((f+i)/8),d=o.viewOf({ptr:r.validityPtr,length:m,dtype:"u8"});if(f===0)a=d;else {let p=new Uint8Array(Math.ceil(i/8));for(let h=0;h<i;h++){let y=f+h;d[y>>3]>>(y&7)&1&&(p[h>>3]|=1<<(h&7));}a=p;}}let l;if(n==="date32"){let f=o.viewOf({ptr:r.dataPtr,length:i,dtype:"i32"});({data:l}=dt(f,a,t));}else {let f=o.viewOf({ptr:r.dataPtr,length:i,dtype:"i64"});({data:l}=dt(f,a,t,s));}let u=new Array(i);if(a!==null)for(let f=0;f<i;f++){let m=(a[f>>3]??0)>>(f&7)&1;u[f]=m?l[f]??0:null;}else for(let f=0;f<i;f++)u[f]=l[f]??0;let c=P(o,"i32",u);return new st(o,`${this.series.name}.dt.${t}`,c)}year(){return this.extract("year")}month(){return this.extract("month")}day(){return this.extract("day")}hour(){return this.extract("hour")}minute(){return this.extract("minute")}second(){return this.extract("second")}millisecond(){return this.extract("millisecond")}weekday(){return this.extract("weekday")}dayOfYear(){return this.extract("dayOfYear")}quarter(){return this.extract("quarter")}},Qt=class{constructor(t){this.series=t;}series;slice(t,n){let{dtype:r,col:o,name:i}=this.series,s=this.series.ctx;if(r!=="utf8")throw new TypeError(`str.slice requires a utf8 column, got ${r}.`);let a=o.length,l=o.dict?W(s,o.dict):[],u=l.length,c=new Int32Array(u),f=[],m=new Map;for(let y=0;y<u;y++){let g=n===void 0?l[y].slice(t):l[y].slice(t,n),b=m.get(g);b===void 0&&(b=f.length,f.push(g),m.set(g,b)),c[y]=b;}let d=s.viewOf({ptr:o.dataPtr,length:a,dtype:"i32"}),p=new Array(a);if(o.validityPtr===0)for(let y=0;y<a;y++)p[y]=f[c[d[y]]];else {let y=o.validityBitOffset,g=v(y+a),b=s.viewOf({ptr:o.validityPtr,length:g,dtype:"u8"});for(let w=0;w<a;w++)T(b,y+w)?p[w]=f[c[d[w]]]:p[w]=null;}let h=P(s,"utf8",p);return new st(s,`${i}.str.slice(${t}${n===void 0?"":`, ${n}`})`,h)}},st=class{name;dtype;length;ctx;column;constructor(t,n,r){this.ctx=t,this.name=n,this.dtype=r.dtype,this.length=r.length,this.column=r;}get col(){return this.column}toArray(){return K(this.ctx,this.column)}get(t){return t<0||t>=this.length?null:this.toArray()[t]??null}values(){return this.ctx.viewOf({ptr:this.column.dataPtr,length:this.length,dtype:C[this.dtype].view})}get dt(){if(this.dtype!=="date32"&&this.dtype!=="timestamp")throw new TypeError(`dt accessor requires a date32 or timestamp column, got ${this.dtype}.`);return new Oe(this)}get str(){if(this.dtype!=="utf8")throw new TypeError(`str accessor requires a utf8 column, got ${this.dtype}.`);return new Qt(this)}[Symbol.iterator](){return this.toArray()[Symbol.iterator]()}toString(){return `Series '${this.name}' (${this.dtype}, ${this.length} rows)`}};function an(e){return e==="bool"?"u8":e==="utf8"?"i32":C[e].wasm}function ht(e,t){if(t.validityPtr===0)return {ptr:0,owns:false};let n=t.validityBitOffset;if((n&7)===0)return {ptr:t.validityPtr+(n>>3),owns:false};let r=t.length,o=v(r),i=e.mod.alloc(Math.max(o,1)),s=e.viewOf({ptr:t.validityPtr,length:v(n+r),dtype:"u8"}),a=e.viewOf({ptr:i,length:o,dtype:"u8"});a.fill(0);for(let l=0;l<r;l++)T(s,n+l)&&S(a,l);return {ptr:i,owns:true}}function gt(e,t){t.owns&&t.ptr!==0&&(e.viewOf.forget({ptr:t.ptr,length:1,dtype:"u8"}),e.mod.free(t.ptr));}function ln(e,t){let n=(t.count+1)*4,r=e.mod.alloc(Math.max(n,1)),o=e.mod.alloc(Math.max(t.bytesLen,1));return e.viewOf({ptr:r,length:t.count+1,dtype:"i32"}).set(e.viewOf({ptr:t.offsetsPtr,length:t.count+1,dtype:"i32"})),t.bytesLen>0&&e.viewOf({ptr:o,length:t.bytesLen,dtype:"u8"}).set(e.viewOf({ptr:t.bytesPtr,length:t.bytesLen,dtype:"u8"})),{count:t.count,offsetsPtr:r,bytesPtr:o,bytesLen:t.bytesLen}}function un(e,t){return Math.max(t*C[e].size,1)}function Ie(e,t,n,r){let{ctx:o,wasm:i}=e,s=an(t.dtype),a=o.mod.alloc(un(t.dtype,r));k(i,`gather_${s}`)(t.dataPtr,n,r,a);let l=0;if(t.validityPtr!==0){let c=ht(o,t),f=v(r),m=o.mod.alloc(Math.max(f,1));o.viewOf({ptr:m,length:Math.max(f,1),dtype:"u8"}).fill(0),k(i,"gather_validity")(c.ptr,n,r,m),gt(o,c),l=m;}let u=t.dict?ln(o,t.dict):null;return {dtype:t.dtype,length:r,dataPtr:a,validityPtr:l,validityBitOffset:0,dict:u,owned:true}}function cn(e,t,n){let{ctx:r,wasm:o}=e,i=t.length>0?t[0].length:0,s=r.mod.alloc(Math.max(i*4,1)),a=r.viewOf({ptr:s,length:i,dtype:"i32"});for(let c=0;c<i;c++)a[c]=c;let l=k(o,"argsort_i32").length>=6,u=l?r.mod.alloc(Math.max(i*4,1)):0;try{for(let c=t.length-1;c>=0;c--)yo(e,t[c],n[c]===!0,s,i,u,l);}finally{u!==0&&(r.viewOf.forget({ptr:u,length:i,dtype:"i32"}),r.mod.free(u));}return {ptr:s,len:i}}function Te(e,t,n,r,o,i,s,a,l){let u=k(e,t);l?u(n,r,o,i,s,a):u(n,r,o,i,s);}function yo(e,t,n,r,o,i,s){let{ctx:a,wasm:l}=e,u=n?1:0,c=ht(a,t);try{if(t.dtype==="utf8"){let f=ho(e,t,o);try{Te(l,"argsort_i32",f,c.ptr,r,o,u,i,s);}finally{a.viewOf.forget({ptr:f,length:o,dtype:"i32"}),a.mod.free(f);}}else if(t.dtype==="bool"){let f=go(e,t,o);try{Te(l,"argsort_i32",f,c.ptr,r,o,u,i,s);}finally{a.viewOf.forget({ptr:f,length:o,dtype:"i32"}),a.mod.free(f);}}else {let f=C[t.dtype].wasm;Te(l,`argsort_${f}`,t.dataPtr,c.ptr,r,o,u,i,s);}}finally{gt(a,c);}}function ho(e,t,n){let{ctx:r}=e,o=t.dict?W(r,t.dict):[],i=o.map((c,f)=>f).sort((c,f)=>{let m=o[c],d=o[f];return m<d?-1:m>d?1:0}),s=new Int32Array(o.length);for(let c=0;c<i.length;c++)s[i[c]]=c;let a=r.mod.alloc(Math.max(n*4,1)),l=r.viewOf({ptr:t.dataPtr,length:n,dtype:"i32"}),u=r.viewOf({ptr:a,length:n,dtype:"i32"});for(let c=0;c<n;c++){let f=l[c];u[c]=f>=0&&f<s.length?s[f]:0;}return a}function go(e,t,n){let{ctx:r}=e,o=r.mod.alloc(Math.max(n*4,1)),i=r.viewOf({ptr:t.dataPtr,length:n,dtype:"bool"}),s=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let a=0;a<n;a++)s[a]=i[a];return o}function Pe(e,t){let n=0,r={};for(let{name:o,col:i}of t){let s=i.length,a=i.validityBitOffset,l=i.validityPtr===0?null:e.viewOf({ptr:i.validityPtr,length:v(a+s),dtype:"u8"});if(i.dtype==="utf8"){let u=e.viewOf({ptr:i.dataPtr,length:s,dtype:"i32"}),c=i.dict;Object.defineProperty(r,o,{enumerable:true,get(){return l&&!T(l,a+n)?null:q(e,c,u[n])}});}else if(i.dtype==="bool"){let u=e.viewOf({ptr:i.dataPtr,length:s,dtype:"bool"});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!T(l,a+n)?null:u[n]!==0}});}else if(i.dtype==="i64"){let u=e.viewOf({ptr:i.dataPtr,length:s,dtype:"i64"});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!T(l,a+n)?null:u[n]}});}else {let u=e.viewOf({ptr:i.dataPtr,length:s,dtype:C[i.dtype].view});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!T(l,a+n)?null:u[n]}});}}return {at(o){return n=o,r}}}function fn(e){if(e<=1)return 1;let t=1;for(;t<e;)t<<=1;return t}var mn=4,St=16;function Ft(e,t){if(t===0)return e.alloc(0);let n=e.alloc(t);if(n===0)throw new Error(`[hash stubs] OOM: alloc(${t}) returned 0`);return new Uint8Array(e.memory.buffer,n,t).fill(0),n}function dn(e,t,n,r,o){let i=Math.max(mn,fn(2*Math.max(n,1))),s=0;try{for(s=Ft(e,i*St);;){let a=e.group_build(t,n,s,i,r);if(a!==-1)return a;e.free(s),s=0,i*=2,s=Ft(e,i*St);}}finally{s!==0&&e.free(s);}}function pn(e,t,n,r,o,i,s,a,l){let u=Math.max(mn,fn(2*Math.max(a,1))),c=Math.max(1,o+a),f=0,m=0,d=0;try{if(f=Ft(e,u*St),m=e.alloc(c*4),m===0)throw new Error("[hash stubs] OOM: out_l_idx alloc failed");if(d=e.alloc(c*4),d===0)throw new Error("[hash stubs] OOM: out_r_idx alloc failed");for(;;){let p=t(n,r,o,i,s,a,f,u,m,d,c);if(p===-1){e.free(f),f=0,u*=2,f=Ft(e,u*St);continue}if(p>c){if(e.free(m),m=0,e.free(d),d=0,c=p,m=e.alloc(c*4),m===0)throw new Error("[hash stubs] OOM: out_l_idx resize failed");if(d=e.alloc(c*4),d===0)throw new Error("[hash stubs] OOM: out_r_idx resize failed");e.free(f),f=0,f=Ft(e,u*St);continue}let h=new Int32Array(e.memory.buffer,m,p).slice(),y=new Int32Array(e.memory.buffer,d,p).slice();return {count:p,lIdx:h,rIdx:y}}}finally{f!==0&&e.free(f),m!==0&&e.free(m),d!==0&&e.free(d);}}function yn(e,t,n,r,o,i,s,a){return pn(e,(l,u,c,f,m,d,p,h,y,g,b)=>e.join_hash_inner(l,u,c,f,m,d,p,h,y,g,b),t,n,r,o,i,s)}function hn(e,t,n,r,o,i,s,a){return pn(e,(l,u,c,f,m,d,p,h,y,g,b)=>e.join_hash_left(l,u,c,f,m,d,p,h,y,g,b),t,n,r,o,i,s)}var bo=new Set(["sum","mean","min","max","count","size","nunique","std","var","first","last"]),Mt=class{src;keys;constructor(t,n){this.src=t,this.keys=n;for(let r of n)if(t.dtypeOf(r)===void 0)throw et(r,t.columnNames())}agg(t){let{rt:n}=this.src,{ctx:r}=n,o=this.src.length,i=this.keys.map(u=>this.src.getColumn(u)),s=this.buildPlan(t),a=xo(n,i),l=[];try{let u=a.firstRow,c=[];for(let d=0;d<this.keys.length;d++){let p=Ao(n,i[d],u);l.push(p),c.push({name:this.keys[d],col:p});}let f=r.viewOf({ptr:a.groupIdsPtr,length:o,dtype:"i32"});for(let d of s){let p=Do(n,d,f,a.groupCount,o);l.push(p),c.push({name:d.outName,col:p});}let m=this.src.buildResult(c);return l.length=0,m}finally{for(let u of l)Y(r,u);for(let u of s)u.ownsOperand&&u.operand&&Y(r,u.operand);r.viewOf.forget({ptr:a.groupIdsPtr,length:o,dtype:"i32"}),r.mod.free(a.groupIdsPtr);}}buildPlan(t){let n=[];for(let[r,o]of Object.entries(t))if(o instanceof _)n.push(this.exprPlan(r,o));else if(Array.isArray(o))for(let i of o)n.push(this.columnPlan(`${r}_${i}`,r,i));else n.push(this.columnPlan(r,r,o));return n}columnPlan(t,n,r){if(!bo.has(r))throw new E(`unknown aggregation '${r}' for '${n}'.`);if(r==="size")return {outName:t,op:r,operand:null,operandDtype:"i32",ownsOperand:false,resultDtype:"i32"};let o=this.src.getColumn(n);if(!o)throw et(n,this.src.columnNames());let i=wo(r,o.dtype);return {outName:t,op:r,operand:o,operandDtype:o.dtype,ownsOperand:false,resultDtype:i}}exprPlan(t,n){let r=n.node;if(r.kind!=="agg")throw new E(`agg value for '${t}' must be a top-level aggregation (e.g. col('a').sum()).`);let o=r.op,i=ye(r.operand,this.src),s=Tt(o,i),a=Et(r.operand,this.src).execute();if(a.kind!=="column"||!a.column)throw new E(`aggregation operand for '${t}' did not produce a column.`);return {outName:t,op:o,operand:a.column,operandDtype:i,ownsOperand:true,resultDtype:s}}};function wo(e,t){return e==="size"?"i32":Tt(e,t)}function xo(e,t){let{ctx:n,wasm:r}=e,o=t.length>0?t[0].length:0,i=n.mod.alloc(Math.max(o*8,1));try{for(let f=0;f<t.length;f++){let m=t[f],d=vo(e,m,o),p=ht(n,m);try{if(f===0)k(r,`hash_${d.tok}`)(d.ptr,p.ptr,i,o);else {let h=n.mod.alloc(Math.max(o*8,1));try{k(r,`hash_${d.tok}`)(d.ptr,p.ptr,h,o),k(r,"hash_combine")(i,h,o);}finally{n.viewOf.forget({ptr:h,length:o,dtype:"u8"}),n.mod.free(h);}}}finally{gt(n,p),d.free();}}let s=n.mod.alloc(Math.max(o*4,1)),a=dn(r,i,o,s),l=n.viewOf({ptr:s,length:o,dtype:"i32"}),u=new Int32Array(a),c=0;for(let f=0;f<o&&c<a;f++)l[f]===c&&(u[c++]=f);return {groupIdsPtr:s,groupCount:a,firstRow:u}}finally{n.viewOf.forget({ptr:i,length:o,dtype:"u8"}),n.mod.free(i);}}function vo(e,t,n){let{ctx:r}=e;if(t.dtype==="utf8")return {ptr:t.dataPtr,tok:"i32",free(){}};if(t.dtype==="bool"){let o=r.mod.alloc(Math.max(n*4,1)),i=r.viewOf({ptr:t.dataPtr,length:n,dtype:"bool"}),s=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let a=0;a<n;a++)s[a]=i[a];return {ptr:o,tok:"i32",free(){r.viewOf.forget({ptr:o,length:n,dtype:"i32"}),r.mod.free(o);}}}return {ptr:t.dataPtr,tok:C[t.dtype].wasm,free(){}}}function Ao(e,t,n){let{ctx:r}=e,o=n.length,i=t.validityPtr===0?null:r.viewOf({ptr:t.validityPtr,length:v(t.validityBitOffset+t.length),dtype:"u8"}),s=t.validityBitOffset;if(t.dtype==="utf8"){let c=r.viewOf({ptr:t.dataPtr,length:t.length,dtype:"i32"}),f=t.dict,m=new Array(o);for(let d=0;d<o;d++){let p=n[d];m[d]=i&&!T(i,s+p)?null:q(r,f,c[p]);}return P(r,"utf8",m)}if(t.dtype==="i64"){let c=r.viewOf({ptr:t.dataPtr,length:t.length,dtype:"i64"}),f=new Array(o);for(let m=0;m<o;m++){let d=n[m];f[m]=i&&!T(i,s+d)?null:c[d];}return P(r,"i64",f)}let a=t.dtype==="bool",l=r.viewOf({ptr:t.dataPtr,length:t.length,dtype:C[t.dtype].view}),u=new Array(o);for(let c=0;c<o;c++){let f=n[c];i&&!T(i,s+f)?u[c]=null:u[c]=a?l[f]!==0:l[f];}return P(r,t.dtype,u)}function Do(e,t,n,r,o){let{ctx:i}=e,{op:s}=t;if(s==="size"){let g=new Array(r).fill(0);for(let b=0;b<o;b++){let w=n[b];g[w]=g[w]+1;}return P(i,"i32",g)}let a=t.operand,l=a.validityPtr===0?null:i.viewOf({ptr:a.validityPtr,length:v(a.validityBitOffset+o),dtype:"u8"}),u=a.validityBitOffset,c=g=>l===null||T(l,u+g);if(s==="count"){let g=new Array(r).fill(0);for(let b=0;b<o;b++)if(c(b)){let w=n[b];g[w]=g[w]+1;}return P(i,"i32",g)}if(s==="first"||s==="last")return Io(e,t,n,r,o,c);if(s==="nunique")return Oo(e,t,n,r,o,c);if(s==="std"||s==="var")return Co(e,t,n,r,o,c);if(a.dtype==="i64"){let g=i.viewOf({ptr:a.dataPtr,length:o,dtype:"i64"});if(s==="sum"){let x=new Array(r).fill(0n);for(let A=0;A<o;A++)if(c(A)){let O=n[A];x[O]=x[O]+g[A];}return P(i,"i64",x)}if(s==="mean"){let x=new Float64Array(r),A=new Int32Array(r);for(let D=0;D<o;D++){if(!c(D))continue;let I=n[D];x[I]=x[I]+Number(g[D]),A[I]=A[I]+1;}let O=new Array(r);for(let D=0;D<r;D++)O[D]=A[D]>0?x[D]/A[D]:null;return P(i,"f64",O)}let b=new Array(r).fill(null),w=s==="min";for(let x=0;x<o;x++){if(!c(x))continue;let A=n[x],O=g[x];b[A]===null?b[A]=O:b[A]=w?O<b[A]?O:b[A]:O>b[A]?O:b[A];}return P(i,"i64",b)}let f=i.viewOf({ptr:a.dataPtr,length:o,dtype:C[a.dtype].view}),m=new Array(r).fill(null);if(s==="sum"){let g=new Float64Array(r);for(let b=0;b<o;b++)if(c(b)){let w=n[b];g[w]=g[w]+f[b];}for(let b=0;b<r;b++)m[b]=g[b];return P(i,t.resultDtype,m)}if(s==="mean"){let g=new Float64Array(r),b=new Int32Array(r);for(let w=0;w<o;w++){if(!c(w))continue;let x=n[w];g[x]=g[x]+f[w],b[x]=b[x]+1;}for(let w=0;w<r;w++)m[w]=b[w]>0?g[w]/b[w]:null;return P(i,"f64",m)}let d=new Int32Array(r),p=new Int32Array(r),h=new Float64Array(r),y=s==="min";for(let g=0;g<o;g++){if(!c(g))continue;let b=n[g];d[b]=d[b]+1;let w=f[g];Number.isNaN(w)||(p[b]===0?h[b]=w:h[b]=y?Math.min(h[b],w):Math.max(h[b],w),p[b]=p[b]+1);}for(let g=0;g<r;g++)m[g]=d[g]===0?null:p[g]===0?NaN:h[g];return P(i,t.resultDtype,m)}function Co(e,t,n,r,o,i){let{ctx:s}=e,a=t.operand,l=a.dtype==="i64",u=l?s.viewOf({ptr:a.dataPtr,length:o,dtype:"i64"}):s.viewOf({ptr:a.dataPtr,length:o,dtype:C[a.dtype].view}),c=new Float64Array(r),f=new Int32Array(r);for(let y=0;y<o;y++){if(!i(y))continue;let g=n[y];c[g]=c[g]+(l?Number(u[y]):u[y]),f[g]=f[g]+1;}let m=new Float64Array(r);for(let y=0;y<r;y++)m[y]=f[y]>0?c[y]/f[y]:0;let d=new Float64Array(r);for(let y=0;y<o;y++){if(!i(y))continue;let g=n[y],w=(l?Number(u[y]):u[y])-m[g];d[g]=d[g]+w*w;}let p=new Array(r),h=t.op==="std";for(let y=0;y<r;y++)if(f[y]<2)p[y]=null;else {let g=d[y]/(f[y]-1);p[y]=h?Math.sqrt(g):g;}return P(s,"f64",p)}function Oo(e,t,n,r,o,i){let{ctx:s}=e,a=t.operand,l=new Array(r),u=a.dtype==="utf8"||a.dtype==="bool"?s.viewOf({ptr:a.dataPtr,length:o,dtype:a.dtype==="utf8"?"i32":"bool"}):a.dtype==="i64"?s.viewOf({ptr:a.dataPtr,length:o,dtype:"i64"}):s.viewOf({ptr:a.dataPtr,length:o,dtype:C[a.dtype].view});for(let f=0;f<o;f++){if(!i(f))continue;let m=n[f];(l[m]??=new Set).add(u[f]);}let c=new Array(r);for(let f=0;f<r;f++)c[f]=l[f]?l[f].size:0;return P(s,"i32",c)}function Io(e,t,n,r,o,i){let{ctx:s}=e,a=t.operand,l=t.op==="first",u=new Int32Array(r).fill(-1);for(let d=0;d<o;d++){if(!i(d))continue;let p=n[d];l?u[p]===-1&&(u[p]=d):u[p]=d;}let c=new Array(r);if(a.dtype==="utf8"){let d=s.viewOf({ptr:a.dataPtr,length:o,dtype:"i32"}),p=a.dict;for(let h=0;h<r;h++)c[h]=u[h]===-1?null:q(s,p,d[u[h]]);return P(s,"utf8",c)}if(a.dtype==="i64"){let d=s.viewOf({ptr:a.dataPtr,length:o,dtype:"i64"});for(let p=0;p<r;p++){let h=u[p];c[p]=h===-1?null:d[h];}return P(s,"i64",c)}let f=a.dtype==="bool",m=s.viewOf({ptr:a.dataPtr,length:o,dtype:C[a.dtype].view});for(let d=0;d<r;d++){let p=u[d];c[d]=p===-1?null:f?m[p]!==0:m[p];}return P(s,a.dtype,c)}function On(e,t,n){let r=n.how??"inner",o=Array.isArray(n.on)?n.on:[n.on];if(o.length===0)throw new E("join requires at least one key in `on`.");let i=e.rt,{ctx:s}=i,a=e.length,l=t.length;for(let c of o){let f=e.dtypeOf(c);if(f===void 0)throw et(c,e.columnNames());let m=t.dtypeOf(c);if(m===void 0)throw et(c,t.columnNames());if(f!==m)throw rn("join",f,m,`join key '${c}' must have one dtype.`)}let u=o.map(c=>Bo(i,e.getColumn(c),t.getColumn(c),a,l));try{let c=Dn(i,u.map(h=>({ptr:h.leftPtr,tok:h.tok})),a),f=Dn(i,u.map(h=>({ptr:h.rightPtr,tok:h.tok})),l),m=Cn(i,o.map(h=>e.getColumn(h)),a),d=Cn(i,o.map(h=>t.getColumn(h)),l),p;try{let h=i.wasm;p=r==="left"?hn(h,c,m.ptr,a,f,d.ptr,l):yn(h,c,m.ptr,a,f,d.ptr,l);}finally{s.viewOf.forget({ptr:c,length:a,dtype:"u8"}),s.mod.free(c),s.viewOf.forget({ptr:f,length:l,dtype:"u8"}),s.mod.free(f),bt(i,m.ptr,m.owns),bt(i,d.ptr,d.owns);}return To(e,t,o,p,r)}finally{for(let c of u)c.free();}}function To(e,t,n,r,o){let i=e.rt,{ctx:s}=i,a=r.count,l=new Set(n),u=e.columnNames(),c=t.columnNames().filter(y=>!l.has(y)),f=new Set(u),m=gn(i,r.lIdx,a),d,p=null;o==="left"?(p=ko(r.rIdx,a),d=Po(i,r.rIdx,a)):d=gn(i,r.rIdx,a);let h=[];try{let y=[];for(let b of u){let w=xn(i,e.getColumn(b),m,a,null);h.push(w),y.push({name:b,col:w});}for(let b of c){let w=xn(i,t.getColumn(b),d,a,p);h.push(w);let x=f.has(b)?`${b}_right`:b;y.push({name:x,col:w});}let g=e.buildResult(y);return h.length=0,g}finally{for(let y of h)Y(s,y);s.mod.free(m),s.mod.free(d);}}function gn(e,t,n){let r=e.ctx.mod.alloc(Math.max(n*4,1));return n>0&&new Int32Array(e.wasm.memory.buffer,r,n).set(t),r}function Po(e,t,n){let r=e.ctx.mod.alloc(Math.max(n*4,1));if(n>0){let o=new Int32Array(e.wasm.memory.buffer,r,n);for(let i=0;i<n;i++)o[i]=t[i]<0?0:t[i];}return r}function ko(e,t){let n=false;for(let i=0;i<t;i++)if(e[i]<0){n=true;break}if(!n)return null;let r=v(t),o=new Uint8Array(r).fill(255);for(let i=0;i<t;i++)if(e[i]<0){let s=i>>3;o[s]=o[s]&~(1<<(i&7));}return t&7&&(o[r-1]=o[r-1]&(1<<(t&7))-1),o}function bn(e,t,n,r,o){return {dtype:e,length:t,dataPtr:n,validityPtr:r,validityBitOffset:0,dict:o,owned:true}}function Eo(e,t){let{count:n,offsetsPtr:r,bytesPtr:o,bytesLen:i}=t,s=(n+1)*4,a=e.ctx.mod.alloc(s),l=e.ctx.mod.alloc(Math.max(i,1)),u=e.wasm.memory.buffer;return new Uint8Array(u,a,s).set(new Uint8Array(u,r,s)),i>0&&new Uint8Array(u,l,i).set(new Uint8Array(u,o,i)),{count:n,offsetsPtr:a,bytesPtr:l,bytesLen:i}}function wn(e,t,n,r,o){let i=t.validityPtr!==0,s=o!==null;if(!i&&!s)return 0;let a=v(r);if(!s){let u=e.ctx.mod.alloc(Math.max(a,1));return k(e.wasm,"gather_validity")(t.validityPtr,n,r,u),u}let l=e.ctx.mod.alloc(Math.max(a,1));if(new Uint8Array(e.wasm.memory.buffer,l,a).set(o),i){let u=e.ctx.mod.alloc(Math.max(a,1));try{k(e.wasm,"gather_validity")(t.validityPtr,n,r,u);let c=new Uint8Array(e.wasm.memory.buffer,l,a),f=new Uint8Array(e.wasm.memory.buffer,u,a);for(let m=0;m<a;m++)c[m]=c[m]&f[m];}finally{e.ctx.mod.free(u);}}return l}var Ro={bool:"u8"};function xn(e,t,n,r,o){let{ctx:i}=e;if(t.dtype==="utf8"){let u=i.mod.alloc(Math.max(r*4,1));r>0&&k(e.wasm,"gather_i32")(t.dataPtr,n,r,u);let c=Eo(e,t.dict);return bn("utf8",r,u,wn(e,t,n,r,o),c)}let s=C[t.dtype],a=Ro[s.wasm]??s.wasm,l=i.mod.alloc(Math.max(r*s.size,1));return r>0&&k(e.wasm,`gather_${a}`)(t.dataPtr,n,r,l),bn(t.dtype,r,l,wn(e,t,n,r,o),null)}var In="i64_direct";function Bo(e,t,n,r,o){if(t.dtype==="utf8"){let i=vn(e,t,r),s=vn(e,n,o);return {leftPtr:i,rightPtr:s,tok:In,free(){bt(e,i,true),bt(e,s,true);}}}if(t.dtype==="bool"){let i=An(e,t,r),s=An(e,n,o);return {leftPtr:i,rightPtr:s,tok:"i32",free(){bt(e,i,true),bt(e,s,true);}}}return {leftPtr:t.dataPtr,rightPtr:n.dataPtr,tok:C[t.dtype].wasm,free(){}}}function vn(e,t,n){let{ctx:r,wasm:o}=e,i=t.dict,s=i.count,a=r.mod.alloc(Math.max(s*8,1));try{k(o,"hash_utf8_dict")(i.offsetsPtr,i.bytesPtr,s,a);let l=r.mod.alloc(Math.max(n*8,1));return s===0||n===0||k(o,"gather_i64")(a,t.dataPtr,n,l),l}finally{r.mod.free(a);}}function An(e,t,n){let{ctx:r}=e,o=r.mod.alloc(Math.max(n*4,1)),i=r.viewOf({ptr:t.dataPtr,length:n,dtype:"bool"}),s=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let a=0;a<n;a++)s[a]=i[a];return o}function Dn(e,t,n){let{ctx:r,wasm:o}=e,i=r.mod.alloc(Math.max(n*8,1)),s=n*8;for(let a=0;a<t.length;a++){let l=t[a];if(l.tok===In)if(a===0){if(s>0){let u=o.memory.buffer;new Uint8Array(u,i,s).set(new Uint8Array(u,l.ptr,s));}}else k(o,"hash_combine")(i,l.ptr,n);else if(a===0)k(o,`hash_${l.tok}`)(l.ptr,0,i,n);else {let u=r.mod.alloc(Math.max(n*8,1));try{k(o,`hash_${l.tok}`)(l.ptr,0,u,n),k(o,"hash_combine")(i,u,n);}finally{r.viewOf.forget({ptr:u,length:n,dtype:"u8"}),r.mod.free(u);}}}return i}function Cn(e,t,n){let{ctx:r}=e,o=t.filter(u=>u.validityPtr!==0);if(o.length===0)return {ptr:0,owns:false};let i=v(n),s=r.mod.alloc(Math.max(i,1)),a=r.viewOf({ptr:s,length:Math.max(i,1),dtype:"u8"});a.fill(0);let l=o.map(u=>({view:r.viewOf({ptr:u.validityPtr,length:v(u.validityBitOffset+n),dtype:"u8"}),bitOff:u.validityBitOffset}));for(let u=0;u<n;u++){let c=true;for(let f of l)if(!T(f.view,f.bitOff+u)){c=false;break}c&&S(a,u);}return {ptr:s,owns:true}}function bt(e,t,n){n&&t!==0&&(e.ctx.viewOf.forget({ptr:t,length:1,dtype:"u8"}),e.ctx.mod.free(t));}function Tn(e,t){if(e===null)return "null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="string")return e.length>24?`${e.slice(0,23)}\u2026`:e;if(t==="date32"&&typeof e=="number")return new Date(e*864e5).toISOString().slice(0,10);if(typeof e=="bigint")return t==="timestamp"?new Date(Number(e)).toISOString():String(e);if(Number.isNaN(e))return "NaN";if(e===1/0)return "inf";if(e===-1/0)return "-inf";if(Number.isInteger(e))return String(e);if(t==="f32"||t==="f64"){let n=e.toPrecision(6);return n.includes(".")&&!n.includes("e")?n.replace(/0+$/,"").replace(/\.$/,""):n}return String(e)}function Pn(e){return e==="utf8"||e==="bool"?"left":"right"}function So(e,t,n){let r=t-e.length;return r<=0?e:n==="right"?" ".repeat(r)+e:e+" ".repeat(r)}function kn(e,t,n,r,o){let i=e.length,s=new Array(i);for(let c=0;c<i;c++){let f=Math.max(e[c].length,t[c].length);for(let m of n)f=Math.max(f,m[c].length);s[c]=f;}let a=c=>c.map((f,m)=>So(f,s[m],r[m])).join(" "),l=s.map(c=>"\u2500".repeat(c)).join(" "),u=[];u.push(a(e)),u.push(a(t)),u.push(l);for(let c of n)u.push(a(c));return o&&u.push(o),u.join(`
2
+ `)}var Mo=new Set(["f64","f32","i32","u32","i64"]),j=class e{length;_rt;entries;byName;disposed=false;constructor(t,n,r){this._rt=t,this.entries=n,this.length=r,this.byName=new Map(n.map(o=>[o.name,o]));}get ctx(){return this._rt.ctx}get wasm(){return this._rt.wasm}get rt(){return this._rt}getColumn(t){return this.byName.get(t)?.col}dtypeOf(t){return this.byName.get(t)?.col.dtype}columnNames(){return this.entries.map(t=>t.name)}buildResult(t){let n=t.length>0?t[0].col.length:this.length;return e.fromRoots(this._rt,t,n)}static fromColumns(t,n={}){let r=n.runtime??Zt(),o=[],i=-1;for(let[s,a]of Object.entries(t)){let l=n.dtypes?.[s]??Ce(a),u=l==="timestamp"?n.tzs?.[s]:void 0,c=P(r.ctx,l,a,u);if(i===-1)i=c.length;else if(c.length!==i)throw new E(`column '${s}' has length ${c.length}, expected ${i}.`);o.push({name:s,col:c});}return e.fromRoots(r,o,i===-1?0:i)}static fromRecords(t,n={}){n.runtime??Zt();let o=[],i=new Set;for(let a of t)for(let l of Object.keys(a))i.has(l)||(i.add(l),o.push(l));let s={};for(let a of o){let l=new Array(t.length);for(let u=0;u<t.length;u++){let c=t[u][a];l[u]=c===void 0?null:c;}s[a]=l;}return e.fromColumns(s,n)}static fromRoots(t,n,r){let o=n.map(i=>({name:i.name,col:i.col,owner:new Bt(t.ctx,i.col)}));return new e(t,o,r)}static _adoptColumns(t,n,r){return e.fromRoots(t,n,r)}get shape(){return [this.length,this.entries.length]}get columns(){return this.columnNames()}get dtypes(){let t={};for(let n of this.entries)t[n.name]=n.col.dtype;return t}col(t){let n=this.entryOf(t);return new st(this._rt.ctx,t,n.col)}select(t){return new e(this._rt,this.shareEntries(t),this.length)}drop(t){let n=new Set(t);for(let o of t)if(!this.byName.has(o))throw et(o,this.columnNames());let r=this.entries.filter(o=>!n.has(o.name)).map(o=>o.name);return new e(this._rt,this.shareEntries(r),this.length)}withColumn(t,n,r={}){let o=this.materializeColumn(n,r),i=new Bt(this._rt.ctx,o),s={name:t,col:o,owner:i},a=[],l=false;for(let u of this.entries)u.name===t?(a.push(s),l=true):a.push(this.retainEntry(u));return l||a.push(s),new e(this._rt,a,this.length)}assign(t,n,r){return this.withColumn(t,n,r)}filter(t){let n=ve(t,this).execute();try{let r=this.entries.map(o=>({name:o.name,col:n.compact(o.col)}));return e.fromRoots(this._rt,r,n.count)}finally{n.free();}}filterFn(t){let n=Pe(this._rt.ctx,this.entries),r=[];for(let o=0;o<this.length;o++)t(n.at(o))&&r.push(o);return this.gatherRows(r)}mapFn(t){let n=Pe(this._rt.ctx,this.entries),r=new Array(this.length);for(let o=0;o<this.length;o++)r[o]=t(n.at(o));return r}sortValues(t,n={}){let r=typeof t=="string"?[t]:[...t];if(r.length===0)throw new E("sortValues requires at least one key.");let o=r.map(a=>this.entryOf(a).col),i=Array.isArray(n.descending)?r.map((a,l)=>n.descending[l]===true):r.map(()=>n.descending===true),s=cn(this._rt,o,i);try{let a=this.entries.map(l=>({name:l.name,col:Ie(this._rt,l.col,s.ptr,s.len)}));return e.fromRoots(this._rt,a,s.len)}finally{this._rt.ctx.viewOf.forget({ptr:s.ptr,length:s.len,dtype:"i32"}),this._rt.ctx.mod.free(s.ptr);}}groupby(t){let n=typeof t=="string"?[t]:[...t];if(n.length===0)throw new E("groupby requires at least one key.");return new Mt(this,n)}join(t,n){return On(this,t,n)}head(t=5){return this.sliceRange(0,t)}tail(t=5){return this.sliceRange(Math.max(0,this.length-t),this.length)}slice(t,n=this.length){return this.sliceRange(t,n)}sliceRange(t,n){let r=Math.max(0,Math.min(t,this.length)),o=Math.max(r,Math.min(n,this.length)),i=this.entries.map(s=>({name:s.name,col:$t(s.col,r,o),owner:s.owner.retain()}));return new e(this._rt,i,o-r)}toColumns(){let t={};for(let n of this.entries)t[n.name]=K(this._rt.ctx,n.col);return t}toRecords(){let t=this.toColumns(),n=this.columnNames(),r=new Array(this.length);for(let o=0;o<this.length;o++){let i={};for(let s of n)i[s]=t[s][o];r[o]=i;}return r}describe(){let t=["count","mean","std","min","25%","50%","75%","max"],n=this.entries.filter(i=>Mo.has(i.col.dtype)),r={statistic:t},o={statistic:"utf8"};for(let i of n)r[i.name]=Uo(K(this._rt.ctx,i.col)),o[i.name]="f64";return e.fromColumns(r,{runtime:this._rt,dtypes:o})}dispose(){if(!this.disposed){this.disposed=true;for(let t of this.entries)t.owner.release();}}toString(){return this.render()}[Symbol.for("nodejs.util.inspect.custom")](){return this.render()}entryOf(t){let n=this.byName.get(t);if(!n)throw et(t,this.columnNames());return n}retainEntry(t){return t.owner.retain(),{name:t.name,col:t.col,owner:t.owner}}shareEntries(t){return t.map(n=>this.retainEntry(this.entryOf(n)))}materializeColumn(t,n){if(t instanceof _){let o=Et(t,this).execute();if(o.kind==="column"&&o.column)return o.column;let i=o.scalar,s=new Array(this.length).fill(i.value);return P(this._rt.ctx,i.dtype,s)}let r=n.dtype??Ce(t);if(t.length!==this.length)throw new E(`withColumn value has length ${t.length}, expected ${this.length}.`);return P(this._rt.ctx,r,t)}gatherRows(t){let{ctx:n}=this._rt,r=t.length,o=n.mod.alloc(Math.max(r*4,1));try{let i=n.viewOf({ptr:o,length:r,dtype:"i32"});for(let a=0;a<r;a++)i[a]=t[a];let s=this.entries.map(a=>({name:a.name,col:Ie(this._rt,a.col,o,r)}));return e.fromRoots(this._rt,s,r)}finally{n.viewOf.forget({ptr:o,length:r,dtype:"i32"}),n.mod.free(o);}}render(){let t=this.columnNames();if(t.length===0)return `Empty DataFrame [${this.length} rows \xD7 0 columns]`;let n=this.entries.map(c=>c.col.dtype),r=n.map(Pn),o=5,i=5,s=[],a=this.length>o+i,l=(c,f)=>{let m=this.entries.map(d=>K(this._rt.ctx,$t(d.col,c,f)));for(let d=0;d<f-c;d++)s.push(m.map((p,h)=>Tn(p[d],n[h])));};a?(l(0,o),s.push(t.map(()=>"\u2026")),l(this.length-i,this.length)):l(0,this.length);let u=`[${this.length} rows \xD7 ${t.length} columns]`;return kn(t,n,s,r,u)}};function _o(e){let t=[],n=r=>(t.push(r),r);try{return e(n)}finally{for(let r of t)r.dispose();}}function Uo(e){let t=[];for(let l of e){if(l===null)continue;let u=typeof l=="bigint"?Number(l):l;Number.isFinite(u)&&t.push(u);}let n=t.length;if(n===0)return [0,null,null,null,null,null,null,null];let r=t.slice().sort((l,u)=>l-u),i=t.reduce((l,u)=>l+u,0)/n,s=n>=2?Math.sqrt(t.reduce((l,u)=>l+(u-i)*(u-i),0)/(n-1)):null,a=l=>{if(r.length===1)return r[0];let u=l*(r.length-1),c=Math.floor(u),f=Math.ceil(u),m=u-c;return r[c]+(r[f]-r[c])*m};return [n,i,s,r[0],a(.25),a(.5),a(.75),r[r.length-1]]}var Vo=["","null","NA"],No=100,te=class{buf="";row=[];field="";inQuote=false;delim;onRow;constructor(t,n){this.delim=t,this.onRow=n;}feed(t){this.buf+=t,this.parse(false);}finish(){this.parse(true);}parse(t){let n=this.delim,r=0,o=this.buf,i=o.length;for(;r<i;){let s=o[r];if(this.inQuote)if(s==='"')if(r+1<i)o[r+1]==='"'?(this.field+='"',r+=2):(this.inQuote=false,r++);else if(t)this.inQuote=false,r++;else break;else this.field+=s,r++;else if(s==='"')this.inQuote=true,r++;else if(o.startsWith(n,r))this.row.push(this.field),this.field="",r+=n.length;else if(s==="\r")if(r+1<i)o[r+1]===`
3
+ `?(this.emitRow(),r+=2):(this.field+=s,r++);else if(t)this.emitRow(),r++;else break;else s===`
4
+ `?(this.emitRow(),r++):(this.field+=s,r++);}if(this.buf=o.slice(r),t&&(this.row.length>0||this.field.length>0)){if(this.inQuote)throw new Error(`CSV parse error: unterminated quoted field starting near "${this.field.slice(0,40)}"`);this.emitRow();}}emitRow(){this.row.push(this.field),this.field="",this.onRow(this.row),this.row=[];}},$o=-2147483648,Lo=2**31-1,Rn=9223372036854775807n,Bn=-9223372036854775808n,jo=9007199254740991n;function Ee(e){if(e.length===0)return false;let t=0;if(e[0]==="-"&&(t=1),t===e.length||e.length-t>1&&e[t]==="0")return false;for(;t<e.length;t++){let n=e.charCodeAt(t);if(n<48||n>57)return false}return true}function En(e){if(!Ee(e))return false;let t=Number(e);return t>=$o&&t<=Lo&&Number.isInteger(t)}function zo(e){if(!Ee(e))return false;try{let t=BigInt(e);return (t<0n?-t:t)>jo&&t>=Bn&&t<=Rn}catch{return false}}function Wo(e){if(!Ee(e))return false;try{let t=BigInt(e);return t>=Bn&&t<=Rn}catch{return false}}function ke(e){if(e.length===0||e.trim().length===0)return false;let t=Number(e);return !isNaN(t)}function Xt(e){let t=e.toLowerCase();return t==="true"||t==="false"}function qo(e,t){return e==="utf8"?"utf8":e==="i32"?En(t)?"i32":zo(t)?"i64":ke(t)?"f64":Xt(t)?"bool":"utf8":e==="i64"?Wo(t)?"i64":ke(t)?"f64":Xt(t)?"bool":"utf8":e==="f64"?ke(t)?"f64":Xt(t)?"bool":"utf8":Xt(t)?"bool":(En(t),"utf8")}function Ho(e,t){let n="i32",r=false;for(let o of e)if(!t.has(o)&&(r=true,n=qo(n,o),n==="utf8"))return "utf8";return r?n:"utf8"}function Ko(e){try{return BigInt(e)}catch{throw new Error(`CSV parse error: cannot parse '${e}' as i64 \u2014 expected an integer decimal string.`)}}var Yo=/^(-?\d{4,})-(\d{2})-(\d{2})$/;function Jo(e){let t=Yo.exec(e);if(!t)throw new Error(`CSV parse error: cannot parse '${e}' as date32 \u2014 expected strict 'yyyy-MM-dd' format.`);let n=Number(t[1]),r=Number(t[2]),o=Number(t[3]);if(r<1||r>12||o<1||o>31)throw new Error(`CSV parse error: invalid date components in '${e}' (month=${r}, day=${o}).`);return Kt(n,r,o)}var Go=/Z$|[+-]\d{2}:?\d{2}$/;function Zo(e){if(!Go.test(e))throw new Error(`CSV parse error: timestamp '${e}' has no timezone (Z or UTC offset required). Ambiguous local-time strings are rejected to avoid silent tz guessing \u2014 use '${e}Z' for UTC or append an explicit offset like '+00:00'.`);let t=Date.parse(e);if(isNaN(t))throw new Error(`CSV parse error: cannot parse '${e}' as ISO-8601 timestamp.`);return BigInt(t)}function Qo(e,t,n){if(n.has(e))return null;switch(t){case "i64":return Ko(e);case "date32":return Jo(e);case "timestamp":return Zo(e);case "i32":case "u32":case "f64":case "f32":return Number(e);case "bool":return e.toLowerCase()==="true";case "utf8":return e;default:return e}}function Xo(e,t={}){let n=t.delimiter??",",r=t.header!==false,o=t.skipRows??0,i=t.maxRows??1/0,s=new Set(t.nullValues??Vo),a=t.dtypes??{},l=[],u=new te(n,x=>l.push(x));u.feed(e),u.finish();let c=x=>x?{runtime:x}:{};if(l.length===0)return j.fromColumns({},c(t.runtime));let f=o;if(f>=l.length)return j.fromColumns({},c(t.runtime));let m,d;if(r?(m=l[f],d=f+1):(m=l[f].map((A,O)=>t.columns?.[O]??`column_${O}`),d=f),t.columns)for(let x=0;x<t.columns.length;x++)m[x]=t.columns[x];let p=m.length,h=l.slice(d,d+(isFinite(i)?i:l.length));for(let x=0;x<h.length;x++)if(h[x].length!==p)throw new Error(`CSV parse error: row ${d+x+1} has ${h[x].length} fields, expected ${p} (columns: ${m.join(", ")})`);if(h.length===0){let x={},A={};for(let D of m)x[D]=[],A[D]=a[D]??"utf8";let O={...c(t.runtime),dtypes:A};return j.fromColumns(x,O)}let y=h.slice(0,No),g={};for(let x=0;x<p;x++){let A=m[x];if(a[A])g[A]=a[A];else {let O=y.map(D=>D[x]);g[A]=Ho(O,s);}}let b={};for(let x of m)b[x]=new Array(h.length);for(let x=0;x<h.length;x++){let A=h[x];for(let O=0;O<p;O++){let D=m[O];b[D][x]=Qo(A[O],g[D],s);}}let w={...c(t.runtime),dtypes:g};return j.fromColumns(b,w)}function ti(e,t={}){let n=JSON.parse(e);if(!Array.isArray(n))throw new TypeError(`fromJSON: expected a JSON array of records, got ${typeof n}`);return j.fromRecords(n,t)}function ei(e){return JSON.stringify(e.toRecords())}var _t=class{space;dv;head;vtableFields=new Map;objectStart=0;constructor(t=512){this.space=new Uint8Array(t),this.dv=new DataView(this.space.buffer),this.head=t;}offset(){return this.space.length-this.head}grow(t){let n=Math.max(this.space.length*2,this.space.length+t),r=new Uint8Array(n),o=this.space.length-this.head;r.set(this.space.subarray(this.head),n-o),this.head=n-o,this.space=r,this.dv=new DataView(r.buffer);}prep(t,n){let r=~(this.offset()+n)+1&t-1;this.head<t+r+n&&this.grow(t+r+n);for(let o=0;o<r;o++)this.space[--this.head]=0;}writeU8(t){this.prep(1,0),this.space[--this.head]=t&255;}writeU16(t){this.prep(2,0),this.head-=2,this.dv.setUint16(this.head,t,true);}writeI32(t){this.prep(4,0),this.head-=4,this.dv.setInt32(this.head,t,true);}writeU32(t){this.prep(4,0),this.head-=4,this.dv.setUint32(this.head,t,true);}writeI64(t,n=0){this.prep(8,0),this.head-=8,this.dv.setInt32(this.head,t,true),this.dv.setInt32(this.head+4,n,true);}createString(t){let n=new TextEncoder().encode(t);this.prep(4,n.length+1),this.space[--this.head]=0;for(let r=n.length-1;r>=0;r--)this.space[--this.head]=n[r];return this.writeU32(n.length),this.offset()}createByteVector(t){this.prep(4,t.length);for(let n=t.length-1;n>=0;n--)this.space[--this.head]=t[n];return this.writeU32(t.length),this.offset()}createOffsetVector(t){this.prep(4,t.length*4);for(let n=t.length-1;n>=0;n--){let r=this.offset()+4-t[n];this.head-=4,this.dv.setUint32(this.head,r,true);}return this.writeU32(t.length),this.offset()}createStructVector(t,n){this.prep(8,t.length);for(let r=t.length-1;r>=0;r--)this.space[--this.head]=t[r];return this.writeU32(n),this.offset()}startTable(){this.vtableFields=new Map,this.objectStart=this.offset();}addFieldBool(t,n,r=false){n!==r&&(this.writeU8(n?1:0),this.vtableFields.set(t,this.offset()));}addFieldI8(t,n,r=0){n!==r&&(this.writeU8(n&255),this.vtableFields.set(t,this.offset()));}addFieldI16(t,n,r=0){n!==r&&(this.writeU16(n),this.vtableFields.set(t,this.offset()));}addFieldI32(t,n,r=0){n!==r&&(this.writeI32(n),this.vtableFields.set(t,this.offset()));}addFieldI64(t,n,r=0){n===0&&r===0||(this.writeI64(n,r),this.vtableFields.set(t,this.offset()));}addFieldOffset(t,n){this.prep(4,0),this.head-=4;let r=this.offset()-n;this.dv.setUint32(this.head,r,true),this.vtableFields.set(t,this.offset());}endTable(){this.vtableFields.size;let t=this.vtableFields.size===0?0:Math.max(...this.vtableFields.keys())+1;this.writeI32(0);let n=this.offset(),r=n-this.objectStart,o=4+t*2;for(let a=t-1;a>=0;a--){let l=this.vtableFields.get(a),u=l!==void 0?n-l:0;this.writeU16(u);}this.writeU16(r),this.writeU16(o);let s=this.offset()-n;return this.dv.setInt32(this.space.length-n,s,true),n}finish(t){return this.prep(4,0),this.head-=4,this.dv.setUint32(this.head,this.offset()-t,true),this.space.slice(this.head)}},Re=class e{constructor(t,n){this.dv=t;this.pos=n;}dv;pos;fieldPos(t){let{dv:n,pos:r}=this,o=n.getInt32(r,true),i=r-o,s=n.getUint16(i,true),a=4+t*2;if(a>=s)return 0;let l=n.getUint16(i+a,true);return l===0?0:r+l}getInt8(t,n=0){let r=this.fieldPos(t);return r?this.dv.getInt8(r):n}getUint8(t,n=0){let r=this.fieldPos(t);return r?this.dv.getUint8(r):n}getInt16(t,n=0){let r=this.fieldPos(t);return r?this.dv.getInt16(r,true):n}getInt32(t,n=0){let r=this.fieldPos(t);return r?this.dv.getInt32(r,true):n}getBool(t,n=false){let r=this.fieldPos(t);return r?this.dv.getUint8(r)!==0:n}getInt64(t){let n=this.fieldPos(t);return n===0?[0,0]:[this.dv.getInt32(n,true),this.dv.getInt32(n+4,true)]}getInt64Num(t){let[n,r]=this.getInt64(t);return r*4294967296+(n>>>0)}follow(t){return t+this.dv.getUint32(t,true)}getString(t){let n=this.fieldPos(t);if(n===0)return null;let r=this.follow(n),o=this.dv.getUint32(r,true);return new TextDecoder().decode(new Uint8Array(this.dv.buffer,this.dv.byteOffset+r+4,o))}getTable(t){let n=this.fieldPos(t);return n===0?null:new e(this.dv,this.follow(n))}vectorLen(t){let n=this.fieldPos(t);return n===0?0:this.dv.getUint32(this.follow(n),true)}vectorTable(t,n){let r=this.fieldPos(t),i=this.follow(r)+4+n*4;return new e(this.dv,i+this.dv.getUint32(i,true))}structVectorElemPos(t,n,r){let o=this.fieldPos(t);return o===0?0:this.follow(o)+4+n*r}i32at(t){return this.dv.getInt32(t,true)}i64at(t){let n=this.dv.getInt32(t,true);return this.dv.getInt32(t+4,true)*4294967296+(n>>>0)}};function wt(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0,true);return new Re(t,n)}var _n=4,Un=1,_e=2,Ue=3,ee=2,Se=3,Vn=5,Nn=6,$n=8,Ln=10,ni=20,ri=1,jn=2,xt=16,zn=0,Fe=1,re=0,Ve=1,oi=2,ii=3,si=9223372036854775n,ai=-9223372036854775n,oe=e=>e+7&-8;function li(e,t){let n=new Uint8Array(Math.ceil(t/8));for(let r=0;r<t;r++)(e[r]??0)!==0&&(n[r>>3]|=1<<(r&7));return n}function ui(e,t){let n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=e[r>>3]>>(r&7)&1;return n}function ci(e,t){if(t.validityPtr===0)return null;let n=t.validityBitOffset+t.length,r=e.viewOf({ptr:t.validityPtr,length:v(n),dtype:"u8"});if(t.validityBitOffset===0)return r.slice(0,v(t.length));let o=new Uint8Array(v(t.length));for(let i=0;i<t.length;i++)T(r,t.validityBitOffset+i)&&S(o,i);return o}function Sn(e){return e.startTable(),e.endTable()}function ne(e,t,n){return e.startTable(),e.addFieldI32(0,t,0),e.addFieldBool(1,n,false),e.endTable()}function Fn(e,t){return e.startTable(),e.addFieldI16(0,t,0),e.endTable()}function fi(e,t){let n=ne(e,32,true);return e.startTable(),e.addFieldI64(0,t),e.addFieldOffset(1,n),e.endTable()}function mi(e){return e.startTable(),e.addFieldI16(0,zn,Fe),e.endTable()}function di(e,t){let n=t?e.createString(t):null;return e.startTable(),e.addFieldI16(0,Ve,re),n!==null&&e.addFieldOffset(1,n),e.endTable()}function pi(e,t,n,r,o){let i=e.createString(t),s,a,l=null;switch(n){case "f64":s=Se,a=Fn(e,jn);break;case "f32":s=Se,a=Fn(e,ri);break;case "i32":s=ee,a=ne(e,32,true);break;case "u32":s=ee,a=ne(e,32,false);break;case "i64":s=ee,a=ne(e,64,true);break;case "bool":s=Nn,a=Sn(e);break;case "utf8":s=Vn,a=Sn(e),r!==null&&(l=fi(e,r));break;case "date32":s=$n,a=mi(e);break;case "timestamp":s=Ln,a=di(e,o);break;default:throw new Error(`Arrow toArrow: unsupported dtype '${String(n)}'`)}let u=e.createOffsetVector([]);return e.startTable(),e.addFieldOffset(0,i),e.addFieldBool(1,true,false),e.addFieldI8(2,s),e.addFieldOffset(3,a),l!==null&&e.addFieldOffset(4,l),e.addFieldOffset(5,u),e.endTable()}function yi(e,t,n,r){let o=new _t(1024),i=e.map((u,c)=>pi(o,u,t[c],n[c],r[c])),s=o.createOffsetVector(i);o.startTable(),o.addFieldI16(0,0),o.addFieldOffset(1,s);let a=o.endTable();o.startTable(),o.addFieldI16(0,_n),o.addFieldI8(1,Un),o.addFieldOffset(2,a);let l=o.endTable();return o.finish(l)}function hi(e){return Wn(e,Ue,-1)}function gi(e,t){return Wn(e,_e,t)}function Wn(e,t,n){let r=new _t(512),o=new Uint8Array(e.nodes.length*xt),i=new DataView(o.buffer);for(let p=0;p<e.nodes.length;p++)i.setInt32(p*16+0,e.nodes[p].length,true),i.setInt32(p*16+8,e.nodes[p].nullCount,true);let s=r.createStructVector(o,e.nodes.length),a=new Uint8Array(e.buffers.length*xt),l=new DataView(a.buffer);for(let p=0;p<e.buffers.length;p++)l.setInt32(p*16+0,e.buffers[p].offset,true),l.setInt32(p*16+8,e.buffers[p].length,true);let u=r.createStructVector(a,e.buffers.length),c=e.nodes.length>0?e.nodes[0].length:0;r.startTable(),r.addFieldI64(0,c),r.addFieldOffset(1,s),r.addFieldOffset(2,u);let f=r.endTable(),m=f;t===_e&&(r.startTable(),r.addFieldI64(0,n),r.addFieldOffset(1,f),m=r.endTable()),r.startTable(),r.addFieldI16(0,_n),r.addFieldI8(1,t),r.addFieldOffset(2,m),r.addFieldI64(3,e.body.byteLength);let d=r.endTable();return r.finish(d)}function at(e,t){if(!t||t.byteLength===0)return {offset:0,length:0};let n=e.size;e.parts.push(t);let r=oe(t.byteLength);return r>t.byteLength&&e.parts.push(new Uint8Array(r-t.byteLength)),e.size+=r,{offset:n,length:t.byteLength}}function Mn(e){let t=e.reduce((o,i)=>o+i.byteLength,0),n=new Uint8Array(t),r=0;for(let o of e)n.set(o,r),r+=o.byteLength;return n}function Be(e,t){let n=e.byteLength,r=oe(n),o=8+r+t.byteLength,i=new Uint8Array(o),s=new DataView(i.buffer);return s.setInt32(0,-1,true),s.setInt32(4,r,true),i.set(e,8),i.set(t,8+r),i}function bi(e){let t=e.ctx,n=e.columns,r=e.length,o=n.map(w=>e.dtypeOf(w)),i=n.map(w=>e.getColumn(w)),s=o.map(()=>null),a=0;for(let w=0;w<o.length;w++)o[w]==="utf8"&&(s[w]=a++);let l=i.map(w=>w.dtype==="timestamp"?w.tz:void 0),u=[];u.push(Be(yi(n,o,s,l),new Uint8Array(0)));for(let w=0;w<i.length;w++){if(o[w]!=="utf8")continue;let A=i[w].dict,O=A.count,D=s[w],I=t.viewOf({ptr:A.offsetsPtr,length:O+1,dtype:"i32"}),z=A.bytesLen>0?t.viewOf({ptr:A.bytesPtr,length:A.bytesLen,dtype:"u8"}):new Uint8Array(0),lt={parts:[],size:0},ie=at(lt,null),se=at(lt,new Uint8Array(I.buffer,I.byteOffset,I.byteLength).slice()),Ut=at(lt,z.slice()),ut=Mn(lt.parts),qn={nodes:[{length:O,nullCount:0}],buffers:[ie,se,Ut],body:ut};u.push(Be(gi(qn,D),ut));}let c={parts:[],size:0},f=[],m=[];for(let w=0;w<i.length;w++){let x=i[w],A=o[w],O=0;if(x.validityPtr!==0){let D=x.validityBitOffset+r,I=t.viewOf({ptr:x.validityPtr,length:v(D),dtype:"u8"});for(let z=0;z<r;z++)T(I,x.validityBitOffset+z)||O++;}if(f.push({length:r,nullCount:O}),m.push(at(c,ci(t,x))),A==="utf8"){let D=t.viewOf({ptr:x.dataPtr,length:r,dtype:"i32"});m.push(at(c,new Uint8Array(D.buffer,D.byteOffset,D.byteLength).slice()));}else if(A==="bool"){let D=t.viewOf({ptr:x.dataPtr,length:r,dtype:"bool"});m.push(at(c,li(D,r)));}else {let D=C[A],I=t.viewOf({ptr:x.dataPtr,length:r,dtype:D.view});m.push(at(c,new Uint8Array(I.buffer,I.byteOffset,r*D.size).slice()));}}let d=Mn(c.parts),p={nodes:f,buffers:m,body:d};u.push(Be(hi(p),d));let h=new Uint8Array(8);new DataView(h.buffer).setInt32(0,-1,true),u.push(h);let y=u.reduce((w,x)=>w+x.byteLength,0),g=new Uint8Array(y),b=0;for(let w of u)g.set(w,b),b+=w.byteLength;return g}var Me=class{constructor(t){this.buf=t;this.dv=new DataView(t.buffer,t.byteOffset,t.byteLength);}buf;pos=0;dv;next(){if(this.pos+8>this.buf.byteLength)return null;if(this.dv.getUint32(this.pos,true)!==4294967295)throw new Error(`Arrow: expected continuation (0xFFFFFFFF) at offset ${this.pos}`);let n=this.dv.getInt32(this.pos+4,true);if(this.pos+=8,n===0)return null;let r=this.buf.slice(this.pos,this.pos+n);this.pos+=oe(n);let i=wt(r).getInt64Num(3),s=i>0?this.buf.slice(this.pos,this.pos+i):new Uint8Array(0);return this.pos+=oe(i),{meta:r,body:s}}};function wi(e){let t=wt(e);if(t.getUint8(1,0)!==Un)throw new Error("Arrow: first message is not Schema");let n=t.getTable(2);if(!n)throw new Error("Arrow: missing schema table");let r=n.vectorLen(1),o=[];for(let i=0;i<r;i++){let s=n.vectorTable(1,i),a=s.getString(0)??`f${i}`,l=s.getUint8(2,0),u=s.getTable(3),c=s.getTable(4),f=c?c.getInt64Num(0):null,m,d=false,p,h;switch(l){case ee:{let y=u?.getInt32(0,32)??32,g=u?.getBool(1,false)??false;if(y===64){if(!g)throw new Error("Arrow fromArrow: unsupported Arrow type UInt64. databonk supports Int64(signed) as 'i64'.");m="i64";}else m=y<=32&&!g?"u32":"i32";break}case Se:{m=(u?.getInt16(0,0)??0)===jn?"f64":"f32";break}case Nn:m="bool";break;case Vn:case ni:m="utf8",d=f===null;break;case $n:{let y=u?.getInt16(0,Fe)??Fe;if(y!==zn)throw new Error(`Arrow fromArrow: unsupported Date unit ${y} (only Date32(DAY)=0 is supported).`);m="date32";break}case Ln:{let y=u?.getInt16(0,re)??re,g=u?.getString(1)??void 0;m="timestamp",h=y,p=g;break}default:throw new Error(`Arrow fromArrow: unsupported Arrow type tag ${l}. Supported: Int32, Int64, UInt32, Float32, Float64, Bool, Utf8/Dict<Int32,Utf8>, Date32(DAY), Timestamp(any unit, optional tz).`)}o.push({name:a,dtype:m,dictId:f,plainUtf8:d,...p!==void 0?{tz:p}:{},...h!==void 0?{arrowUnit:h}:{}});}return o}function xi(e,t,n){let r=2166136261;for(let o=t;o<n;o++)r^=e[o],r=Math.imul(r,16777619)>>>0;return r}function vi(e,t,n,r,o){let i=n-t;for(let s=0;s<i;s++)if(e[t+s]!==r[o+s])return false;return true}function Ai(e){let t=1;for(;t<e;)t<<=1;return t}function Di(e,t,n){let r=new Int32Array(n);if(n===0)return {dictOffsets:new Int32Array([0]),dictBytes:new Uint8Array(0),dictCount:0,indices:r};let o=Ai(n*2),i=o-1,s=new Int32Array(o).fill(-1),a=new Uint32Array(o),l=0,u=Math.min(n,256),c=new Float64Array(u),f=new Float64Array(u);for(let y=0;y<n;y++){let g=t[y],b=t[y+1],w=xi(e,g,b),x=b-g,A=w>>>0&i,O=-1;for(;;){let D=s[A];if(D<0)break;if(a[A]===w>>>0){let I=c[D];if(f[D]-I===x&&vi(e,g,b,e,I)){O=D;break}}A=A+1&i;}if(O>=0)r[y]=O;else {let D=l++;if(D>=u){u<<=1;let I=new Float64Array(u);I.set(c),c=I;let z=new Float64Array(u);z.set(f),f=z;}c[D]=g,f[D]=b,s[A]=D,a[A]=w>>>0,r[y]=D;}}if(l===n)return {dictOffsets:t,dictBytes:e,dictCount:l,indices:r};let m=new Int32Array(l+1),d=0;for(let y=0;y<l;y++)m[y]=d,d+=f[y]-c[y];m[l]=d;let p=new Uint8Array(d),h=0;for(let y=0;y<l;y++){let g=c[y],b=f[y];p.set(e.subarray(g,b),h),h+=b-g;}return {dictOffsets:m,dictBytes:p,dictCount:l,indices:r}}function Ci(e,t){let r=wt(e).getTable(2);if(!r)throw new Error("Arrow: DictionaryBatch missing");let o=r.getInt64Num(0),i=r.getTable(1);if(!i)throw new Error("Arrow: DictionaryBatch missing inner RecordBatch");let s=i.getInt64Num(0),a=y=>i.i32at(i.structVectorElemPos(2,y,xt)),l=y=>i.i32at(i.structVectorElemPos(2,y,xt)+8),u=i.vectorLen(2);if(u<2)throw new Error("Arrow: DictionaryBatch RecordBatch needs \u22652 buffers");let c=a(1);l(1);let m=u>=3?a(2):0,d=u>=3?l(2):0,p=new Int32Array(t.buffer,t.byteOffset+c,s+1).slice(),h=d>0?t.slice(m,m+d):new Uint8Array(0);return {id:o,entry:{offsets:p,bytes:h,count:s}}}function Oi(e,t,n,r,o){let i=wt(e);if(i.getUint8(1,0)!==Ue)throw new Error("Arrow: expected RecordBatch");let s=i.getTable(2);if(!s)throw new Error("Arrow: missing RecordBatch table");let a=s.getInt64Num(0),l=s.vectorLen(1);if(l!==n.length)throw new Error(`Arrow: field count mismatch (schema=${n.length}, batch=${l})`);let u=d=>s.i32at(s.structVectorElemPos(2,d,xt)),c=d=>s.i32at(s.structVectorElemPos(2,d,xt)+8),f=[],m=0;for(let d=0;d<n.length;d++){let{dtype:p,dictId:h}=n[d],y=u(m),g=c(m);m++;let b=g>0;if(p==="utf8")if(h!==null){let w=u(m);m++;let x=r.get(h);if(!x)throw new Error(`Arrow: missing dictionary id=${h}`);let A=Nt(o,x.bytes,x.offsets,x.count),O=o.mod.alloc(Math.max(a*4,1));o.viewOf({ptr:O,length:a,dtype:"i32"}).set(new Int32Array(t.buffer,t.byteOffset+w,a));let I=0;b&&(I=o.mod.alloc(v(a)),o.viewOf({ptr:I,length:v(a),dtype:"u8"}).set(t.subarray(y,y+v(a)))),f.push({dtype:"utf8",length:a,dataPtr:O,validityPtr:I,validityBitOffset:0,dict:A,owned:true});}else {let w=u(m);m++;let x=u(m),A=c(m);m++;let O=new Int32Array(t.buffer,t.byteOffset+w,a+1),D=t.subarray(x,x+A),{dictOffsets:I,dictBytes:z,dictCount:lt,indices:ie}=Di(D,O,a),se=Nt(o,z,I,lt),Ut=o.mod.alloc(Math.max(a*4,1));o.viewOf({ptr:Ut,length:a,dtype:"i32"}).set(ie);let ut=0;b&&(ut=o.mod.alloc(v(a)),o.viewOf({ptr:ut,length:v(a),dtype:"u8"}).set(t.subarray(y,y+v(a)))),f.push({dtype:"utf8",length:a,dataPtr:Ut,validityPtr:ut,validityBitOffset:0,dict:se,owned:true});}else if(p==="bool"){let w=u(m),x=c(m);m++;let A=t.subarray(w,w+x),O=ui(A,a),D=o.mod.alloc(Math.max(a,1));o.viewOf({ptr:D,length:a,dtype:"bool"}).set(O);let I=0;b&&(I=o.mod.alloc(v(a)),o.viewOf({ptr:I,length:v(a),dtype:"u8"}).set(t.subarray(y,y+v(a)))),f.push({dtype:"bool",length:a,dataPtr:D,validityPtr:I,validityBitOffset:0,dict:null,owned:true});}else {let w=C[p],x=u(m);m++;let A=o.mod.alloc(Math.max(a*w.size,1)),O=o.viewOf({ptr:A,length:a,dtype:w.view}),D=new w.ctor(t.buffer,t.byteOffset+x,a);O.set(D);let I=0;b&&(I=o.mod.alloc(v(a)),o.viewOf({ptr:I,length:v(a),dtype:"u8"}).set(t.subarray(y,y+v(a)))),f.push({dtype:p,length:a,dataPtr:A,validityPtr:I,validityBitOffset:0,dict:null,owned:true});}}return {columns:f,length:a}}function Ii(e,t){return t===Ve?e:e.map(n=>{if(n===null)return null;switch(t){case re:return n>si||n<ai?null:n*1000n;case oi:return n/1000n;case ii:return n/1000000n;default:return null}})}function Ti(e,t){let n=new Me(e),r=n.next();if(!r)throw new Error("Arrow fromArrow: empty or truncated buffer");let o=wi(r.meta),i=new Map,s=null;for(;;){let c=n.next();if(!c)break;let m=wt(c.meta).getUint8(1,0);if(m===_e){let{id:d,entry:p}=Ci(c.meta,c.body);i.set(d,p);}else if(m===Ue){s=c;break}}if(!s)throw new Error("Arrow fromArrow: no RecordBatch found in stream");let{columns:a,length:l}=Oi(s.meta,s.body,o,i,t.ctx),u=[];for(let c=0;c<o.length;c++){let{name:f,dtype:m,tz:d,arrowUnit:p}=o[c],h=a[c];if(m==="timestamp"&&p!==void 0&&p!==Ve){let y=K(t.ctx,h),g=Ii(y,p);Y(t.ctx,h),h=P(t.ctx,"timestamp",g,d);}else m==="timestamp"&&d!==void 0&&(h={...h,tz:d});u.push({name:f,col:h});}return j._adoptColumns(t,u,l)}var Pi="0.2.0";function sl(e="world"){return `Hello, ${e}! dataframe v${Pi}`}export{te as ChunkParser,C as DTYPES,j as DataFrame,Lt as DtProxy,_ as Expr,U as ExprError,E as FrameError,Mt as GroupBy,st as Series,Qt as SeriesStrProxy,jt as StrProxy,Pi as VERSION,Tt as aggResult,nt as badLiteral,he as callKernel,Qn as clearBit,cr as col,K as columnToArray,Et as compile,ve as compileFilter,P as createColumn,le as createMemoryContext,ae as createViewOf,W as decodeDictionary,q as decodeSlot,nr as decodeStats,Zt as defaultRuntime,Vt as detectSimd,Zn as dtypeInfo,rt as dtypeMismatch,Y as freeColumn,ce as freeDictionary,Ti as fromArrow,Xo as fromCSV,ti as fromJSON,T as getBit,sl as hello,ye as inferType,fo as init,$e as lit,sn as loadRuntime,Jn as loadWasmModule,zt as nearest,It as resolve,on as runtimeFromExports,dr as schemaOf,_o as scope,S as setBit,$t as sliceColumn,bi as toArrow,At as toExpr,ei as toJSON,rr as unifyDictionaries,de as unknownColumn,me as unsupportedCast,R as unsupportedDtype,mo as useRuntime,v as validityBytes,ct as writeDictionary,Nt as writeDictionaryFromRawBytes};//# sourceMappingURL=index.js.map
41
5
  //# sourceMappingURL=index.js.map