databonk 0.0.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +511 -111
- package/dist/dataframe-BggBYXYm.d.cts +886 -0
- package/dist/dataframe-BggBYXYm.d.ts +886 -0
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +366 -0
- package/dist/index.d.ts +366 -23
- package/dist/index.js +5 -6734
- package/dist/index.js.map +1 -1
- package/dist/parallel-fv5h4BkA.d.cts +152 -0
- package/dist/parallel-fv5h4BkA.d.ts +152 -0
- package/dist/parquet.cjs +3 -0
- package/dist/parquet.cjs.map +1 -0
- package/dist/parquet.d.cts +57 -0
- package/dist/parquet.d.ts +57 -0
- package/dist/parquet.js +3 -0
- package/dist/parquet.js.map +1 -0
- package/dist/scalar.wasm +0 -0
- package/dist/simd-threads.wasm +0 -0
- package/dist/simd.wasm +0 -0
- package/dist/workers.cjs +102 -0
- package/dist/workers.cjs.map +1 -0
- package/dist/workers.d.cts +74 -0
- package/dist/workers.d.ts +74 -0
- package/dist/workers.js +102 -0
- package/dist/workers.js.map +1 -0
- package/package.json +95 -60
- package/dist/core/column.d.ts +0 -55
- package/dist/core/column.d.ts.map +0 -1
- package/dist/core/dataframe.d.ts +0 -148
- package/dist/core/dataframe.d.ts.map +0 -1
- package/dist/core/index-cache.d.ts +0 -44
- package/dist/core/index-cache.d.ts.map +0 -1
- package/dist/core/index-manager.d.ts +0 -97
- package/dist/core/index-manager.d.ts.map +0 -1
- package/dist/core/index.d.ts +0 -75
- package/dist/core/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -6716
- package/dist/index.esm.js.map +0 -1
- package/dist/io/csv.d.ts +0 -23
- package/dist/io/csv.d.ts.map +0 -1
- package/dist/operations/aggregation.d.ts +0 -23
- package/dist/operations/aggregation.d.ts.map +0 -1
- package/dist/operations/derive.d.ts +0 -38
- package/dist/operations/derive.d.ts.map +0 -1
- package/dist/operations/groupby.d.ts +0 -36
- package/dist/operations/groupby.d.ts.map +0 -1
- package/dist/operations/join.d.ts +0 -58
- package/dist/operations/join.d.ts.map +0 -1
- package/dist/operations/reshape.d.ts +0 -17
- package/dist/operations/reshape.d.ts.map +0 -1
- package/dist/utils/aggregation-engine.d.ts +0 -84
- package/dist/utils/aggregation-engine.d.ts.map +0 -1
- package/dist/utils/bitset.d.ts +0 -30
- package/dist/utils/bitset.d.ts.map +0 -1
- package/dist/utils/hash.d.ts +0 -79
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/performance.d.ts +0 -44
- package/dist/utils/performance.d.ts.map +0 -1
- package/dist/utils/types.d.ts +0 -7
- package/dist/utils/types.d.ts.map +0 -1
- package/dist/validation/schema.d.ts +0 -73
- package/dist/validation/schema.d.ts.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use strict';var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;var qn=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 zt(){try{return WebAssembly.validate(qn)}catch{return false}}var Hn=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;async function Yn(e,t){if(Hn){let[{readFile:i},{fileURLToPath:a}]=await Promise.all([import('fs/promises'),import('url')]),s;if(t===void 0)s=a(new URL(e,(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));else if(t instanceof URL)s=a(new URL(e,t));else if(t.startsWith("file:"))s=a(new URL(e,t));else {let{join:l}=await import('path');s=l(t,e);}return await i(s)}let n=t??new URL(".",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),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 Kn(e={}){let t=e.simd??zt(),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 Jn(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 Le(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=Jn(l.dtype);return new u(e.memory.buffer,l.ptr,l.length)}function a(){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 s=(l=>{let u=Le(l);r.has(u)||r.set(u,l),a();let c=o.get(u);return c===void 0&&(c=i(l),o.set(u,c)),c});return s.generation=()=>t,s.forget=l=>{let u=Le(l);r.delete(u),o.delete(u);},s.clear=()=>{r.clear(),o.clear(),t=-1,n=null;},s}function le(e){return {mod:e,viewOf:ae(e)}}var D={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 Gn(e){let t=D[e];if(t===void 0)throw new Error(`unknown dtype: ${String(e)}`);return t}function A(e){return e+7>>3}function T(e,t){return (e[t>>3]&1<<(t&7))!==0}function R(e,t){let n=t>>3;e[n]=(e[n]??0)|1<<(t&7);}function Zn(e,t){let n=t>>3;e[n]=(e[n]??0)&~(1<<(t&7));}var Qn=new TextEncoder,Xn=new TextDecoder,ue=new WeakMap;function tr(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 st(e,t){let n=t.length,r=t.map(c=>Qn.encode(c)),o=0;for(let c of r)o+=c.length;let i=e.mod.alloc((n+1)*4),a=e.mod.alloc(o),s=e.viewOf({ptr:i,length:n+1,dtype:"i32"}),l=e.viewOf({ptr:a,length:o,dtype:"u8"});s[0]=0;let u=0;for(let c=0;c<n;c++){let f=r[c];l.set(f,u),u+=f.length,s[c+1]=u;}return {count:n,offsetsPtr:i,bytesPtr:a,bytesLen:o}}function W(e,t,n){let r=tr(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"}),a=i[n],s=i[n+1],l;if(s<=a)l="";else {let u=e.viewOf({ptr:t.bytesPtr,length:t.bytesLen,dtype:"u8"});l=Xn.decode(u.subarray(a,s));}return r.slots[n]=l,l}function it(e,t){let n=new Array(t.count);for(let r=0;r<t.count;r++)n[r]=W(e,t,r);return n}function er(e){let t=ue.get(e);return t===void 0?{hits:0,misses:0}:{...t.stats}}function ce(e,t,n){let r=it(e,t),o=it(e,n),i=[],a=new Map,s=c=>{let f=a.get(c);return f===void 0&&(f=i.length,i.push(c),a.set(c,f)),f},l=new Int32Array(r.length),u=new Int32Array(o.length);for(let c=0;c<r.length;c++)l[c]=s(r[c]);for(let c=0;c<o.length;c++)u[c]=s(o[c]);return {merged:i,remapA:l,remapB:u}}function fe(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 X(e){return e==null}function tt(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 I(e,t,n,r){return t==="utf8"?ar(e,n):t==="bool"?or(e,n):t==="i64"?ir(e,n):t==="timestamp"||t==="date32"?sr(e,t,n,r):rr(e,t,n)}function nr(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 rr(e,t,n){let r=D[t],o=n.length;if(nr(t,n)){let c=e.mod.alloc(o*r.size);return e.viewOf({ptr:c,length:o,dtype:r.view}).set(n),tt(t,o,c,0,null)}let i=0;for(let c=0;c<o;c++)X(n[c])&&i++;let a=e.mod.alloc(o*r.size),s=i>0?e.mod.alloc(A(o)):0,l=e.viewOf({ptr:a,length:o,dtype:r.view}),u=null;s!==0&&(u=e.viewOf({ptr:s,length:A(o),dtype:"u8"}),u.fill(0));for(let c=0;c<o;c++){let f=n[c];X(f)?l[c]=0:(l[c]=f,u&&R(u,c));}return tt(t,o,a,s,null)}function or(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),tt("bool",n,l,0,null)}let r=0;for(let l=0;l<n;l++)X(t[l])&&r++;let o=e.mod.alloc(n),i=r>0?e.mod.alloc(A(n)):0,a=e.viewOf({ptr:o,length:n,dtype:"bool"}),s=null;i!==0&&(s=e.viewOf({ptr:i,length:A(n),dtype:"u8"}),s.fill(0));for(let l=0;l<n;l++){let u=t[l];X(u)?a[l]=0:(a[l]=u?1:0,s&&R(s,l));}return tt("bool",n,o,i,null)}function ir(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),tt("i64",n,l,0,null)}let r=0;for(let l=0;l<n;l++){let u=t[l];if(X(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(A(n)):0,a=e.viewOf({ptr:o,length:n,dtype:"i64"}),s=null;i!==0&&(s=e.viewOf({ptr:i,length:A(n),dtype:"u8"}),s.fill(0));for(let l=0;l<n;l++){let u=t[l];X(u)?a[l]=0n:(a[l]=typeof u=="bigint"?u:BigInt(u),s&&R(s,l));}return tt("i64",n,o,i,null)}function sr(e,t,n,r){let o=t==="timestamp",i=o?8:4,a=n.length,s=o?"i64":"i32";if(o?n instanceof BigInt64Array:n instanceof Int32Array){let d=e.mod.alloc(Math.max(a*i,1));return e.viewOf({ptr:d,length:a,dtype:s}).set(n),tt(t,a,d,0,null,r)}let l=0;for(let d=0;d<a;d++)X(n[d])&&l++;let u=e.mod.alloc(Math.max(a*i,1)),c=l>0?e.mod.alloc(A(a)):0,f=e.viewOf({ptr:u,length:a,dtype:s}),m=null;c&&(m=e.viewOf({ptr:c,length:A(a),dtype:"u8"}),m.fill(0));for(let d=0;d<a;d++){let p=n[d];X(p)?f[d]=o?0n:0:(f[d]=o?typeof p=="bigint"?p:BigInt(p):p,m&&R(m,d));}return tt(t,a,u,c,null,r)}function ar(e,t){let n=t.length,r=new Map,o=[],i=new Int32Array(n),a=new Uint8Array(n),s=0;for(let m=0;m<n;m++){let d=t[m];if(X(d))s++,a[m]=1,i[m]=0;else {let p=d,y=r.get(p);y===void 0&&(y=o.length,o.push(p),r.set(p,y)),i[m]=y;}}let l=e.mod.alloc(n*4),u=s>0?e.mod.alloc(A(n)):0,c=st(e,o);if(e.viewOf({ptr:l,length:n,dtype:"i32"}).set(i),u!==0){let m=e.viewOf({ptr:u,length:A(n),dtype:"u8"});m.fill(0);for(let d=0;d<n;d++)a[d]===0&&R(m,d);}return tt("utf8",n,l,u,c)}function q(e,t){let{length:n,validityPtr:r,validityBitOffset:o}=t,i=r===0?null:e.viewOf({ptr:r,length:A(o+n),dtype:"u8"}),a=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++)a[m]=i&&!T(i,o+m)?null:W(e,f,c[m]);return a}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++)a[f]=i&&!T(i,o+f)?null:c[f];return a}if(t.dtype==="date32"){let c=e.viewOf({ptr:t.dataPtr,length:n,dtype:"i32"});for(let f=0;f<n;f++)a[f]=i&&!T(i,o+f)?null:c[f];return a}let s=D[t.dtype],l=e.viewOf({ptr:t.dataPtr,length:n,dtype:s.view}),u=t.dtype==="bool";for(let c=0;c<n;c++)i&&!T(i,o+c)?a[c]=null:a[c]=u?l[c]!==0:l[c];return a}function Wt(e,t,n){let r=Math.max(0,Math.min(t,e.length)),i=Math.max(r,Math.min(n,e.length))-r,a=D[e.dtype].size;return {dtype:e.dtype,length:i,dataPtr:e.dataPtr+r*a,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=D[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:A(t.validityBitOffset+t.length),dtype:"u8"}),e.mod.free(t.validityPtr)),t.dict!==null&&fe(e,t.dict);}function Tt(e){return e instanceof _?e:je(e)}var _=class e{node;constructor(t){this.node=Object.freeze(t),Object.freeze(this);}add(t){return Ot("add",this,t)}sub(t){return Ot("sub",this,t)}mul(t){return Ot("mul",this,t)}div(t){return Ot("div",this,t)}mod(t){return Ot("mod",this,t)}neg(){return new e({kind:"neg",operand:this})}gt(t){return dt("gt",this,t)}ge(t){return dt("ge",this,t)}lt(t){return dt("lt",this,t)}le(t){return dt("le",this,t)}eq(t){return dt("eq",this,t)}ne(t){return dt("ne",this,t)}and(t){return new e({kind:"bool",op:"and",left:this,right:Tt(t)})}or(t){return new e({kind:"bool",op:"or",left:this,right:Tt(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 K("sum",this)}mean(){return K("mean",this)}min(){return K("min",this)}max(){return K("max",this)}count(){return K("count",this)}nunique(){return K("nunique",this)}std(){return K("std",this)}var(){return K("var",this)}first(){return K("first",this)}last(){return K("last",this)}get dt(){return new de(this)}toString(){return M(this.node)}},de=class{constructor(t){this.operand=t;}operand;year(){return J("year",this.operand)}month(){return J("month",this.operand)}day(){return J("day",this.operand)}hour(){return J("hour",this.operand)}minute(){return J("minute",this.operand)}second(){return J("second",this.operand)}millisecond(){return J("millisecond",this.operand)}weekday(){return J("weekday",this.operand)}dayOfYear(){return J("dayOfYear",this.operand)}quarter(){return J("quarter",this.operand)}};function lr(e){return new _({kind:"col",name:e})}function je(e,t){return new _({kind:"lit",value:e,dtype:t??null})}function Ot(e,t,n){return new _({kind:"arith",op:e,left:t,right:Tt(n)})}function dt(e,t,n){return new _({kind:"compare",op:e,left:t,right:Tt(n)})}function K(e,t){return new _({kind:"agg",op:e,operand:t})}function J(e,t){return new _({kind:"dt",component:e,operand:t})}var ur={add:"+",sub:"-",mul:"*",div:"/",mod:"%"};function me(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(${me(e.value)}, ${e.dtype})`:`lit(${me(e.value)})`;case "arith":return `(${M(e.left.node)} ${ur[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(${me(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}()`}}var V=class extends Error{constructor(t){super(t),this.name="ExprError";}};function lt(e,t,n,r){let o=r?` ${r}`:"";return new V(`dtype mismatch in '${e}': cannot combine ${t} and ${n}.${o}`)}function B(e,t,n){let r=n?` ${n}`:"";return new V(`operation '${e}' is not supported for dtype ${t}.${r}`)}function pe(e,t){return new V(`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 ye(e,t){let n=qt(e,t),r=n?` Did you mean '${n}'?`:"",o=t.length?` Known columns: ${t.map(i=>`'${i}'`).join(", ")}.`:"";return new V(`unknown column '${e}'.${r}${o}`)}function at(e,t,n){return new V(`literal ${JSON.stringify(e)} is not a valid ${t} value for '${n}'.`)}function qt(e,t){let n=null,r=1/0;for(let i of t){let a=cr(e,i);a<r&&(r=a,n=i);}let o=Math.max(2,Math.ceil(e.length/3));return n!==null&&r<=o?n:null}function cr(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 a=0;a<=r;a++)o[a]=a;for(let a=1;a<=n;a++){i[0]=a;let s=e.charCodeAt(a-1);for(let l=1;l<=r;l++){let u=s===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 fr(e){let t=Object.keys(e);return {dtypeOf:n=>e[n],columnNames:()=>t}}var mr=new Set(["f64","f32","i32","u32","i64"]),ze=new Set(["i32","u32","i64"]),Pt=new Set(["f64","f32"]),pt=new Set(["date32","timestamp"]);function et(e){return mr.has(e)}function he(e,t){return Number.isInteger(e)?t==="i32"?e>=-2147483648&&e<=2147483647:e>=0&&e<=4294967295:false}function Yt(e){let t=e.node;return t.kind==="lit"&&t.dtype===null&&typeof t.value=="number"?t.value:null}function U(e,t){return {kind:"lit",value:e,dtype:t}}function Ht(e,t){return e.dtype===t?e:{kind:"cast",dtype:t,from:e.dtype,operand:e}}function Et(e,t){return S(e,t)}function ge(e,t){return Et(e,t).dtype}function S(e,t){let n=e.node;switch(n.kind){case "col":{let r=t.dtypeOf(n.name);if(r===void 0)throw ye(n.name,t.columnNames());return {kind:"col",name:n.name,dtype:r}}case "lit":return n.dtype!==null?U(n.value,n.dtype):typeof n.value=="bigint"?U(n.value,"i64"):typeof n.value=="number"?U(n.value,Number.isInteger(n.value)?"i32":"f64"):U(n.value,typeof n.value=="string"?"utf8":"bool");case "arith":return dr(n.op,n.left,n.right,t);case "neg":return gr(n.operand,t);case "compare":return wr(n.op,n.left,n.right,t);case "bool":return vr(n.op,n.left,n.right,t);case "not":return Ar(n.operand,t);case "isNull":return {kind:"isNull",dtype:"bool",operand:S(n.operand,t)};case "fillNull":return Dr(n.operand,n.value,t);case "cast":return Tr(n.operand,n.to,t);case "agg":return Ir(n.op,n.operand,t);case "dt":return br(n.component,n.operand,t)}}function dr(e,t,n,r){let o=Yt(t),i=Yt(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:U(o,f),right:U(i,f)}}if(o!==null||i!==null){let u=o??i,c=S(o!==null?n:t,r),{opDtype:f,colTarget:m}=pr(e,u,c.dtype),d=Ht(c,m),p=U(u,f);return {kind:"arith",op:e,dtype:f,left:o!==null?p:d,right:o!==null?d:p}}let a=S(t,r),s=S(n,r),l=yr(e,a.dtype,s.dtype);return {kind:"arith",op:e,dtype:l,left:Ht(a,l),right:Ht(s,l)}}function pr(e,t,n){if(n==="timestamp")return {opDtype:"timestamp",colTarget:"timestamp"};if(n==="date32")return {opDtype:"date32",colTarget:"date32"};if(!et(n))throw B(e,n,"arithmetic");return Pt.has(n)?{opDtype:n,colTarget:n}:n==="i64"?Number.isSafeInteger(t)?{opDtype:"i64",colTarget:"i64"}:{opDtype:"f64",colTarget:"f64"}:he(t,n)?{opDtype:n,colTarget:n}:{opDtype:"f64",colTarget:"f64"}}function yr(e,t,n){if(pt.has(t)||pt.has(n))return hr(e,t,n);if(!et(t))throw B(e,t,"arithmetic");if(!et(n))throw B(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"&&Pt.has(n)||n==="i64"&&Pt.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 lt(e,t,n,"insert an explicit .cast() (only int\u2192float widening is implicit).")}function hr(e,t,n){if(e==="sub"&&t==="timestamp"&&n==="timestamp")return "i64";if((e==="add"||e==="sub")&&t==="timestamp"&&ze.has(n)||e==="add"&&ze.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 V(`${e}(${t},${n})`)}function gr(e,t){let n=S(e,t);if(!et(n.dtype))throw B("neg",n.dtype);return {kind:"neg",dtype:n.dtype,operand:n}}function br(e,t,n){let r=S(t,n);if(!pt.has(r.dtype))throw B("dt",r.dtype);return {kind:"dt",component:e,dtype:"i32",operand:r}}function wr(e,t,n,r){let o=e==="eq"||e==="ne",i=It(t)??It(n),a=kt(t)??kt(n),s=Yt(t),l=Yt(n);if(s!==null&&l!==null){let m=Number.isInteger(s)&&Number.isInteger(l)?"i32":"f64";return ut(e,m,U(s,m),U(l,m))}if(s!==null||l!==null){let m=s??l,d=S(s!==null?n:t,r);if(d.dtype==="date32"){let h=U(m,"date32");return ut(e,"date32",s!==null?h:d,s!==null?d:h)}if(d.dtype==="timestamp"){let h=U(m,"timestamp");return ut(e,"timestamp",s!==null?h:d,s!==null?d:h)}if(!et(d.dtype))throw lt(e,s!==null?"f64":d.dtype,s!==null?d.dtype:"f64","cannot compare a number to a non-numeric column.");let p=xr(m,d.dtype),y=Ht(d,p),g=U(m,p);return ut(e,p,s!==null?g:y,s!==null?y:g)}if(i!==null){let m=S(It(t)!==null?n:t,r);if(m.dtype!=="utf8")throw lt(e,"utf8",m.dtype,"cannot compare a string to a non-utf8 column.");if(!o)throw B(e,"utf8","string ordering");let d=U(i,"utf8");return ut(e,"utf8",It(t)!==null?d:m,It(t)!==null?m:d)}if(a!==null){let m=S(kt(t)!==null?n:t,r);if(m.dtype!=="bool")throw lt(e,"bool",m.dtype,"cannot compare a boolean to a non-bool column.");if(!o)throw B(e,"bool");let d=U(a,"bool");return ut(e,"bool",kt(t)!==null?d:m,kt(t)!==null?m:d)}let u=S(t,r),c=S(n,r);if(u.dtype!==c.dtype)throw lt(e,u.dtype,c.dtype,"cast");let f=u.dtype;if(f==="utf8"||f==="bool")throw B(e,f,"column-vs-column");return ut(e,f,u,c)}function ut(e,t,n,r){return {kind:"compare",op:e,dtype:"bool",operandDtype:t,left:n,right:r}}function xr(e,t){return Pt.has(t)?t:t==="i64"?Number.isSafeInteger(e)?"i64":"f64":he(e,t)?t:"f64"}function It(e){let t=e.node;return t.kind==="lit"&&typeof t.value=="string"?t.value:null}function kt(e){let t=e.node;return t.kind==="lit"&&typeof t.value=="boolean"?t.value:null}function vr(e,t,n,r){let o=S(t,r),i=S(n,r);if(o.dtype!=="bool")throw B(e,o.dtype,"boolean");if(i.dtype!=="bool")throw B(e,i.dtype,"boolean");return {kind:"bool",op:e,dtype:"bool",left:o,right:i}}function Ar(e,t){let n=S(e,t);if(n.dtype!=="bool")throw B("not",n.dtype,"boolean");return {kind:"not",dtype:"bool",operand:n}}function Dr(e,t,n){let r=S(e,n);return Cr(t,r.dtype),{kind:"fillNull",dtype:r.dtype,operand:r,value:t}}function Cr(e,t){if(t==="utf8"){if(typeof e!="string")throw at(e,t,"fillNull");return}if(t==="bool"){if(typeof e!="boolean")throw at(e,t,"fillNull");return}if(t==="i64"||t==="timestamp"){if(typeof e!="bigint"&&typeof e!="number")throw at(e,t,"fillNull");if(typeof e=="number"&&!Number.isSafeInteger(e))throw at(e,t,"fillNull");return}if(typeof e!="number")throw at(e,t,"fillNull");if((t==="i32"||t==="u32")&&!he(e,t))throw at(e,t,"fillNull")}var Or={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 Tr(e,t,n){let r=S(e,n),o=r.dtype;if(!Or[o]?.has(t))throw pe(o,t);return {kind:"cast",dtype:t,from:o,operand:r}}function Ir(e,t,n){let r=S(t,n),o=Rt(e,r.dtype);return {kind:"agg",op:e,dtype:o,operandDtype:r.dtype,operand:r}}function Rt(e,t){switch(e){case "count":return "i32";case "nunique":if(et(t)||t==="utf8"||pt.has(t))return "i32";throw B("nunique",t);case "sum":if(Pt.has(t))return t;if(t==="i64")return "i64";if(t==="i32"||t==="u32")return "f64";throw B("sum",t);case "mean":case "std":case "var":if(et(t))return "f64";throw B(e,t);case "min":case "max":if(et(t)||pt.has(t))return t;throw B(e,t);case "first":case "last":if(et(t)||t==="utf8"||pt.has(t))return t;throw B(e,t)}}function be(e,t,n){let r=e[t];if(typeof r!="function")throw new Error(`kernel export not found: ${t}`);return r(...n)}function We(e,t,n){let r=e[t];if(typeof r!="function")throw new Error(`kernel export not found: ${t}`);return r(...n)}function Kt(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 Bt=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 A(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),be(this.wasm,t,n)}callBigInt(t,...n){return this.trace.kernels.push(t),We(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 qe(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,A(n+e.len),"u8"),a=e.view(o,r,"u8");a.fill(0);for(let s=0;s<e.len;s++)T(i,n+s)&&R(a,s);return {ptr:o,owns:true}}function He(e,t,n){if(n===0)return 0;let r=e.view(t,A(n),"u8"),o=0;for(let i=0;i<n;i++)r[i>>3]>>(i&7)&1&&o++;return o}var we=86400000n,kr=[0,31,59,90,120,151,181,212,243,273,304,334];function Ye(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,a=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),s=Math.floor((5*a+2)/153),l=a-Math.floor((153*s+2)/5)+1,u=s<10?s+3:s-9;return {year:i+(u<=2?1:0),month:u,day:l}}function Jt(e,t,n){let r=e-(t<=2?1:0),o=Math.floor(r/400),i=r-o*400,a=Math.floor((153*(t>2?t-3:t+9)+2)/5)+n-1,s=i*365+Math.floor(i/4)-Math.floor(i/100)+a;return o*146097+s-719468}function Pr(e){return e%4===0&&e%100!==0||e%400===0}function Gt(e,t,n){let r=(kr[t-1]??0)+n;return t>2&&Pr(e)?r+1:r}function Zt(e){return ((e+3)%7+7)%7+1}function Er(e){let t=e/we;return e%we!==0n&&e<0n&&(t-=1n),Number(t)}function Ke(e){let{year:t,month:n,day:r}=Ye(e);return {year:t,month:n,day:r,hour:0,minute:0,second:0,millisecond:0,weekday:Zt(e),dayOfYear:Gt(t,n,r),quarter:Math.ceil(n/3)}}function Je(e){let t=typeof e=="bigint"?e:BigInt(Math.trunc(e)),n=Er(t),r=Number(t-BigInt(n)*we),{year:o,month:i,day:a}=Ye(n),s=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:a,hour:s,minute:u,second:f,millisecond:m,weekday:Zt(n),dayOfYear:Gt(o,i,a),quarter:Math.ceil(i/3)}}var Ge=new Map;function Rr(e){let t=Ge.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 Ge.set(e,n),n}function Ze(e,t){let r=Rr(t).formatToParts(e),o=0,i=0,a=0,s=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":a=parseInt(m.value,10);break;case "hour":s=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=Jt(o,i,a);return {year:o,month:i,day:a,hour:s,minute:l,second:u,millisecond:c,weekday:Zt(f),dayOfYear:Gt(o,i,a),quarter:Math.ceil(i/3)}}function Br(e,t){return ((e[t>>3]??0)&1<<(t&7))!==0}function yt(e,t,n,r){let o=e.length,i=new Int32Array(o),a=e instanceof Int32Array,s=typeof r=="string"&&r.length>0;for(let l=0;l<o;l++){if(t!==null&&!Br(t,l))continue;let u;if(a)u=Ke(e[l]??0);else if(s){let c=Number(e[l]??0n);u=Ze(c,r);}else {let c=e[l]??0n;u=Je(c);}i[l]=u[n];}return {data:i,validity:t}}function Mt(e,t){let n=Et(e,t),r=n.kind==="agg"?"scalar":"column";return {dtype:n.dtype,resultKind:r,execute(){let o=new Bt(t);try{if(n.kind==="agg")return {kind:"scalar",scalar:Ce(o,t,n),stats:Kt(o.trace)};let i=H(o,t,n);return {kind:"column",column:rn(o,i),stats:Kt(o.trace)}}finally{o.freeAll();}}}}function De(e,t){let n=Et(e,t);if(n.dtype!=="bool")throw new V(`filter predicate must be boolean, got ${n.dtype}. Use a comparison / boolean expression.`);return {execute(){let r=new Bt(t),o=Xr(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 s=r.alloc(r.validityBytes,"mask");r.call("validity_and",o.maskPtr,o.validity.ptr,s,r.len),F(r,o.validity),i=s;}let a=He(r,i,r.len);return Sr(r,t,i,a)}}}function Sr(e,t,n,r){let o=null,i=()=>{if(o)return o;let a=new Int32Array(r),s=e.view(n,A(e.len),"u8"),l=0;for(let u=0;u<e.len;u++)s[u>>3]>>(u&7)&1&&(a[l++]=u);return o=a,a};return {count:r,compact(a){let s=D[a.dtype],l=t.ctx.mod.alloc(Math.max(r*s.size,1)),u=e.call(`filter_${to(a.dtype)}`,a.dataPtr,n,l,e.len);if(u!==r)throw new Error(`filter count mismatch: kernel ${u}, expected ${r}`);let c=0;if(a.validityPtr!==0){let m=i(),d=e.view(a.validityPtr,A(a.validityBitOffset+e.len),"u8"),p=0,y=A(r),g=t.ctx.mod.alloc(Math.max(y,1)),h=e.view(g,y,"u8");h.fill(0);for(let x=0;x<r;x++)T(d,a.validityBitOffset+m[x])?R(h,x):p++;p===0?(t.ctx.viewOf.forget({ptr:g,length:y,dtype:"u8"}),t.ctx.mod.free(g)):c=g;}let f=a.dict?on(t.ctx,a.dict):null;return {dtype:a.dtype,length:r,dataPtr:l,validityPtr:c,validityBitOffset:0,dict:f,owned:true}},free(){e.freeAll();},get stats(){return Kt(e.trace)}}}var Fr={gt:"lt",lt:"gt",ge:"le",le:"ge",eq:"eq",ne:"ne"},Mr=new Set(["add","mul"]),_r=new Set(["f64_i32","f64_u32","f64_bool","f32_i32","f32_u32","f32_bool","i32_u32","u32_i32","f64_i64","f32_i64"]),xe=86400000n;function H(e,t,n){switch(n.kind){case "col":return Vr(e,t,n.name,n.dtype);case "lit":return Qt(e,n.value,n.dtype);case "arith":return Ur(e,t,n);case "neg":return $r(e,t,n.dtype,n.operand);case "compare":return Lr(e,t,n);case "bool":return Wr(e,t,n.op,n.left,n.right);case "not":return qr(e,t,n.operand);case "isNull":return Hr(e,t,n.operand);case "fillNull":return Yr(e,t,n.dtype,n.operand,n.value);case "cast":return Gr(e,t,n.from,n.dtype,n.operand);case "agg":{let r=Ce(e,t,n);return Qt(e,r.value,n.dtype)}case "dt":return Zr(e,t,n.component,n.operand)}}function Vr(e,t,n,r){let o=t.getColumn(n);if(!o)throw new V(`column '${n}' vanished during execution`);let i=qe(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 L(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 St(e){return e.kind==="lit"||e.kind==="agg"||e.kind==="cast"&&St(e.operand)}function Ur(e,t,n){let r=n.dtype,o=St(n.left),i=St(n.right);if(o&&i){let l=Qt(e,G(e,t,n.left),r);return ve(e,t,n.op,l,G(e,t,n.right),r)}if(i){let l=L(e,t,n.left);return ve(e,t,n.op,l,G(e,t,n.right),r)}if(o){let l=L(e,t,n.right);return Nr(e,t,n.op,G(e,t,n.left),l,r)}let a=L(e,t,n.left),s=L(e,t,n.right);return tn(e,t,n.op,a,s,r)}function ve(e,t,n,r,o,i){let a=D[i].size,s=r.ownsData?r.dataPtr:e.alloc(e.len*a,"data");if(o===null||(n==="div"||n==="mod")&&((i==="i32"||i==="u32")&&o===0||i==="i64"&&o===0n))return F(e,r.validity),oo(e,s,e.len*a),j(i,s,ct(e),null,false);let u=D[i].wasm;if(u==="i64"){let c=typeof o=="bigint"?o:BigInt(o);e.callBigInt(`${n}_i64_scalar`,r.dataPtr,c,s,e.len);}else e.call(`${n}_${u}_scalar`,r.dataPtr,o,s,e.len);return j(i,s,r.validity,null,false)}function Nr(e,t,n,r,o,i){if(Mr.has(n))return ve(e,t,n,o,r,i);let a=Qt(e,r,i);return tn(e,t,n,a,o,i)}function tn(e,t,n,r,o,i){let a=D[i].size,s=(n==="div"||n==="mod")&&(i==="i32"||i==="u32"||i==="i64"),l=N;if(s){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*a,"data"),c=D[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=Ae(e,r.validity,o.validity);return s&&(f=Ae(e,f,l)),j(i,u,f,null,false)}function $r(e,t,n,r){let o=L(e,t,r),i=D[n].size,a=o.ownsData?o.dataPtr:e.alloc(e.len*i,"data");return e.call(`neg_${n}`,o.dataPtr,a,e.len),j(n,a,o.validity,null,false)}function Lr(e,t,n){let r=n.operandDtype,o=St(n.left),i=St(n.right);if(o&&i){let c=G(e,t,n.left),f=G(e,t,n.right);return ro(e,no(n.op,c,f))}if(r==="bool")return zr(e,t,n,o);if(r==="utf8")return jr(e,t,n,o);let a=D[r].wasm,s=e.alloc(e.validityBytes,"mask");if(o||i){let c=L(e,t,o?n.right:n.left),f=G(e,t,o?n.left:n.right);if(f===null)return F(e,c.validity),e.free(c.ownsData?c.dataPtr:0),e.view(s,e.validityBytes,"u8").fill(0),{rep:"mask",maskPtr:s,ownsMask:true,validity:ct(e)};let m=o?Fr[n.op]:n.op;if(a==="i64"){let d=typeof f=="bigint"?f:BigInt(f);e.callBigInt(`${m}_i64_scalar_mask`,c.dataPtr,d,s,e.len);}else e.call(`${m}_${a}_scalar_mask`,c.dataPtr,f,s,e.len);return c.ownsData&&e.free(c.dataPtr),{rep:"mask",maskPtr:s,ownsMask:true,validity:c.validity}}let l=L(e,t,n.left),u=L(e,t,n.right);return e.call(`${n.op}_${a}_mask`,l.dataPtr,u.dataPtr,s,e.len),l.ownsData&&e.free(l.dataPtr),u.ownsData&&e.free(u.dataPtr),{rep:"mask",maskPtr:s,ownsMask:true,validity:Ae(e,l.validity,u.validity)}}function jr(e,t,n,r){let o=L(e,t,r?n.right:n.left),i=G(e,t,r?n.left:n.right),a=e.alloc(e.validityBytes,"mask"),s=e.view(a,e.validityBytes,"u8");if(i===null)return s.fill(0),o.ownsData&&e.free(o.dataPtr),F(e,o.validity),o.ownsDict&&Ft(t,o.dict),{rep:"mask",maskPtr:a,ownsMask:true,validity:ct(e)};let u=(o.dict?it(t.ctx,o.dict):[]).indexOf(i);return u>=0?e.call(`${n.op}_i32_scalar_mask`,o.dataPtr,u,a,e.len):s.fill(n.op==="ne"?255:0),o.ownsData&&e.free(o.dataPtr),o.ownsDict&&Ft(t,o.dict),{rep:"mask",maskPtr:a,ownsMask:true,validity:o.validity}}function zr(e,t,n,r){let o=G(e,t,r?n.left:n.right),i=ht(e,H(e,t,r?n.right:n.left));return (n.op==="eq"?o===false:o===true)?en(e,i):i}function Wr(e,t,n,r,o){let i=ht(e,H(e,t,r)),a=ht(e,H(e,t,o)),s=n==="and"?"and_kleene":"or_kleene",l=i.ownsData?i.dataPtr:a.ownsData?a.dataPtr:e.alloc(e.len,"data"),u=i.validity.ptr===0&&a.validity.ptr===0,c;if(u){let f=e.alloc(e.validityBytes,"scratch");e.call(s,i.dataPtr,0,a.dataPtr,0,l,f,e.len),e.free(f),c=N;}else {let f=e.alloc(e.validityBytes,"validity");e.call(s,i.dataPtr,i.validity.ptr,a.dataPtr,a.validity.ptr,l,f,e.len),F(e,i.validity),F(e,a.validity),c={ptr:f,owns:true};}return l!==i.dataPtr&&i.ownsData&&e.free(i.dataPtr),l!==a.dataPtr&&a.ownsData&&e.free(a.dataPtr),{rep:"boolcol",dataPtr:l,ownsData:true,validity:c}}function qr(e,t,n){return en(e,ht(e,H(e,t,n)))}function en(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 Hr(e,t,n){let r=H(e,t,n),o=Oe(r),i=e.alloc(e.len,"data");return e.call("is_null",o.ptr,i,e.len),nn(e,t,r),{rep:"boolcol",dataPtr:i,ownsData:true,validity:N}}function Yr(e,t,n,r,o){if(n==="bool")return Kr(e,t,r,o);if(n==="utf8")return Jr(e,t,r,o);let i=L(e,t,r);if(i.validity.ptr===0)return i;let a=D[n].size,s=i.ownsData?i.dataPtr:e.alloc(e.len*a,"data"),l=D[n].wasm;if(l==="i64"){let u=typeof o=="bigint"?o:BigInt(o);e.callBigInt("fill_null_i64",i.dataPtr,i.validity.ptr,u,s,e.len);}else e.call(`fill_null_${l}`,i.dataPtr,i.validity.ptr,o,s,e.len);return F(e,i.validity),j(n,s,N,null,false)}function Kr(e,t,n,r){let o=ht(e,H(e,t,n));if(o.validity.ptr===0)return o;let i=o.ownsData?o.dataPtr:e.alloc(e.len,"data"),a=e.view(o.dataPtr,e.len,"u8"),s=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(s,c)?a[c]:u;return F(e,o.validity),{rep:"boolcol",dataPtr:i,ownsData:true,validity:N}}function Jr(e,t,n,r){let o=L(e,t,n);if(o.validity.ptr===0)return o;let i=o.dict?it(t.ctx,o.dict):[],a=i.indexOf(r),s=o.dict,l=o.ownsDict;a<0&&(a=i.length,s=st(t.ctx,[...i,r]),e.track(s.offsetsPtr,(s.count+1)*4,"dict"),e.track(s.bytesPtr,Math.max(s.bytesLen,1),"dict"),o.ownsDict&&Ft(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]:a;return F(e,o.validity),j("utf8",u,N,s,l)}function Gr(e,t,n,r,o){let i=H(e,t,o);if(n===r)return i;let a=(i.rep==="boolcol",i.dataPtr),s=(i.rep==="boolcol",i.ownsData),l=Oe(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"),y=e.alloc(e.validityBytes,"scratch");return e.call("cast_i32_i64",a,l.ptr,p,y,e.len),e.free(y),e.callBigInt("mul_i64_scalar",p,xe,p,e.len),s&&e.free(a),j("timestamp",p,l,null,false)}if(n==="timestamp"&&r==="date32"){let p=e.view(a,e.len,"i64"),y=e.alloc(e.len*4,"data"),g=e.view(y,e.len,"i32");for(let h=0;h<e.len;h++){let x=p[h],w=x/xe;x%xe!==0n&&x<0n&&(w-=1n),g[h]=Number(w);}return s&&e.free(a),j("date32",y,l,null,false)}let u=D[r].size,f=s&&D[n].size===u?a:e.alloc(e.len*u,"data"),m=_r.has(`${n}_${r}`),d;if(m){let p=e.alloc(e.validityBytes,"validity");e.call(`cast_${n}_${r}`,a,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}`,a,l.ptr,f,p,e.len),e.free(p),d=l;}return f!==a&&s&&e.free(a),r==="bool"?{rep:"boolcol",dataPtr:f,ownsData:true,validity:d}:j(r,f,d,null,false)}function Zr(e,t,n,r){let o=L(e,t,r),i=e.len,a;if(r.kind==="col"){let f=t.getColumn(r.name);f?.tz&&(a=f.tz);}let s=null;o.validity.ptr!==0&&(s=e.view(o.validity.ptr,e.validityBytes,"u8"));let l;if(o.dtype==="date32"){let f=e.view(o.dataPtr,i,"i32");l=yt(f,s,n);}else {let f=e.view(o.dataPtr,i,"i64");l=yt(f,s,n,a);}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&&Ft(t,o.dict),j("i32",u,o.validity,null,false)}function Ce(e,t,n){let r=H(e,t,n.operand),o=Oe(r),i=r.rep==="mask"?0:(r.rep==="boolcol",r.dataPtr),a=r.rep==="column"?r.dict:null,s=n.operandDtype,l=s==="utf8"?"i32":s,u=e.len,c=o.ptr===0?u:e.call("count_null",o.ptr,u),f=Qr(e,t,n.op,s,l,i,o.ptr,u,c,a);return nn(e,t,r),{value:f,dtype:n.dtype}}function Qr(e,t,n,r,o,i,a,s,l,u){let c=r==="utf8"?"i32":D[r].wasm,f=m=>o==="u32"?m>>>0:m;switch(n){case "count":return l;case "nunique":return e.call(`nunique_${c}_null`,i,a,s);case "sum":return c==="i64"?e.callBigInt("sum_i64_null",i,a,s):e.call(`sum_${r}_null`,i,a,s);case "mean":return l>=1?e.call(`mean_${r}_null`,i,a,s):null;case "std":return l>=2?e.call(`std_${r}_null`,i,a,s):null;case "var":return l>=2?e.call(`var_${r}_null`,i,a,s):null;case "min":case "max":return l?c==="i64"?e.callBigInt(`${n}_i64_null`,i,a,s):f(e.call(`${n}_${c}_null`,i,a,s)):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,a,s,m):d=e.call(`${n}_${c}_null`,i,a,s,m);let p=e.view(m,1,"i32")[0]!==0;return e.free(m),p?c==="i64"?d:r==="utf8"?W(t.ctx,u,d):f(d):null}}}function ht(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 Xr(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]&&R(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 Oe(e){return e.validity}function to(e){return e==="bool"?"u8":e==="utf8"?"i32":D[e].wasm}function G(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 Ce(e,t,n).value;if(n.kind==="cast")return eo(G(e,t,n.operand),n.from,n.dtype);throw new Error(`internal: ${n.kind} is not a scalar operand`)}var Qe=9223372036854776e3;function eo(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 a=Math.trunc(i);return a>=Qe||a<-Qe?null:BigInt(a)}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 no(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 Qt(e,t,n){if(n==="utf8")throw new V("broadcasting a utf8 scalar to a column is not supported in P3.1.");if(n==="bool"){let s=e.alloc(e.len,"data");return e.view(s,e.len,"u8").fill(t===null?0:t?1:0),{rep:"boolcol",dataPtr:s,ownsData:true,validity:t===null?ct(e):N}}let r=D[n].size,o=e.alloc(e.len*r,"data");if(n==="i64"||n==="timestamp"){let s=e.view(o,e.len,"i64"),l=t===null?0n:typeof t=="bigint"?t:BigInt(t);for(let u=0;u<e.len;u++)s[u]=l;return j(n,o,t===null?ct(e):N,null,false)}let i=e.view(o,e.len,D[n].view),a=t===null?0:t;for(let s=0;s<e.len;s++)i[s]=a;return j(n,o,t===null?ct(e):N,null,false)}function ro(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?ct(e):N}}function Ae(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 ct(e){let t=e.alloc(e.validityBytes,"validity");return e.view(t,e.validityBytes,"u8").fill(0),{ptr:t,owns:true}}function oo(e,t,n){e.view(t,n,"u8").fill(0);}function j(e,t,n,r,o){return {rep:"column",dtype:e,dataPtr:t,ownsData:true,validity:n,dict:r,ownsDict:o}}function nn(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&&Ft(t,n.dict);}function Ft(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 rn(e,t){if(t.rep==="mask")return rn(e,ht(e,t));let n=e.ctx,r=t.rep==="boolcol"?"bool":t.dtype,o=D[r],i;t.ownsData?(i=t.dataPtr,e.transfer(t.dataPtr)):(i=n.mod.alloc(Math.max(e.len*o.size,1)),Xe(e,t.dataPtr,i,e.len*o.size));let a=t.validity,s=0;a.ptr!==0&&(a.owns?(s=a.ptr,e.transfer(a.ptr)):(s=n.mod.alloc(Math.max(e.validityBytes,1)),Xe(e,a.ptr,s,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=on(n,t.dict)),{dtype:r,length:e.len,dataPtr:i,validityPtr:s,validityBitOffset:0,dict:l,owned:true}}function Xe(e,t,n,r){if(r<=0)return;let o=e.view(t,r,"u8");e.view(n,r,"u8").set(o);}function on(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 P=class extends Error{constructor(t){super(t),this.name="FrameError";}};function nt(e,t){let n=qt(e,t),r=n?` Did you mean '${n}'?`:"",o=t.length?` Available columns: ${t.map(i=>`'${i}'`).join(", ")}.`:"";return new P(`unknown column '${e}'.${r}${o}`)}function sn(e,t,n,r){let o=r?` ${r}`:"";return new P(`dtype mismatch in '${e}': ${t} vs ${n}.${o}`)}function $(e,t){let n=e[t];if(typeof n!="function")throw new P(`kernel export not found: ${t}`);return n}var io=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;async function so(e,t){if(io){let[{readFile:i},{fileURLToPath:a}]=await Promise.all([import('fs/promises'),import('url')]),s;if(t===void 0)s=a(new URL(e,(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));else if(t instanceof URL)s=a(new URL(e,t));else if(t.startsWith("file:"))s=a(new URL(e,t));else {let{join:l}=await import('path');s=l(t,e);}return i(s)}let n=t??new URL(".",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),r=new URL(e,n),o=await fetch(r);if(!o.ok)throw new P(`failed to fetch wasm at ${r.toString()}: ${o.status}`);return o.arrayBuffer()}function an(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 ln(e={}){let t=e.simd??zt(),n=await so(t?"simd.wasm":"scalar.wasm",e.wasmDir),{instance:r}=await WebAssembly.instantiate(n,{});return an(r.exports,t)}var _t=null;async function ao(e){return _t=await ln(e),_t}function lo(e){_t=e;}function Xt(){if(_t===null)throw new P("no DataFrame runtime is loaded \u2014 call `await init()` first (or pass a runtime).");return _t}var Vt=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 Te(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 uo=new Set(["year","month","day","weekday","dayOfYear","quarter"]),Ie=class{constructor(t){this.series=t;}series;extract(t){let{dtype:n}=this.series;if(n==="date32"){if(!uo.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,a=n==="timestamp"&&r.tz?r.tz:void 0,s=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)s=d;else {let p=new Uint8Array(Math.ceil(i/8));for(let y=0;y<i;y++){let g=f+y;d[g>>3]>>(g&7)&1&&(p[y>>3]|=1<<(y&7));}s=p;}}let l;if(n==="date32"){let f=o.viewOf({ptr:r.dataPtr,length:i,dtype:"i32"});({data:l}=yt(f,s,t));}else {let f=o.viewOf({ptr:r.dataPtr,length:i,dtype:"i64"});({data:l}=yt(f,s,t,a));}let u=new Array(i);if(s!==null)for(let f=0;f<i;f++){let m=(s[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=I(o,"i32",u);return new gt(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")}},gt=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 q(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:D[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 Ie(this)}[Symbol.iterator](){return this.toArray()[Symbol.iterator]()}toString(){return `Series '${this.name}' (${this.dtype}, ${this.length} rows)`}};function un(e){return e==="bool"?"u8":e==="utf8"?"i32":D[e].wasm}function bt(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=A(r),i=e.mod.alloc(Math.max(o,1)),a=e.viewOf({ptr:t.validityPtr,length:A(n+r),dtype:"u8"}),s=e.viewOf({ptr:i,length:o,dtype:"u8"});s.fill(0);for(let l=0;l<r;l++)T(a,n+l)&&R(s,l);return {ptr:i,owns:true}}function wt(e,t){t.owns&&t.ptr!==0&&(e.viewOf.forget({ptr:t.ptr,length:1,dtype:"u8"}),e.mod.free(t.ptr));}function cn(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 fn(e,t){return Math.max(t*D[e].size,1)}function ke(e,t,n,r){let{ctx:o,wasm:i}=e,a=un(t.dtype),s=o.mod.alloc(fn(t.dtype,r));$(i,`gather_${a}`)(t.dataPtr,n,r,s);let l=0;if(t.validityPtr!==0){let c=bt(o,t),f=A(r),m=o.mod.alloc(Math.max(f,1));o.viewOf({ptr:m,length:Math.max(f,1),dtype:"u8"}).fill(0),$(i,"gather_validity")(c.ptr,n,r,m),wt(o,c),l=m;}let u=t.dict?cn(o,t.dict):null;return {dtype:t.dtype,length:r,dataPtr:s,validityPtr:l,validityBitOffset:0,dict:u,owned:true}}function mn(e,t,n){let{ctx:r,wasm:o}=e,i=t.length>0?t[0].length:0,a=r.mod.alloc(Math.max(i*4,1)),s=r.viewOf({ptr:a,length:i,dtype:"i32"});for(let c=0;c<i;c++)s[c]=c;let l=$(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--)co(e,t[c],n[c]===!0,a,i,u,l);}finally{u!==0&&(r.viewOf.forget({ptr:u,length:i,dtype:"i32"}),r.mod.free(u));}return {ptr:a,len:i}}function Pe(e,t,n,r,o,i,a,s,l){let u=$(e,t);l?u(n,r,o,i,a,s):u(n,r,o,i,a);}function co(e,t,n,r,o,i,a){let{ctx:s,wasm:l}=e,u=n?1:0,c=bt(s,t);try{if(t.dtype==="utf8"){let f=fo(e,t,o);try{Pe(l,"argsort_i32",f,c.ptr,r,o,u,i,a);}finally{s.viewOf.forget({ptr:f,length:o,dtype:"i32"}),s.mod.free(f);}}else if(t.dtype==="bool"){let f=mo(e,t,o);try{Pe(l,"argsort_i32",f,c.ptr,r,o,u,i,a);}finally{s.viewOf.forget({ptr:f,length:o,dtype:"i32"}),s.mod.free(f);}}else {let f=D[t.dtype].wasm;Pe(l,`argsort_${f}`,t.dataPtr,c.ptr,r,o,u,i,a);}}finally{wt(s,c);}}function fo(e,t,n){let{ctx:r}=e,o=t.dict?it(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}),a=new Int32Array(o.length);for(let c=0;c<i.length;c++)a[i[c]]=c;let s=r.mod.alloc(Math.max(n*4,1)),l=r.viewOf({ptr:t.dataPtr,length:n,dtype:"i32"}),u=r.viewOf({ptr:s,length:n,dtype:"i32"});for(let c=0;c<n;c++){let f=l[c];u[c]=f>=0&&f<a.length?a[f]:0;}return s}function mo(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"}),a=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let s=0;s<n;s++)a[s]=i[s];return o}function Ee(e,t){let n=0,r={};for(let{name:o,col:i}of t){let a=i.length,s=i.validityBitOffset,l=i.validityPtr===0?null:e.viewOf({ptr:i.validityPtr,length:A(s+a),dtype:"u8"});if(i.dtype==="utf8"){let u=e.viewOf({ptr:i.dataPtr,length:a,dtype:"i32"}),c=i.dict;Object.defineProperty(r,o,{enumerable:true,get(){return l&&!T(l,s+n)?null:W(e,c,u[n])}});}else if(i.dtype==="bool"){let u=e.viewOf({ptr:i.dataPtr,length:a,dtype:"bool"});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!T(l,s+n)?null:u[n]!==0}});}else if(i.dtype==="i64"){let u=e.viewOf({ptr:i.dataPtr,length:a,dtype:"i64"});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!T(l,s+n)?null:u[n]}});}else {let u=e.viewOf({ptr:i.dataPtr,length:a,dtype:D[i.dtype].view});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!T(l,s+n)?null:u[n]}});}}return {at(o){return n=o,r}}}function dn(e){if(e<=1)return 1;let t=1;for(;t<e;)t<<=1;return t}var pn=4,Ut=16;function Nt(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 yn(e,t,n,r,o){let i=Math.max(pn,dn(2*Math.max(n,1))),a=0;try{for(a=Nt(e,i*Ut);;){let s=e.group_build(t,n,a,i,r);if(s!==-1)return s;e.free(a),a=0,i*=2,a=Nt(e,i*Ut);}}finally{a!==0&&e.free(a);}}function hn(e,t,n,r,o,i,a,s,l){let u=Math.max(pn,dn(2*Math.max(s,1))),c=Math.max(1,o+s),f=0,m=0,d=0;try{if(f=Nt(e,u*Ut),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,a,s,f,u,m,d,c);if(p===-1){e.free(f),f=0,u*=2,f=Nt(e,u*Ut);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=Nt(e,u*Ut);continue}let y=new Int32Array(e.memory.buffer,m,p).slice(),g=new Int32Array(e.memory.buffer,d,p).slice();return {count:p,lIdx:y,rIdx:g}}}finally{f!==0&&e.free(f),m!==0&&e.free(m),d!==0&&e.free(d);}}function gn(e,t,n,r,o,i,a,s){return hn(e,(l,u,c,f,m,d,p,y,g,h,x)=>e.join_hash_inner(l,u,c,f,m,d,p,y,g,h,x),t,n,r,o,i,a)}function bn(e,t,n,r,o,i,a,s){return hn(e,(l,u,c,f,m,d,p,y,g,h,x)=>e.join_hash_left(l,u,c,f,m,d,p,y,g,h,x),t,n,r,o,i,a)}var po=new Set(["sum","mean","min","max","count","size","nunique","std","var","first","last"]),$t=class{src;keys;constructor(t,n){this.src=t,this.keys=n;for(let r of n)if(t.dtypeOf(r)===void 0)throw nt(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)),a=this.buildPlan(t),s=ho(n,i),l=[];try{let u=s.firstRow,c=[];for(let d=0;d<this.keys.length;d++){let p=bo(n,i[d],u);l.push(p),c.push({name:this.keys[d],col:p});}let f=r.viewOf({ptr:s.groupIdsPtr,length:o,dtype:"i32"});for(let d of a){let p=wo(n,d,f,s.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 a)u.ownsOperand&&u.operand&&Y(r,u.operand);r.viewOf.forget({ptr:s.groupIdsPtr,length:o,dtype:"i32"}),r.mod.free(s.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(!po.has(r))throw new P(`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 nt(n,this.src.columnNames());let i=yo(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 P(`agg value for '${t}' must be a top-level aggregation (e.g. col('a').sum()).`);let o=r.op,i=ge(r.operand,this.src),a=Rt(o,i),s=Mt(r.operand,this.src).execute();if(s.kind!=="column"||!s.column)throw new P(`aggregation operand for '${t}' did not produce a column.`);return {outName:t,op:o,operand:s.column,operandDtype:i,ownsOperand:true,resultDtype:a}}};function yo(e,t){return e==="size"?"i32":Rt(e,t)}function ho(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=go(e,m,o),p=bt(n,m);try{if(f===0)$(r,`hash_${d.tok}`)(d.ptr,p.ptr,i,o);else {let y=n.mod.alloc(Math.max(o*8,1));try{$(r,`hash_${d.tok}`)(d.ptr,p.ptr,y,o),$(r,"hash_combine")(i,y,o);}finally{n.viewOf.forget({ptr:y,length:o,dtype:"u8"}),n.mod.free(y);}}}finally{wt(n,p),d.free();}}let a=n.mod.alloc(Math.max(o*4,1)),s=yn(r,i,o,a),l=n.viewOf({ptr:a,length:o,dtype:"i32"}),u=new Int32Array(s),c=0;for(let f=0;f<o&&c<s;f++)l[f]===c&&(u[c++]=f);return {groupIdsPtr:a,groupCount:s,firstRow:u}}finally{n.viewOf.forget({ptr:i,length:o,dtype:"u8"}),n.mod.free(i);}}function go(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"}),a=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let s=0;s<n;s++)a[s]=i[s];return {ptr:o,tok:"i32",free(){r.viewOf.forget({ptr:o,length:n,dtype:"i32"}),r.mod.free(o);}}}return {ptr:t.dataPtr,tok:D[t.dtype].wasm,free(){}}}function bo(e,t,n){let{ctx:r}=e,o=n.length,i=t.validityPtr===0?null:r.viewOf({ptr:t.validityPtr,length:A(t.validityBitOffset+t.length),dtype:"u8"}),a=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,a+p)?null:W(r,f,c[p]);}return I(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,a+d)?null:c[d];}return I(r,"i64",f)}let s=t.dtype==="bool",l=r.viewOf({ptr:t.dataPtr,length:t.length,dtype:D[t.dtype].view}),u=new Array(o);for(let c=0;c<o;c++){let f=n[c];i&&!T(i,a+f)?u[c]=null:u[c]=s?l[f]!==0:l[f];}return I(r,t.dtype,u)}function wo(e,t,n,r,o){let{ctx:i}=e,{op:a}=t;if(a==="size"){let h=new Array(r).fill(0);for(let x=0;x<o;x++){let w=n[x];h[w]=h[w]+1;}return I(i,"i32",h)}let s=t.operand,l=s.validityPtr===0?null:i.viewOf({ptr:s.validityPtr,length:A(s.validityBitOffset+o),dtype:"u8"}),u=s.validityBitOffset,c=h=>l===null||T(l,u+h);if(a==="count"){let h=new Array(r).fill(0);for(let x=0;x<o;x++)if(c(x)){let w=n[x];h[w]=h[w]+1;}return I(i,"i32",h)}if(a==="first"||a==="last")return Ao(e,t,n,r,o,c);if(a==="nunique")return vo(e,t,n,r,o,c);if(a==="std"||a==="var")return xo(e,t,n,r,o,c);if(s.dtype==="i64"){let h=i.viewOf({ptr:s.dataPtr,length:o,dtype:"i64"});if(a==="sum"){let b=new Array(r).fill(0n);for(let v=0;v<o;v++)if(c(v)){let O=n[v];b[O]=b[O]+h[v];}return I(i,"i64",b)}if(a==="mean"){let b=new Float64Array(r),v=new Int32Array(r);for(let C=0;C<o;C++){if(!c(C))continue;let k=n[C];b[k]=b[k]+Number(h[C]),v[k]=v[k]+1;}let O=new Array(r);for(let C=0;C<r;C++)O[C]=v[C]>0?b[C]/v[C]:null;return I(i,"f64",O)}let x=new Array(r).fill(null),w=a==="min";for(let b=0;b<o;b++){if(!c(b))continue;let v=n[b],O=h[b];x[v]===null?x[v]=O:x[v]=w?O<x[v]?O:x[v]:O>x[v]?O:x[v];}return I(i,"i64",x)}let f=i.viewOf({ptr:s.dataPtr,length:o,dtype:D[s.dtype].view}),m=new Array(r).fill(null);if(a==="sum"){let h=new Float64Array(r);for(let x=0;x<o;x++)if(c(x)){let w=n[x];h[w]=h[w]+f[x];}for(let x=0;x<r;x++)m[x]=h[x];return I(i,t.resultDtype,m)}if(a==="mean"){let h=new Float64Array(r),x=new Int32Array(r);for(let w=0;w<o;w++){if(!c(w))continue;let b=n[w];h[b]=h[b]+f[w],x[b]=x[b]+1;}for(let w=0;w<r;w++)m[w]=x[w]>0?h[w]/x[w]:null;return I(i,"f64",m)}let d=new Int32Array(r),p=new Int32Array(r),y=new Float64Array(r),g=a==="min";for(let h=0;h<o;h++){if(!c(h))continue;let x=n[h];d[x]=d[x]+1;let w=f[h];Number.isNaN(w)||(p[x]===0?y[x]=w:y[x]=g?Math.min(y[x],w):Math.max(y[x],w),p[x]=p[x]+1);}for(let h=0;h<r;h++)m[h]=d[h]===0?null:p[h]===0?NaN:y[h];return I(i,t.resultDtype,m)}function xo(e,t,n,r,o,i){let{ctx:a}=e,s=t.operand,l=s.dtype==="i64",u=l?a.viewOf({ptr:s.dataPtr,length:o,dtype:"i64"}):a.viewOf({ptr:s.dataPtr,length:o,dtype:D[s.dtype].view}),c=new Float64Array(r),f=new Int32Array(r);for(let g=0;g<o;g++){if(!i(g))continue;let h=n[g];c[h]=c[h]+(l?Number(u[g]):u[g]),f[h]=f[h]+1;}let m=new Float64Array(r);for(let g=0;g<r;g++)m[g]=f[g]>0?c[g]/f[g]:0;let d=new Float64Array(r);for(let g=0;g<o;g++){if(!i(g))continue;let h=n[g],w=(l?Number(u[g]):u[g])-m[h];d[h]=d[h]+w*w;}let p=new Array(r),y=t.op==="std";for(let g=0;g<r;g++)if(f[g]<2)p[g]=null;else {let h=d[g]/(f[g]-1);p[g]=y?Math.sqrt(h):h;}return I(a,"f64",p)}function vo(e,t,n,r,o,i){let{ctx:a}=e,s=t.operand,l=new Array(r),u=s.dtype==="utf8"||s.dtype==="bool"?a.viewOf({ptr:s.dataPtr,length:o,dtype:s.dtype==="utf8"?"i32":"bool"}):s.dtype==="i64"?a.viewOf({ptr:s.dataPtr,length:o,dtype:"i64"}):a.viewOf({ptr:s.dataPtr,length:o,dtype:D[s.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 I(a,"i32",c)}function Ao(e,t,n,r,o,i){let{ctx:a}=e,s=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(s.dtype==="utf8"){let d=a.viewOf({ptr:s.dataPtr,length:o,dtype:"i32"}),p=s.dict;for(let y=0;y<r;y++)c[y]=u[y]===-1?null:W(a,p,d[u[y]]);return I(a,"utf8",c)}if(s.dtype==="i64"){let d=a.viewOf({ptr:s.dataPtr,length:o,dtype:"i64"});for(let p=0;p<r;p++){let y=u[p];c[p]=y===-1?null:d[y];}return I(a,"i64",c)}let f=s.dtype==="bool",m=a.viewOf({ptr:s.dataPtr,length:o,dtype:D[s.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 I(a,s.dtype,c)}function Cn(e,t,n){let r=n.how??"inner",o=Array.isArray(n.on)?n.on:[n.on];if(o.length===0)throw new P("join requires at least one key in `on`.");let i=e.rt,{ctx:a}=i,s=e.length,l=t.length;for(let c of o){let f=e.dtypeOf(c);if(f===void 0)throw nt(c,e.columnNames());let m=t.dtypeOf(c);if(m===void 0)throw nt(c,t.columnNames());if(f!==m)throw sn("join",f,m,`join key '${c}' must have one dtype.`)}let u=o.map(c=>Co(i,e.getColumn(c),t.getColumn(c),s,l));try{let c=An(i,u.map(y=>({ptr:y.leftPtr,tok:y.tok})),s),f=An(i,u.map(y=>({ptr:y.rightPtr,tok:y.tok})),l),m=Dn(i,o.map(y=>e.getColumn(y)),s),d=Dn(i,o.map(y=>t.getColumn(y)),l),p;try{let y=i.wasm;p=r==="left"?bn(y,c,m.ptr,s,f,d.ptr,l):gn(y,c,m.ptr,s,f,d.ptr,l);}finally{a.viewOf.forget({ptr:c,length:s,dtype:"u8"}),a.mod.free(c),a.viewOf.forget({ptr:f,length:l,dtype:"u8"}),a.mod.free(f),xt(i,m.ptr,m.owns),xt(i,d.ptr,d.owns);}return Do(e,t,o,p,r)}finally{for(let c of u)c.free();}}function Do(e,t,n,r,o){let i=e.rt,{ctx:a}=i,s=new Set(n),l=e.columnNames(),u=t.columnNames().filter(m=>!s.has(m)),c=new Set(l),f=[];try{let m=[];for(let p of l){let y=wn(i,e.getColumn(p),r.lIdx);f.push(y),m.push({name:p,col:y});}for(let p of u){let y=wn(i,t.getColumn(p),r.rIdx);f.push(y);let g=c.has(p)?`${p}_right`:p;m.push({name:g,col:y});}let d=e.buildResult(m);return f.length=0,d}finally{for(let m of f)Y(a,m);}}function wn(e,t,n){let{ctx:r}=e,o=q(r,t),i=new Array(n.length);for(let a=0;a<n.length;a++){let s=n[a];i[a]=s<0?null:o[s];}return I(r,t.dtype,i)}function Co(e,t,n,r,o){let{ctx:i}=e;if(t.dtype==="utf8"){let a=ce(i,t.dict,n.dict),s=xn(e,t,a.remapA,r),l=xn(e,n,a.remapB,o);return {leftPtr:s,rightPtr:l,tok:"i32",free(){xt(e,s,true),xt(e,l,true);}}}if(t.dtype==="bool"){let a=vn(e,t,r),s=vn(e,n,o);return {leftPtr:a,rightPtr:s,tok:"i32",free(){xt(e,a,true),xt(e,s,true);}}}return {leftPtr:t.dataPtr,rightPtr:n.dataPtr,tok:D[t.dtype].wasm,free(){}}}function xn(e,t,n,r){let{ctx:o}=e,i=o.mod.alloc(Math.max(r*4,1)),a=o.viewOf({ptr:t.dataPtr,length:r,dtype:"i32"}),s=o.viewOf({ptr:i,length:r,dtype:"i32"});for(let l=0;l<r;l++){let u=a[l];s[l]=u>=0&&u<n.length?n[u]:0;}return i}function vn(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"}),a=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let s=0;s<n;s++)a[s]=i[s];return o}function An(e,t,n){let{ctx:r,wasm:o}=e,i=r.mod.alloc(Math.max(n*8,1));for(let a=0;a<t.length;a++){let s=t[a];if(a===0)$(o,`hash_${s.tok}`)(s.ptr,0,i,n);else {let l=r.mod.alloc(Math.max(n*8,1));try{$(o,`hash_${s.tok}`)(s.ptr,0,l,n),$(o,"hash_combine")(i,l,n);}finally{r.viewOf.forget({ptr:l,length:n,dtype:"u8"}),r.mod.free(l);}}}return i}function Dn(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=A(n),a=r.mod.alloc(Math.max(i,1)),s=r.viewOf({ptr:a,length:Math.max(i,1),dtype:"u8"});s.fill(0);let l=o.map(u=>({view:r.viewOf({ptr:u.validityPtr,length:A(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&&R(s,u);}return {ptr:a,owns:true}}function xt(e,t,n){n&&t!==0&&(e.ctx.viewOf.forget({ptr:t,length:1,dtype:"u8"}),e.ctx.mod.free(t));}function On(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 Tn(e){return e==="utf8"||e==="bool"?"left":"right"}function Oo(e,t,n){let r=t-e.length;return r<=0?e:n==="right"?" ".repeat(r)+e:e+" ".repeat(r)}function In(e,t,n,r,o){let i=e.length,a=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);a[c]=f;}let s=c=>c.map((f,m)=>Oo(f,a[m],r[m])).join(" "),l=a.map(c=>"\u2500".repeat(c)).join(" "),u=[];u.push(s(e)),u.push(s(t)),u.push(l);for(let c of n)u.push(s(c));return o&&u.push(o),u.join(`
|
|
2
|
+
`)}var Io=new Set(["f64","f32","i32","u32","i64"]),z=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??Xt(),o=[],i=-1;for(let[a,s]of Object.entries(t)){let l=n.dtypes?.[a]??Te(s),u=l==="timestamp"?n.tzs?.[a]:void 0,c=I(r.ctx,l,s,u);if(i===-1)i=c.length;else if(c.length!==i)throw new P(`column '${a}' has length ${c.length}, expected ${i}.`);o.push({name:a,col:c});}return e.fromRoots(r,o,i===-1?0:i)}static fromRecords(t,n={}){n.runtime??Xt();let o=[],i=new Set;for(let s of t)for(let l of Object.keys(s))i.has(l)||(i.add(l),o.push(l));let a={};for(let s of o){let l=new Array(t.length);for(let u=0;u<t.length;u++){let c=t[u][s];l[u]=c===void 0?null:c;}a[s]=l;}return e.fromColumns(a,n)}static fromRoots(t,n,r){let o=n.map(i=>({name:i.name,col:i.col,owner:new Vt(t.ctx,i.col)}));return new e(t,o,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 gt(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 nt(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 Vt(this._rt.ctx,o),a={name:t,col:o,owner:i},s=[],l=false;for(let u of this.entries)u.name===t?(s.push(a),l=true):s.push(this.retainEntry(u));return l||s.push(a),new e(this._rt,s,this.length)}assign(t,n,r){return this.withColumn(t,n,r)}filter(t){let n=De(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=Ee(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=Ee(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 P("sortValues requires at least one key.");let o=r.map(s=>this.entryOf(s).col),i=Array.isArray(n.descending)?r.map((s,l)=>n.descending[l]===true):r.map(()=>n.descending===true),a=mn(this._rt,o,i);try{let s=this.entries.map(l=>({name:l.name,col:ke(this._rt,l.col,a.ptr,a.len)}));return e.fromRoots(this._rt,s,a.len)}finally{this._rt.ctx.viewOf.forget({ptr:a.ptr,length:a.len,dtype:"i32"}),this._rt.ctx.mod.free(a.ptr);}}groupby(t){let n=typeof t=="string"?[t]:[...t];if(n.length===0)throw new P("groupby requires at least one key.");return new $t(this,n)}join(t,n){return Cn(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(a=>({name:a.name,col:Wt(a.col,r,o),owner:a.owner.retain()}));return new e(this._rt,i,o-r)}toColumns(){let t={};for(let n of this.entries)t[n.name]=q(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 a of n)i[a]=t[a][o];r[o]=i;}return r}describe(){let t=["count","mean","std","min","25%","50%","75%","max"],n=this.entries.filter(i=>Io.has(i.col.dtype)),r={statistic:t},o={statistic:"utf8"};for(let i of n)r[i.name]=Po(q(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 nt(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=Mt(t,this).execute();if(o.kind==="column"&&o.column)return o.column;let i=o.scalar,a=new Array(this.length).fill(i.value);return I(this._rt.ctx,i.dtype,a)}let r=n.dtype??Te(t);if(t.length!==this.length)throw new P(`withColumn value has length ${t.length}, expected ${this.length}.`);return I(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 s=0;s<r;s++)i[s]=t[s];let a=this.entries.map(s=>({name:s.name,col:ke(this._rt,s.col,o,r)}));return e.fromRoots(this._rt,a,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(Tn),o=5,i=5,a=[],s=this.length>o+i,l=(c,f)=>{let m=this.entries.map(d=>q(this._rt.ctx,Wt(d.col,c,f)));for(let d=0;d<f-c;d++)a.push(m.map((p,y)=>On(p[d],n[y])));};s?(l(0,o),a.push(t.map(()=>"\u2026")),l(this.length-i,this.length)):l(0,this.length);let u=`[${this.length} rows \xD7 ${t.length} columns]`;return In(t,n,a,r,u)}};function ko(e){let t=[],n=r=>(t.push(r),r);try{return e(n)}finally{for(let r of t)r.dispose();}}function Po(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,a=n>=2?Math.sqrt(t.reduce((l,u)=>l+(u-i)*(u-i),0)/(n-1)):null,s=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,a,r[0],s(.25),s(.5),s(.75),r[r.length-1]]}var Eo=["","null","NA"],Ro=100,ee=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 a=o[r];if(this.inQuote)if(a==='"')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+=a,r++;else if(a==='"')this.inQuote=true,r++;else if(o.startsWith(n,r))this.row.push(this.field),this.field="",r+=n.length;else if(a==="\r")if(r+1<i)o[r+1]===`
|
|
3
|
+
`?(this.emitRow(),r+=2):(this.field+=a,r++);else if(t)this.emitRow(),r++;else break;else a===`
|
|
4
|
+
`?(this.emitRow(),r++):(this.field+=a,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=[];}},Bo=-2147483648,So=2**31-1,Pn=9223372036854775807n,En=-9223372036854775808n,Fo=9007199254740991n;function Be(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 kn(e){if(!Be(e))return false;let t=Number(e);return t>=Bo&&t<=So&&Number.isInteger(t)}function Mo(e){if(!Be(e))return false;try{let t=BigInt(e);return (t<0n?-t:t)>Fo&&t>=En&&t<=Pn}catch{return false}}function _o(e){if(!Be(e))return false;try{let t=BigInt(e);return t>=En&&t<=Pn}catch{return false}}function Re(e){if(e.length===0||e.trim().length===0)return false;let t=Number(e);return !isNaN(t)}function te(e){let t=e.toLowerCase();return t==="true"||t==="false"}function Vo(e,t){return e==="utf8"?"utf8":e==="i32"?kn(t)?"i32":Mo(t)?"i64":Re(t)?"f64":te(t)?"bool":"utf8":e==="i64"?_o(t)?"i64":Re(t)?"f64":te(t)?"bool":"utf8":e==="f64"?Re(t)?"f64":te(t)?"bool":"utf8":te(t)?"bool":(kn(t),"utf8")}function Uo(e,t){let n="i32",r=false;for(let o of e)if(!t.has(o)&&(r=true,n=Vo(n,o),n==="utf8"))return "utf8";return r?n:"utf8"}function No(e){try{return BigInt(e)}catch{throw new Error(`CSV parse error: cannot parse '${e}' as i64 \u2014 expected an integer decimal string.`)}}var $o=/^(-?\d{4,})-(\d{2})-(\d{2})$/;function Lo(e){let t=$o.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 Jt(n,r,o)}var jo=/Z$|[+-]\d{2}:?\d{2}$/;function zo(e){if(!jo.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 Wo(e,t,n){if(n.has(e))return null;switch(t){case "i64":return No(e);case "date32":return Lo(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 qo(e,t={}){let n=t.delimiter??",",r=t.header!==false,o=t.skipRows??0,i=t.maxRows??1/0,a=new Set(t.nullValues??Eo),s=t.dtypes??{},l=[],u=new ee(n,b=>l.push(b));u.feed(e),u.finish();let c=b=>b?{runtime:b}:{};if(l.length===0)return z.fromColumns({},c(t.runtime));let f=o;if(f>=l.length)return z.fromColumns({},c(t.runtime));let m,d;if(r?(m=l[f],d=f+1):(m=l[f].map((v,O)=>t.columns?.[O]??`column_${O}`),d=f),t.columns)for(let b=0;b<t.columns.length;b++)m[b]=t.columns[b];let p=m.length,y=l.slice(d,d+(isFinite(i)?i:l.length));for(let b=0;b<y.length;b++)if(y[b].length!==p)throw new Error(`CSV parse error: row ${d+b+1} has ${y[b].length} fields, expected ${p} (columns: ${m.join(", ")})`);if(y.length===0){let b={},v={};for(let C of m)b[C]=[],v[C]=s[C]??"utf8";let O={...c(t.runtime),dtypes:v};return z.fromColumns(b,O)}let g=y.slice(0,Ro),h={};for(let b=0;b<p;b++){let v=m[b];if(s[v])h[v]=s[v];else {let O=g.map(C=>C[b]);h[v]=Uo(O,a);}}let x={};for(let b of m)x[b]=new Array(y.length);for(let b=0;b<y.length;b++){let v=y[b];for(let O=0;O<p;O++){let C=m[O];x[C][b]=Wo(v[O],h[C],a);}}let w={...c(t.runtime),dtypes:h};return z.fromColumns(x,w)}function Ho(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 z.fromRecords(n,t)}function Yo(e){return JSON.stringify(e.toRecords())}var Lt=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 s=t-1;s>=0;s--){let l=this.vtableFields.get(s),u=l!==void 0?n-l:0;this.writeU16(u);}this.writeU16(r),this.writeU16(o);let a=this.offset()-n;return this.dv.setInt32(this.space.length-n,a,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)}},Se=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,a=n.getUint16(i,true),s=4+t*2;if(s>=a)return 0;let l=n.getUint16(i+s,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 vt(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0,true);return new Se(t,n)}var Fn=4,Mn=1,Ue=2,Ne=3,ne=2,Me=3,_n=5,Vn=6,Un=8,Nn=10,Ko=20,Jo=1,$n=2,At=16,Ln=0,_e=1,oe=0,$e=1,Go=2,Zo=3,Qo=9223372036854775n,Xo=-9223372036854775n,ie=e=>e+7&-8;function ti(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 ei(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 ni(e,t){if(t.validityPtr===0)return null;let n=t.validityBitOffset+t.length,r=e.viewOf({ptr:t.validityPtr,length:A(n),dtype:"u8"});if(t.validityBitOffset===0)return r.slice(0,A(t.length));let o=new Uint8Array(A(t.length));for(let i=0;i<t.length;i++)T(r,t.validityBitOffset+i)&&R(o,i);return o}function Rn(e){return e.startTable(),e.endTable()}function re(e,t,n){return e.startTable(),e.addFieldI32(0,t,0),e.addFieldBool(1,n,false),e.endTable()}function Bn(e,t){return e.startTable(),e.addFieldI16(0,t,0),e.endTable()}function ri(e,t){let n=re(e,32,true);return e.startTable(),e.addFieldI64(0,t),e.addFieldOffset(1,n),e.endTable()}function oi(e){return e.startTable(),e.addFieldI16(0,Ln,_e),e.endTable()}function ii(e,t){let n=t?e.createString(t):null;return e.startTable(),e.addFieldI16(0,$e,oe),n!==null&&e.addFieldOffset(1,n),e.endTable()}function si(e,t,n,r,o){let i=e.createString(t),a,s,l=null;switch(n){case "f64":a=Me,s=Bn(e,$n);break;case "f32":a=Me,s=Bn(e,Jo);break;case "i32":a=ne,s=re(e,32,true);break;case "u32":a=ne,s=re(e,32,false);break;case "i64":a=ne,s=re(e,64,true);break;case "bool":a=Vn,s=Rn(e);break;case "utf8":a=_n,s=Rn(e),r!==null&&(l=ri(e,r));break;case "date32":a=Un,s=oi(e);break;case "timestamp":a=Nn,s=ii(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,a),e.addFieldOffset(3,s),l!==null&&e.addFieldOffset(4,l),e.addFieldOffset(5,u),e.endTable()}function ai(e,t,n,r){let o=new Lt(1024),i=e.map((u,c)=>si(o,u,t[c],n[c],r[c])),a=o.createOffsetVector(i);o.startTable(),o.addFieldI16(0,0),o.addFieldOffset(1,a);let s=o.endTable();o.startTable(),o.addFieldI16(0,Fn),o.addFieldI8(1,Mn),o.addFieldOffset(2,s);let l=o.endTable();return o.finish(l)}function li(e){return jn(e,Ne,-1)}function ui(e,t){return jn(e,Ue,t)}function jn(e,t,n){let r=new Lt(512),o=new Uint8Array(e.nodes.length*At),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 a=r.createStructVector(o,e.nodes.length),s=new Uint8Array(e.buffers.length*At),l=new DataView(s.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(s,e.buffers.length),c=e.nodes.length>0?e.nodes[0].length:0;r.startTable(),r.addFieldI64(0,c),r.addFieldOffset(1,a),r.addFieldOffset(2,u);let f=r.endTable(),m=f;t===Ue&&(r.startTable(),r.addFieldI64(0,n),r.addFieldOffset(1,f),m=r.endTable()),r.startTable(),r.addFieldI16(0,Fn),r.addFieldI8(1,t),r.addFieldOffset(2,m),r.addFieldI64(3,e.body.byteLength);let d=r.endTable();return r.finish(d)}function ft(e,t){if(!t||t.byteLength===0)return {offset:0,length:0};let n=e.size;e.parts.push(t);let r=ie(t.byteLength);return r>t.byteLength&&e.parts.push(new Uint8Array(r-t.byteLength)),e.size+=r,{offset:n,length:t.byteLength}}function Sn(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 Fe(e,t){let n=e.byteLength,r=ie(n),o=8+r+t.byteLength,i=new Uint8Array(o),a=new DataView(i.buffer);return a.setInt32(0,-1,true),a.setInt32(4,r,true),i.set(e,8),i.set(t,8+r),i}function ci(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)),a=o.map(()=>null),s=0;for(let w=0;w<o.length;w++)o[w]==="utf8"&&(a[w]=s++);let l=i.map(w=>w.dtype==="timestamp"?w.tz:void 0),u=[];u.push(Fe(ai(n,o,a,l),new Uint8Array(0)));for(let w=0;w<i.length;w++){if(o[w]!=="utf8")continue;let v=i[w].dict,O=v.count,C=a[w],k=t.viewOf({ptr:v.offsetsPtr,length:O+1,dtype:"i32"}),E=v.bytesLen>0?t.viewOf({ptr:v.bytesPtr,length:v.bytesLen,dtype:"u8"}):new Uint8Array(0),rt={parts:[],size:0},Z=ft(rt,null),Q=ft(rt,new Uint8Array(k.buffer,k.byteOffset,k.byteLength).slice()),mt=ft(rt,E.slice()),ot=Sn(rt.parts),Dt={nodes:[{length:O,nullCount:0}],buffers:[Z,Q,mt],body:ot};u.push(Fe(ui(Dt,C),ot));}let c={parts:[],size:0},f=[],m=[];for(let w=0;w<i.length;w++){let b=i[w],v=o[w],O=0;if(b.validityPtr!==0){let C=b.validityBitOffset+r,k=t.viewOf({ptr:b.validityPtr,length:A(C),dtype:"u8"});for(let E=0;E<r;E++)T(k,b.validityBitOffset+E)||O++;}if(f.push({length:r,nullCount:O}),m.push(ft(c,ni(t,b))),v==="utf8"){let C=t.viewOf({ptr:b.dataPtr,length:r,dtype:"i32"});m.push(ft(c,new Uint8Array(C.buffer,C.byteOffset,C.byteLength).slice()));}else if(v==="bool"){let C=t.viewOf({ptr:b.dataPtr,length:r,dtype:"bool"});m.push(ft(c,ti(C,r)));}else {let C=D[v],k=t.viewOf({ptr:b.dataPtr,length:r,dtype:C.view});m.push(ft(c,new Uint8Array(k.buffer,k.byteOffset,r*C.size).slice()));}}let d=Sn(c.parts),p={nodes:f,buffers:m,body:d};u.push(Fe(li(p),d));let y=new Uint8Array(8);new DataView(y.buffer).setInt32(0,-1,true),u.push(y);let g=u.reduce((w,b)=>w+b.byteLength,0),h=new Uint8Array(g),x=0;for(let w of u)h.set(w,x),x+=w.byteLength;return h}var Ve=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+=ie(n);let i=vt(r).getInt64Num(3),a=i>0?this.buf.slice(this.pos,this.pos+i):new Uint8Array(0);return this.pos+=ie(i),{meta:r,body:a}}};function fi(e){let t=vt(e);if(t.getUint8(1,0)!==Mn)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 a=n.vectorTable(1,i),s=a.getString(0)??`f${i}`,l=a.getUint8(2,0),u=a.getTable(3),c=a.getTable(4),f=c?c.getInt64Num(0):null,m,d=false,p,y;switch(l){case ne:{let g=u?.getInt32(0,32)??32,h=u?.getBool(1,false)??false;if(g===64){if(!h)throw new Error("Arrow fromArrow: unsupported Arrow type UInt64. databonk supports Int64(signed) as 'i64'.");m="i64";}else m=g<=32&&!h?"u32":"i32";break}case Me:{m=(u?.getInt16(0,0)??0)===$n?"f64":"f32";break}case Vn:m="bool";break;case _n:case Ko:m="utf8",d=f===null;break;case Un:{let g=u?.getInt16(0,_e)??_e;if(g!==Ln)throw new Error(`Arrow fromArrow: unsupported Date unit ${g} (only Date32(DAY)=0 is supported).`);m="date32";break}case Nn:{let g=u?.getInt16(0,oe)??oe,h=u?.getString(1)??void 0;m="timestamp",y=g,p=h;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:s,dtype:m,dictId:f,plainUtf8:d,...p!==void 0?{tz:p}:{},...y!==void 0?{arrowUnit:y}:{}});}return o}function mi(e,t){let r=vt(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 a=i.getInt64Num(0),s=g=>i.i32at(i.structVectorElemPos(2,g,At)),l=g=>i.i32at(i.structVectorElemPos(2,g,At)+8),u=i.vectorLen(2);if(u<2)throw new Error("Arrow: DictionaryBatch RecordBatch needs \u22652 buffers");let c=s(1);l(1);let m=u>=3?s(2):0,d=u>=3?l(2):0,p=new Int32Array(t.buffer,t.byteOffset+c,a+1).slice(),y=d>0?t.slice(m,m+d):new Uint8Array(0);return {id:o,entry:{offsets:p,bytes:y,count:a}}}function di(e,t,n,r,o){let i=vt(e);if(i.getUint8(1,0)!==Ne)throw new Error("Arrow: expected RecordBatch");let a=i.getTable(2);if(!a)throw new Error("Arrow: missing RecordBatch table");let s=a.getInt64Num(0),l=a.vectorLen(1);if(l!==n.length)throw new Error(`Arrow: field count mismatch (schema=${n.length}, batch=${l})`);let u=d=>a.i32at(a.structVectorElemPos(2,d,At)),c=d=>a.i32at(a.structVectorElemPos(2,d,At)+8),f=[],m=0;for(let d=0;d<n.length;d++){let{dtype:p,dictId:y,plainUtf8:g}=n[d],h=u(m),x=c(m);m++;let w=x>0;if(p==="utf8")if(y!==null){let b=u(m);m++;let v=r.get(y);if(!v)throw new Error(`Arrow: missing dictionary id=${y}`);let O=new TextDecoder,C=[];for(let Q=0;Q<v.count;Q++){let mt=v.offsets[Q],ot=v.offsets[Q+1];C.push(ot>mt?O.decode(v.bytes.subarray(mt,ot)):"");}let k=st(o,C),E=o.mod.alloc(Math.max(s*4,1));o.viewOf({ptr:E,length:s,dtype:"i32"}).set(new Int32Array(t.buffer,t.byteOffset+b,s));let Z=0;w&&(Z=o.mod.alloc(A(s)),o.viewOf({ptr:Z,length:A(s),dtype:"u8"}).set(t.subarray(h,h+A(s)))),f.push({dtype:"utf8",length:s,dataPtr:E,validityPtr:Z,validityBitOffset:0,dict:k,owned:true});}else {let b=u(m);m++;let v=u(m),O=c(m);m++;let C=new Int32Array(t.buffer,t.byteOffset+b,s+1),k=t.subarray(v,v+O),E=new TextDecoder,rt=new Map,Z=[],Q=new Int32Array(s);for(let Ct=0;Ct<s;Ct++){let zn=C[Ct],Wn=C[Ct+1],se=E.decode(k.subarray(zn,Wn)),jt=rt.get(se);jt===void 0&&(jt=Z.length,Z.push(se),rt.set(se,jt)),Q[Ct]=jt;}let mt=st(o,Z),ot=o.mod.alloc(Math.max(s*4,1));o.viewOf({ptr:ot,length:s,dtype:"i32"}).set(Q);let Dt=0;w&&(Dt=o.mod.alloc(A(s)),o.viewOf({ptr:Dt,length:A(s),dtype:"u8"}).set(t.subarray(h,h+A(s)))),f.push({dtype:"utf8",length:s,dataPtr:ot,validityPtr:Dt,validityBitOffset:0,dict:mt,owned:true});}else if(p==="bool"){let b=u(m),v=c(m);m++;let O=t.subarray(b,b+v),C=ei(O,s),k=o.mod.alloc(Math.max(s,1));o.viewOf({ptr:k,length:s,dtype:"bool"}).set(C);let E=0;w&&(E=o.mod.alloc(A(s)),o.viewOf({ptr:E,length:A(s),dtype:"u8"}).set(t.subarray(h,h+A(s)))),f.push({dtype:"bool",length:s,dataPtr:k,validityPtr:E,validityBitOffset:0,dict:null,owned:true});}else {let b=D[p],v=u(m);m++;let O=o.mod.alloc(Math.max(s*b.size,1)),C=o.viewOf({ptr:O,length:s,dtype:b.view}),k=new b.ctor(t.buffer,t.byteOffset+v,s);C.set(k);let E=0;w&&(E=o.mod.alloc(A(s)),o.viewOf({ptr:E,length:A(s),dtype:"u8"}).set(t.subarray(h,h+A(s)))),f.push({dtype:p,length:s,dataPtr:O,validityPtr:E,validityBitOffset:0,dict:null,owned:true});}}return f}function pi(e,t){return t===$e?e:e.map(n=>{if(n===null)return null;switch(t){case oe:return n>Qo||n<Xo?null:n*1000n;case Go:return n/1000n;case Zo:return n/1000000n;default:return null}})}function yi(e,t){let n=new Ve(e),r=n.next();if(!r)throw new Error("Arrow fromArrow: empty or truncated buffer");let o=fi(r.meta),i=new Map,a=null;for(;;){let m=n.next();if(!m)break;let p=vt(m.meta).getUint8(1,0);if(p===Ue){let{id:y,entry:g}=mi(m.meta,m.body);i.set(y,g);}else if(p===Ne){a=m;break}}if(!a)throw new Error("Arrow fromArrow: no RecordBatch found in stream");let s=di(a.meta,a.body,o,i,t.ctx),l={},u={},c={};for(let m=0;m<o.length;m++){let{name:d,dtype:p,tz:y,arrowUnit:g}=o[m],h=q(t.ctx,s[m]);p==="timestamp"&&g!==void 0&&g!==$e&&(h=pi(h,g)),l[d]=h,u[d]=p,y&&(c[d]=y),hi(t.ctx,s[m]);}let f={runtime:t,dtypes:u,tzs:c};return z.fromColumns(l,f)}function hi(e,t){Y(e,t);}var gi="0.2.0";function qa(e="world"){return `Hello, ${e}! dataframe v${gi}`}exports.ChunkParser=ee;exports.DTYPES=D;exports.DataFrame=z;exports.Expr=_;exports.ExprError=V;exports.FrameError=P;exports.GroupBy=$t;exports.Series=gt;exports.VERSION=gi;exports.aggResult=Rt;exports.badLiteral=at;exports.callKernel=be;exports.clearBit=Zn;exports.col=lr;exports.columnToArray=q;exports.compile=Mt;exports.compileFilter=De;exports.createColumn=I;exports.createMemoryContext=le;exports.createViewOf=ae;exports.decodeDictionary=it;exports.decodeSlot=W;exports.decodeStats=er;exports.defaultRuntime=Xt;exports.detectSimd=zt;exports.dtypeInfo=Gn;exports.dtypeMismatch=lt;exports.freeColumn=Y;exports.freeDictionary=fe;exports.fromArrow=yi;exports.fromCSV=qo;exports.fromJSON=Ho;exports.getBit=T;exports.hello=qa;exports.inferType=ge;exports.init=ao;exports.lit=je;exports.loadRuntime=ln;exports.loadWasmModule=Kn;exports.nearest=qt;exports.resolve=Et;exports.runtimeFromExports=an;exports.schemaOf=fr;exports.scope=ko;exports.setBit=R;exports.sliceColumn=Wt;exports.toArrow=ci;exports.toExpr=Tt;exports.toJSON=Yo;exports.unifyDictionaries=ce;exports.unknownColumn=ye;exports.unsupportedCast=pe;exports.unsupportedDtype=B;exports.useRuntime=lo;exports.validityBytes=A;exports.writeDictionary=st;//# sourceMappingURL=index.cjs.map
|
|
5
|
+
//# sourceMappingURL=index.cjs.map
|