@jrc03c/js-math-tools
Version:
some math tools for JS
17 lines (14 loc) • 68.7 kB
JavaScript
(()=>{var Cr=Object.defineProperty;var Jr=(e,t)=>{for(var r in t)Cr(e,r,{get:t[r],enumerable:!0})};var se={};Jr(se,{DataFrame:()=>Y,IndexMatcher:()=>ht,MathError:()=>V,Series:()=>U,abs:()=>ct,add:()=>ut,apply:()=>it,arccos:()=>qe,arcsin:()=>Ve,arctan:()=>Ge,argmax:()=>jt,argmin:()=>Bt,assert:()=>a,cast:()=>$,ceil:()=>We,chop:()=>He,clamp:()=>Qe,combinations:()=>Pt,combinationsIterator:()=>Ut,copy:()=>F,correl:()=>zt,cos:()=>Ze,count:()=>st,covariance:()=>ft,dataTypes:()=>tr,decycle:()=>et,diff:()=>Ct,distance:()=>$t,divide:()=>nr,dot:()=>X,dropMissing:()=>wt,dropMissingPairwise:()=>Ot,dropNaN:()=>St,dropNaNPairwise:()=>Tt,dropUndefined:()=>or,every:()=>yt,exp:()=>ir,factorial:()=>sr,filter:()=>x,find:()=>Kt,findAll:()=>Lt,flatten:()=>E,float:()=>mr,floor:()=>ar,forEach:()=>N,identity:()=>ur,indexOf:()=>Q,inferType:()=>_t,int:()=>C,intersect:()=>kt,inverse:()=>Dt,isArray:()=>f,isBoolean:()=>tt,isBrowser:()=>It,isDataFrame:()=>b,isDate:()=>K,isEqual:()=>P,isFunction:()=>_,isJagged:()=>Z,isNested:()=>mt,isNumber:()=>p,isObject:()=>M,isSeries:()=>g,isString:()=>O,isUndefined:()=>h,lerp:()=>cr,log:()=>dr,map:()=>d,max:()=>ot,mean:()=>gr,median:()=>yr,merge:()=>br,min:()=>Et,mod:()=>vr,mode:()=>Sr,multiply:()=>Yt,ndarray:()=>z,normal:()=>Or,ones:()=>Tr,permutations:()=>_r,permutationsIterator:()=>Vt,pow:()=>dt,print:()=>Dr,product:()=>rt,random:()=>W,range:()=>D,reduce:()=>Ir,remap:()=>Ar,reshape:()=>nt,reverse:()=>q,round:()=>Fr,scale:()=>H,seed:()=>re,set:()=>B,shape:()=>v,shuffle:()=>at,sign:()=>Mr,sin:()=>jr,some:()=>Gt,sort:()=>L,sqrt:()=>Jt,stats:()=>I,std:()=>Wt,stdev:()=>Er,subtract:()=>Rt,sum:()=>gt,tan:()=>Br,time:()=>Ur,transpose:()=>R,union:()=>Pr,variance:()=>kr,vectorize:()=>w,zeros:()=>bt,zip:()=>zr});function p(e){return typeof e=="number"&&!isNaN(e)||typeof e=="bigint"}var It=new Function(`
try {
return this === window
} catch(e) {}
try {
return !!importScripts
} catch(e){}
return false
`);var V=class extends Error{constructor(t){It()?super(t):super(`
\x1B[31m`+t+`
\x1B[0m`)}};function a(e,t){if(!e)throw new V(t)}function N(e,t){for(let r=0;r<e.length;r++)t(e[r],r,e)}var Xt=[Array,ArrayBuffer,BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int16Array,Int32Array,Int8Array,Uint16Array,Uint32Array,Uint8Array,Uint8ClampedArray];function h(e){return e===null||typeof e>"u"}function d(e,t){let r=new Array(e.length);for(let n=0;n<e.length;n++)r[n]=t(e[n],n,e);return r}var Yr=d(Xt,e=>e.name);function f(e){try{return e instanceof Array?!0:h(e.constructor)?!1:Xt.indexOf(e.constructor)>-1||Yr.indexOf(e.constructor.name)>-1}catch{return!1}}function b(e){try{return!!e._symbol&&e._symbol===Symbol.for("@jrc03c/js-math-tools/dataframe")}catch{return!1}}function _(e){return typeof e=="function"}function M(e){return typeof e=="object"&&!h(e)&&!f(e)}function g(e){try{return!!e._symbol&&e._symbol===Symbol.for("@jrc03c/js-math-tools/series")}catch{return!1}}function Q(e,t){if(b(e)){let i=Q(e.values,t);return i.length>0&&p(i[0])&&i[0]>=0&&i[0]<e.index.length&&(i[0]=e.index[i[0]]),i.length>1&&p(i[1])&&i[1]>=0&&i[1]<e.columns.length&&(i[1]=e.columns[i[1]]),i}if(g(e)){let i=Q(e.values,t);return i.length>0&&p(i[0])&&i[0]>=0&&i[0]<e.index.length&&(i[0]=e.index[i[0]]),i}if(a(M(e)||f(e),"You must pass (1) an object, array, Series, or DataFrame and (2) a function or value into the `indexOf` function!"),!_(t)){let i=t;t=m=>m===i}function r(i,m,s){if(s=s||[],s.indexOf(i)>-1)return null;if(M(i)){s.push(i);let u=Object.keys(i).concat(Object.getOwnPropertySymbols(i));for(let l=0;l<u.length;l++){let c=u[l],y=i[c];if(m(y))return[c];let S=r(y,m,s);if(S&&S.length>0)return[c].concat(S)}}else if(f(i)){s.push(i);for(let u=0;u<i.length;u++){let l=i[u];if(m(l))return[u];let c=r(l,m,s);if(c&&c.length>0)return[u].concat(c)}}else if(m(i))return[];return null}function n(i){try{return t(i)}catch{return!1}}let o=r(e,n);return o&&o.length>0?o:null}function F(e){function t(r){if(typeof r=="object"){if(r===null)return null;if(f(r))return r instanceof Array?d(r,o=>F(o)):r.slice();if(g(r)){let o=r.copy();return o.values=F(o.values),o}if(b(r)){let o=r.copy();return o.values=F(r.values),o}if(r instanceof Date)return new Date(r.getTime());r=et(r);let n={};return N(Object.keys(r).concat(Object.getOwnPropertySymbols(r)),o=>{n[o]=F(r[o])}),n}else return r}return t(et(e))}function et(e){function t(o,i,m){if(i=i||[],m=m||"",i.indexOf(o)>-1){let s=m.split("/").slice(m.startsWith("/")?1:0);if(s.some((l,c)=>{let y=s.slice(0,s.length-c-1),S=r;return N(y,T=>{S=S[T]}),S===o}))return`<reference to "${r===o?"/":"/"+Q(r,o).join("/")}">`}return typeof o=="object"?o===null?null:(i.push(o),f(o)?typeof o.constructor<"u"&&o.constructor.name!=="Array"?o.slice():d(o,(s,u)=>t(s,i,m+"/"+u)):(N(Object.keys(o).concat(Object.getOwnPropertySymbols(o)),s=>{o[s]=t(o[s],i,m+"/"+s.toString())}),o)):o}let r=e,n=t(r);if(b(e)){let o=e.copy();o._values=n.values,o._columns=n.columns,o._index=n.index,n=o}if(g(e)){let o=e.copy();o.name=n.name,o._values=n.values,o._index=n.index,n=o}return n}function K(e){return e instanceof Date&&e.toString()!=="Invalid Date"}var me=["number","int","float","bigint"];function P(e,t){function r(n,o){let i=typeof n,m=typeof o;if(i!==m&&!me.includes(i)&&!me.includes(m))return!1;if(i==="undefined"&&m==="undefined")return!0;if(i==="boolean"||i==="symbol")return n===o;if(i==="number"||i==="bigint")try{let s=n.toString(),u=o.toString();return s===u}catch{return!1}if(i==="string"||i==="function")return n===o;if(i==="object"){if(n===null||o===null)return n===null&&o===null;{if(K(n))return K(o)?n.getTime()===o.getTime():!1;if(K(o))return!1;if(n instanceof RegExp&&o instanceof RegExp)return n.toString()===o.toString();if(f(n)!==f(o))return!1;let s=Object.keys(n).concat(Object.getOwnPropertySymbols(n)),u=Object.keys(o).concat(Object.getOwnPropertySymbols(o));if(s.length!==u.length)return!1;for(let l=0;l<s.length;l++){let c=s[l];if(!r(n[c],o[c]))return!1}return!0}}}try{return r(e,t)}catch{return r(et(e),et(t))}}function Nt(e){let t="abcdefg1234567890",r="";for(;r.length<e;)r+=t[Math.floor(Math.random()*t.length)];return r}var Rr=Nt(16),$r=Nt(16),Kr=Nt(16),Lr=Nt(16),qr=Nt(16),At=class{constructor(){this.clear()}get counts(){return d(this.values,t=>this.get(t))}get values(){return Object.values(this.valuesDict)}clear(){return this.countsDict={},this.valuesDict={},this}count(t){for(let r of t)f(r)?this.count(r):this.increment(r);return this}delete(t){let r=this.getStandardizedKey(t);return delete this.countsDict[r],delete this.valuesDict[r],this}get(t){return this.countsDict[this.getStandardizedKey(t)]||0}getStandardizedKey(t){return typeof t=="object"&&t===null?Rr:h(t)?$r:_(t)?t.toString():typeof t=="symbol"?t.toString()+" - "+qr:t===1/0?Kr:t===-1/0?Lr:typeof t=="bigint"?t.toString():b(t)?t.toJSONString():g(t)?JSON.stringify(t.toObject()):JSON.stringify(t)}has(t){return!h(this.countsDict[this.getStandardizedKey(t)])}increment(t){return this.set(t,this.get(t)+1)}set(t,r){let n=this.getStandardizedKey(t);return this.countsDict[n]=r,this.valuesDict[n]=t,this}toArray(){return d(this.values,t=>({value:t,count:this.get(t)}))}toObject(){let t={};return N(this.values,r=>{t[r]=this.get(r)}),t}};function E(e){if(b(e)||g(e))return E(e.values);a(f(e),"The `flatten` function only works on arrays, Series, and DataFrames!");function t(r){let n=[];return N(r,o=>{f(o)?n=n.concat(t(o)):n.push(o)}),n}return t(e)}function I(e,t){t=t||{};let r=new At,n={},o=E(e),i=[],m=-1/0,s=1/0,u=!1,l=0;for(let y of o){if(typeof y=="bigint"&&(u=!0),!t.shouldDropNaNs||p(y))try{y>m&&(m=y),y<s&&(s=y),l+=Number(y),i.push(y)}catch{m=NaN,s=NaN,l=NaN}r.increment(y)}let c=l/i.length;if(n.counts=r,n.max=m,n.mean=c,n.min=s,n.n=o.length,n.sum=l,isNaN(n.mean)&&(n.max=NaN,n.min=NaN),t.shouldDropNaNs&&(n.nWithoutNaNs=i.length),t.mode){let y=Array.from(d(r.values,j=>[j,r.get(j)])).toSorted((j,k)=>k[1]-j[1]),S=y[0][1],T=[];for(let j of y)if(j[1]==S)T.push(j[0]);else break;n.mode=T.toSorted()}if(t.median)if(isNaN(c))n.median=NaN;else{let y=i.toSorted((T,j)=>Number(T)-Number(j)),S=Math.floor(y.length/2);if(y.length%2===0){let T=y[S-1],j=y[S];if(n.median=(Number(T)+Number(j))/2,u&&typeof T=="bigint"&&typeof j=="bigint")try{n.median=BigInt(n.median)}catch{}}else n.median=y[S]}if(t.stdev||t.variance){let y=0;for(let T of i)y+=Math.pow(Number(T)-c,2);y/=i.length;let S=Math.sqrt(y);n.stdev=S,n.variance=y}if(u){try{n.sum=BigInt(n.sum)}catch{}try{n.mean=BigInt(n.mean)}catch{}t.mode&&(n.mode=d(n.mode,y=>{try{return BigInt(y)}catch{return y}}))}return n}function st(e,t){let{counts:r}=I(e);return h(t)||(_(t)?N(r.values,n=>{t(n)||r.delete(n)}):N(r.values,n=>{P(n,t)||r.delete(n)})),r}function x(e,t){let r=[];for(let n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}function Qt(e){if(b(e)||g(e))return Qt(e.values);if(f(e)){let t=!1,r=!1,n=null;for(let o of e){if(Qt(o))return!0;if(f(o)){if(n===null)n=o.length;else if(o.length!==n)return!0;t=!0}else r=!0;if(t&&r)return!0}}return!1}function Z(e){return Qt(et(e))}function mt(e){if(b(e)||g(e))return mt(e.values);a(f(e),"The `isNested` function only works on arrays, Series, and DataFrames!");for(let t=0;t<e.length;t++)if(f(e[t]))return!0;return!1}var lt="You must pass a natural number or a one-dimensional array of natural numbers into the `ndarray` function!";function z(e){a(!h(e),lt),f(e)||(e=[e]),a(!mt(e),lt),a(e.length>0,lt);let t=e[0];if(typeof t=="bigint"&&(t=Number(t)),a(p(t),lt),a(t>=0,lt),a(Math.floor(t)===t,lt),a(t!==1/0,"We can't create an array containing an infinite number of values!"),e.length===1){let r=[];for(let n=0;n<t;n++)r.push(void 0);return r}else{let r=[];for(let n=0;n<t;n++)r.push(z(e.slice(1)));return r}}var Zt=class e{static from(t){return new e(t.a,t.b)}a=0;b=0;step=0;constructor(t,r,n){this.a=t,this.b=r,this.step=n??1}get length(){return Math.abs((Math.max(this.a,this.b)-Math.min(this.a,this.b))/this.step)}get pairIterator(){let t=this[Symbol.iterator]();function*r(){let n=0;for(let o of t)yield[o,n],n++}return r()}[Symbol.iterator](){let t=typeof this.a=="bigint"||typeof this.b=="bigint"||typeof this.step=="bigint",r=t?BigInt(this.a):this.a,n=t?BigInt(this.b):this.b,o=t?BigInt(this.step):this.step;(r<=n&&o<0||r>n&&o>0)&&(o*=t?BigInt(-1):-1);function*i(){if(r<=n)for(let m=r;m<n;m+=o)yield m;else for(let m=r;m>n;m+=o)yield m}return i()}drop(t){return new e(this.a+t*this.step,this.b)}every(t){for(let r of this.pairIterator)if(!t(...r))return!1;return!0}filter(t){let r=[];for(let n of this.pairIterator)t(...n)&&r.push(n[0]);return r}find(t){for(let r of this.pairIterator)if(t(...r))return r[0]}flatMap(){throw new Error("The `RangeIterator.flatMap` method has no implementation!")}forEach(t){for(let r of this.pairIterator)t(...r)}map(t){let r=[];for(let n of this.pairIterator)r.push(t(...n));return r}reduce(t,r){for(let n of this.pairIterator)r=t(n[0],r,n[1]);return r}some(t){for(let r of this.pairIterator)if(t(...r))return!0;return!1}take(t){return new e(this.a,this.a+t*this.step)}toArray(){let t=[];for(let r of this)t.push(r);return t}};function D(e,t,r=1){return a(!h(e)&&!h(t)&&!h(r),"You must pass two numbers and optionally a step value to the `range` function!"),a(p(e)&&p(t)&&p(r),"You must pass two numbers and optionally a step value to the `range` function!"),a(r!==0,"The step value must be greater than 0! (NOTE: The step value is a magnitude; it does not indicate direction.)"),new Zt(e,t,r)}function vt(e){let t="abcdefg1234567890",r="";for(;r.length<e;)r+=t[Math.floor(Math.random()*t.length)];return r}var Vr=vt(256),Gr=vt(256),Wr=vt(256),Hr=vt(256),Xr=vt(256);function B(e){if(b(e)||g(e))return B(e.values);a(f(e),"The `set` function only works on arrays, Series, and DataFrames!");let t=[],r={};return N(E(e),n=>{let o=typeof n=="object"&&n===null?Vr:h(n)?Gr:_(n)?n.toString():typeof n=="symbol"?n.toString()+" - "+Xr:n===1/0?Wr:n===-1/0?Hr:typeof n=="bigint"?n.toString():b(n)?n.toJSONString():g(n)?JSON.stringify(n.toObject()):JSON.stringify(n);typeof r[o]>"u"&&t.push(n),r[o]=!0}),t}function ae(e){if(f(e)){let t=ae(e[0]);return[e.length].concat(t||[])}else return}function v(e){return b(e)||g(e)?v(e.values):(a(f(e),"The `shape` function only works on arrays, Series, and DataFrames!"),ae(e))}function te(e,t,r){if(h(r)&&(r=0),a(r===0||r===1||r==="vertical"||r==="horizontal",'The only valid axis values for use when appending data to a DataFrame are 0, 1, "vertical", and "horizontal". Note that 0 == "horizontal" and 1 == "vertical".'),f(t)){a(!Z(t),"The array of data you're trying to append to this DataFrame is jagged!");let n=v(t);if(n.length===1)if(r===0){let o=e.copy();o._values.push(t);let i=Math.max(e.shape[1],n[0]);for(N(o._values,m=>{for(;m.length<i;)m.push(void 0)});o._index.length<o._values.length;)o._index.push("row"+o._index.length);for(;o._columns.length<i;)o._columns.push("col"+o._columns.length);return o}else{let o=Math.max(e.shape[0],n[0]),i=e.copy();for(D(0,o).forEach(m=>{m>=i._values.length&&i._values.push(z(e.shape[1])),i._values[m].push(t[m])});i._index.length<i._values.length;)i._index.push("row"+i._index.length);for(;i._columns.length<i._values[0].length;)i._columns.push("col"+i._columns.length);return i}else if(n.length===2)if(r===0){let o=Math.max(...d(t,m=>m.length).concat([e.shape[1]])),i=e.copy();for(i._values=d(i._values.concat(t),m=>{for(;m.length<o;)m.push(void 0);return m});i._index.length<i._values.length;)i._index.push("row"+i._index.length);for(;i._columns.length<o;)i._columns.push("col"+i._columns.length);return i}else{let o=Math.max(...d(t,s=>s.length))+e.shape[1],i=Math.max(e.shape[0],n[0]),m=e.copy();for(D(0,i).forEach(s=>{for(s>=m._values.length&&m._values.push(z(e.shape[1])),m._values[s]=m._values[s].concat(t[s]);m._values[s].length<o;)m._values[s].push(void 0)});m._index.length<m._values.length;)m._index.push("row"+m._index.length);for(;m._columns.length<o;)m._columns.push("col"+m._columns.length);return m}else throw new V("Only 1- and 2-dimensional arrays can be appended to a DataFrame!")}else if(g(t)){let n=te(e,t.values,r);return r===0?n.index[n.index.length-1]=n.index.indexOf(t.name)>-1?t.name+" (2)":t.name:n.columns[n.columns.length-1]=n.columns.indexOf(t.name)>-1?t.name+" (2)":t.name,n}else if(b(t))if(r===0){let n=e.copy(),o=B(n._columns.concat(t._columns)).length;for(N(n._values,i=>{for(;i.length<o;)i.push(void 0)}),t.apply(i=>{let m=i.copy(),s=[];N(n._columns,u=>{let l=m._index.indexOf(u);l>-1?(s.push(m._values[l]),m._values.splice(l,1),m._index.splice(l,1)):s.push(void 0)}),n._values.push(s.concat(m._values))},1),n._columns=n._columns.concat(x(t._columns,i=>n._columns.indexOf(i)<0));n._index.length<n._values.length;){let i="row"+n._index.length;n._index.push(i+(e._index.indexOf(i)>-1?" (2)":""))}return n}else{let n=e.copy();return N(n._index,(o,i)=>{let m=t._index.indexOf(o);m>-1?n._values[i]=n._values[i].concat(t._values[m]):n._values[i]=n._values[i].concat(z(t.shape[1]))}),N(t._index,(o,i)=>{n._index.indexOf(o)<0&&(n._index.push(o),n._values.push(z(n._columns.length).concat(t._values[i])))}),n._columns=n._columns.concat(d(t._columns,o=>o+(n._columns.indexOf(o)>-1?" (2)":""))),n}else throw new V("Only 1- or 2-dimensional arrays, Series, and DataFrames can be appended to a DataFrame!")}function ue(e,t,r,n,o){if(o=o||0,a(_(n),"The first parameter to the `apply` method must be a function."),a(o===0||o===1,"The second parameter to the `apply` method (the `axis`) must be 0 or 1."),o===0){let i={},m;if(N(r.columns,(s,u)=>{let l=new t(d(r.values,y=>y[u]));l.name=s,l.index=r.index;let c=n(l,u,r);c instanceof t?i[s]=c.values:i[s]=c,h(m)&&(m=c instanceof t||f(c))}),m){let s=new e(i);return s.index=r.index,s}else{let s=new t(d(r.columns,u=>i[u]));return s.index=r.columns,s}}else if(o===1){let i,m=d(r.values,(s,u)=>{let l=new t(s);l.name=r.index[u],l.index=r.columns;let c=n(l,u,r);return h(i)&&(i=c instanceof t||f(c)),c instanceof t?c.values:c});if(i){let s=new e(m);return s.index=r.index,s.columns=r.columns,s}else{let s=new t(m);return s.index=r.index,s}}}function O(e){return typeof e=="string"}function fe(e,t,r,n,o){let i=s=>s instanceof e,m=s=>s instanceof t;if(h(o))if(i(n)){let s=r.copy(),u=s.shape,l=n.shape;for(let c=0;c<l[1];c++){let y=n.columns[c],S=s.columns.includes(y)?s.columns.indexOf(y):s.columns.length;s.columns.includes(y)||s._columns.push(y);for(let T=0;T<u[0];T++)s._values[T][S]=n._values[T][c]}return s}else{if(m(n))return r.assign(n.name,n.values);if(M(n))return r.assign(new e(n));throw new V("You must pass a DataFrame, Series, or object into the `assign` method!")}else{a(O(n),"If passing two arguments into the `assign` method, then the first argument must be a string name!"),a(f(o)&&!Z(o)&&v(o).length===1,"If passing two arguments into the `assign` method, then the second argument must be a 1-dimensional array!");let s=r.copy();if(s.columns.includes(n)){let u=s.columns.indexOf(n);return s.columns[u]=n,N(s.values,(l,c)=>l[u]=o[c]),s}else return s._columns.push(n),N(s._values,(u,l)=>u.push(o[l])),s}}function le(e,t){if(t.isEmpty)return new e;let r=new e(F(t.values));return r.columns=t.columns.slice(),r.index=t.index.slice(),r}function pe(e,t,r,n,o){h(n)&&(n=[]),h(o)&&(o=[]),(O(n)||p(n))&&(n=[n]),(O(o)||p(o))&&(o=[o]),a(f(n),"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."),a(f(o),"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."),a(v(n).length===1,"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."),a(v(o).length===1,"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings.");let i,m;N(r.index,(u,l)=>{n.indexOf(u)<0&&n.indexOf(l)<0&&(i||(i=[]),i.push(u))}),N(r.columns,(u,l)=>{o.indexOf(u)<0&&o.indexOf(l)<0&&(m||(m=[]),m.push(u))});let s=r.get(i,m);if(s instanceof t){let u=new e;u=u.assign(s),r.index.indexOf(s.name)>-1&&(u=u.transpose()),s=u}return s}function Ft(e){return p(e)&&(e>=0?Math.floor(e)===e:Math.ceil(e)===e)}function G(e){return Ft(e)&&e>=0}function ce(e,t,r,n,o,i){n=n||0,a(n===0||n===1,"The first parameter of the `dropMissing` method (the `axis`) must be 0 or 1."),i=i||0,a(G(i),"The third parameter of the `dropMissing` method (the `threshold`) should be a whole number (meaning that data should be dropped if it contains more than `threshold` null values)."),o=i>0?"none":o||"any",a(o==="any"||o==="all"||o==="none","The second parameter of the `dropMissing` method (the `condition` parameter, which indicates the condition under which data should be dropped) should be 'any' or 'all' (meaning that if 'any' of the data contains null values, then it should be dropped; or that if 'all' of the data contains null values, then it should be dropped).");function m(l){if(i>0){let c=0;for(let y=0;y<l.length;y++){let S=l[y];if(h(S)&&c++,c>=i)return[]}}else if(o==="any")for(let c=0;c<l.length;c++){let y=l[c];if(h(y))return[]}else if(o==="all"){for(let c=0;c<l.length;c++){let y=l[c];if(!h(y))return l}return[]}return l}let s=r.copy(),u=Math.random().toString();if(n===0){s=s.assign(u,s.index);let l=x(d(s.values,m),y=>y.length>0);if(v(l).length<2)return new e;s.values=l;let c=s.get(null,u);if(h(c))return new e;O(c)&&(c=[c]),c instanceof t&&(c=c.values),s.index=c,s=s.drop(null,u)}else if(n===1){let l={};if(N(s.columns,(y,S)=>{let T=d(s.values,k=>k[S]),j=m(T);j.length>0&&(l[y]=j)}),Object.keys(l).length+Object.getOwnPropertySymbols(l).length===0)return new e;let c=new e(l);return c.index=s.index,c}return s}function St(e){if(b(e)||g(e))return e.dropNaN(...Object.values(arguments).slice(1));a(f(e),"The `dropNaN` function only works on arrays, Series, and DataFrames!");let t=[];return N(e,r=>{try{return t.push(St(r))}catch{if(p(r))return t.push(r)}}),t}function he(e,t,r,n,o){r=r||0,a(r===0||r===1,"The first parameter of the `dropNaN` method (the `axis`) must be 0 or 1."),o=o||0,a(G(o),"The third parameter of the `dropNaN` method (the `threshold`) should be a whole number (meaning that data should be dropped if it contains more than `threshold` NaN values)."),n=o>0?"none":n||"any",a(n==="any"||n==="all"||n==="none","The second parameter of the `dropNaN` method (the `condition` parameter, which indicates the condition under which data should be dropped) should be 'any' or 'all' (meaning that if 'any' of the data contains NaN values, then it should be dropped; or that if 'all' of the data contains NaN values, then it should be dropped).");function i(s){let u=St(s);return o>0?s.length-u.length<o:n==="any"?u.length===s.length:n==="all"?u.length>0:!0}let m=t.copy();if(r===0){let s=x(m.index,u=>{let l=m.get(u,null).values;return i(l)});return s.length>0?m.get(s,null):new e}else if(r===1){let s=x(m.columns,u=>{let l=m.get(null,u).values;return i(l)});return s.length>0?m.get(null,s):new e}return m}function de(e){let t={};return N(E(e),(r,n)=>{t[r]=n}),t}function pt(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e)).sort((t,r)=>e[t]-e[r])}function ge(e,t,r,n,o){a(_(n),"The `filter` method takes a single parameter: a function that is used to filter the values."),h(o)&&(o=0),a(o===0||o===1,"The `axis` parameter to the `filter` method must be 0 or 1.");let i=r.copy();if(i.isEmpty)return i;let m=de(i.index),s=de(i.columns);if(o===0){let u=0,l=x(i.values,(c,y)=>{let S=new t(c);S.name=r.index[y],S.index=r.columns;let T=n(S,y,r);return T?u++:delete m[i.index[y]],T});if(u===0)return new e;if(u===1){let c=new t(l[0]);return c.name=pt(m)[0],c.index=pt(s),c}i.values=l,i.index=pt(m)}else if(o===1){i=i.transpose();let u=0,l=x(i.values,(c,y)=>{let S=new t(c);S.name=r.columns[y],S.index=r.index;let T=n(S,y,r);return T?u++:delete s[i.index[y]],T});if(u===0)return new e;if(u===1){let c=new t(l[0]);return c.name=pt(s)[0],c.index=pt(m),c}i.values=l,i.index=pt(s),i=i.transpose()}return i}function ye(e,t,r){(O(t)||p(t))&&(t=[t]),(O(r)||p(r))&&(r=[r]);for(let o in t)typeof t[o]=="bigint"&&(t[o]=Number(t[o]));for(let o in r)typeof r[o]=="bigint"&&(r[o]=Number(r[o]));let n=B(d((t||[]).concat(r||[]),o=>typeof o));return a(n.length<=2,"Only whole numbers and/or strings are allowed in `get` arrays!"),n.length===1&&a(n[0]==="string"||n[0]==="number","Only whole numbers and/or strings are allowed in `get` arrays!"),n.length===2&&(a(n.indexOf("string")>-1,"Only whole numbers and/or strings are allowed in `get` arrays!"),a(n.indexOf("number")>-1,"Only whole numbers and/or strings are allowed in `get` arrays!")),h(t)||(t=d(t,o=>{if(O(o))return a(e.index.indexOf(o)>-1,`Row "${o}" does not exist!`),o;if(p(o))return a(o>=0,`Index ${o} is out of bounds!`),a(Math.floor(o)===o,"Row numbers must be integers!"),a(o<e.index.length,`Index ${o} is out of bounds!`),e.index[o]})),h(r)||(r=d(r,o=>{if(O(o))return a(e.columns.indexOf(o)>-1,`Column "${o}" does not exist!`),o;if(p(o))return a(o>=0,`Column ${o} is out of bounds!`),a(Math.floor(o)===o,"Column numbers must be integers!"),a(o<e.columns.length,`Column ${o} is out of bounds!`),e.columns[o]})),e.getSubsetByNames(t,r)}function Qr(e,t){try{return e<t?-1:e>t?1:0}catch{return e=typeof e=="object"&&e!==null?JSON.stringify(e):e.toString(),t=typeof t=="object"&&t!==null?JSON.stringify(t):t.toString(),e<t?-1:e>t?1:0}}function L(e,t){if(h(t)&&(t=Qr),b(e)||g(e))return e.sort(...Object.values(arguments).slice(1));a(f(e),"The `sort` function only works on arrays, Series, and DataFrames!"),a(_(t),"The second parameter of the `sort` function must be a comparison function!");let r=e.slice();return r.sort(t),r}function Zr(e){let t=e.toLowerCase(),r="";for(let o=0;o<t.length;o++){let i=t[o];i.match(/[a-z0-9]/g)?r+=i:r+=" "}let n=x(r.split(" "),o=>o.length>0);return n[0]+d(n.slice(1),o=>o[0].toUpperCase()+o.substring(1)).join("")}function ee(e,t,r){h(r)?r=t.columns:O(r)&&(r=[r]);let n={};N(r,i=>{a(O(i),"You must pass either a string or a one-dimensional array of strings into the `getDummies` (AKA `oneHotEncode`) method!");let m=t.columns.indexOf(i);a(m>-1,`The given DataFrame does not have a column called "${i}"!`);let s=d(t.values,l=>l[m]),u=L(B(s));N(s,l=>{N(u,c=>{let y=i+"_"+Zr(c.toString());n[y]||(n[y]=[]),l===c?n[y].push(1):n[y].push(0)})})});let o=new e(n);return o.index=t.index,o}function be(e,t,r){let n=e.shape;h(t)&&(t=D(0,n[0]).toArray()),h(r)&&(r=D(0,n[1]).toArray()),p(t)&&(t=[t]),p(r)&&(r=[r]),a(f(t)&&f(r),"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."),a(v(t).length===1&&v(r).length===1,"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."),a(t.length>0,"The `rowIndices` array must contain at least one index."),a(r.length>0,"The `colIndices` array must contain at least one index."),N(t,m=>{a(G(m),"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."),a(m<e.index.length,`The row index ${m} is out of bounds.`)}),N(r,m=>{a(G(m),"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."),a(m<e.columns.length,`The column index ${m} is out of bounds.`)});let o=d(t,m=>e.index[m]),i=d(r,m=>e.columns[m]);return e.getSubsetByNames(o,i)}function Ne(e,t,r,n,o){h(n)&&(n=r.index),h(o)&&(o=r.columns),O(n)&&(n=[n]),O(o)&&(o=[o]),a(f(n)&&f(o),"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."),a(v(n).length===1&&v(o).length===1,"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."),a(n.length>0,"The `rows` array must contain at least one row name."),a(o.length>0,"The `cols` array must contain at least one column name."),N(n,s=>{a(O(s),"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."),a(r.index.indexOf(s)>-1,`The row name "${s}" does not exist in the list of rows.`)}),N(o,s=>{a(O(s),"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."),a(r.columns.indexOf(s)>-1,`The column name "${s}" does not exist in the list of columns.`)});let i=d(n,s=>d(o,u=>r.values[r.index.indexOf(s)][r.columns.indexOf(u)]));if(n.length===1&&o.length===1)return i[0][0];if(n.length===1){let s=new t(i[0]);return s.name=n[0],s.index=o,s}if(o.length===1){let s=new t(d(i,u=>u[0]));return s.name=o[0],s.index=n,s}let m=new e(i);return m.columns=o,m.index=n,m}function ve(e,t,r){function n(S,T){return O(S)&&S.length>T?S.substring(0,T-3)+"...":S}if(r.isEmpty)return console.table({}),console.log("Shape:",[0,0],`
`),r;let o=typeof window>"u"?20:10,i=Math.floor(o/2),m=4,s=Math.floor(m/2),u=o>r.index.length?null:D(0,i).toArray().concat(D(r.index.length-i,r.index.length).toArray()),l=m>r.columns.length?null:D(0,s).toArray().concat(D(r.columns.length-s,r.columns.length).toArray()),c=r.get(u,l);c instanceof t&&(r.shape[0]===1?(c=new e([c.values]),c.index=r.index,c.columns=new t(r.columns).get(l).values):r.shape[1]===1&&(c=new e([c.values]).transpose(),c.index=new t(r.index).get(u).values,c.columns=r.columns)),o<=r.index.length&&(c._index.splice(i,0,"..."),c._values.splice(i,0,D(0,c.columns.length).map(()=>"..."))),m<=r.columns.length&&(c._columns.splice(s,0,"..."),c._values=d(c._values,S=>(S.splice(s,0,"..."),S)));let y=28;return c instanceof t?(c.values=d(c.values,S=>n(S,y)),c.name=n(c.name,y),c.index=d(c.index,S=>n(S,y))):(c.values=d(c.values,S=>d(S,T=>n(T,y))),c.columns=d(c.columns,S=>n(S,y)),c.index=d(c.index,S=>n(S,y))),console.table(c.toDetailedObject()),console.log("Shape:",r.shape,`
`),r}function Se(e,t){let r=t?e:e.copy(),n=(r.index.length-1).toString().length;return r.index=D(0,e.shape[0]).map(o=>"row"+o.toString().padStart(n,"0")),r}function rt(e,t){if(b(e)||g(e))return rt(e.values,t);a(f(e),"The `product` function only works on arrays, Series, and DataFrames!");try{if(e.length===0)return NaN;let r=E(e),n=!1,o=1;for(let i of r){if(!p(i))if(t)i=1;else return NaN;typeof i=="bigint"&&(n=!0,i=Number(i)),o*=i}if(n)try{return BigInt(o)}catch{}return o}catch{return NaN}}function we(e){return Ft(e)&&e>0}function nt(e,t){if(b(e)||g(e))return nt(e.values,t);if(a(f(e),"The first argument passed into the `reshape` function must be an array!"),p(t)&&(t=[t]),a(f(t),"The second argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"),a(v(t).length===1,"The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"),t=d(t,i=>(typeof i=="bigint"&&(i=Number(i)),a(we(i),"The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"),Number(i))),t.length===0)return E(e);let r=E(e);if(t.length===1&&t[0]===r.length)return r;a(rt(t)===r.length,"The new shape doesn't match the number of values available in `x` (the first argument passed into the `reshape` function)!");let n=[],o=Math.floor(r.length/t[0]);for(let i=0;i<t[0];i++){let m=r.slice(i*o,(i+1)*o);n.push(nt(m,t.slice(1)))}return n}var _e=Math.pow(2,64),A=[];re(Math.floor(Math.random()*_e));function tn(e,t){e=J(e);function r(){e+=J("0x9e3779b97f4a7c15");let o=F(e);return o=(o^o>>BigInt(30))*J("0xbf58476d1ce4e5b9"),o=(o^o>>BigInt(27))*J("0x94d049bb133111eb"),o^o>>BigInt(31)}let n=[];for(let o=0;o<t;o++)n.push(r());return n}function J(e){return BigInt.asUintN(64,BigInt(e))}function Oe(e,t){return e=J(e),t=BigInt(t),J(J(e<<t)|J(e>>J(BigInt(64)-t)))}function re(e){if(typeof e=="bigint"&&(e=Number(e)),h(e))return F(A);{a(p(e),"If passing a value into the `seed` function, then that value must be an integer!");let t=tn(Math.floor(e),4);A[0]=t[0],A[1]=t[1],A[2]=t[2],A[3]=t[3]}}function Te(){let e=J(Oe(A[0]+A[3],23)+A[0]),t=J(A[1]<<BigInt(17));return A[2]=J(A[2]^A[0]),A[3]=J(A[3]^A[1]),A[1]=J(A[1]^A[2]),A[0]=J(A[0]^A[3]),A[2]=J(A[2]^t),A[3]=Oe(A[3],45),Math.floor(Number(e))/_e}function W(e){return h(e)?Te():(f(e)||(e=[e]),nt(d(z(rt(e)),Te),e))}function at(e){if(b(e)||g(e))return e.shuffle(...Object.values(arguments).slice(1));a(f(e),"The `shuffle` function only works on arrays, Series, and DataFrames!");let t=[],r=e.slice();for(let n=0;n<e.length;n++){let o=Math.floor(W()*r.length);t.push(r.splice(o,1)[0])}return t}function De(e,t){return h(t)&&(t=0),a(t===0||t===1,"The `axis` parameter to the `shuffle` must be 0, 1, or undefined."),e.get(t===0?at(e.index):null,t===1?at(e.columns):null)}function tt(e){return typeof e=="boolean"}function Ie(e,t,r){return _(t)?en(e,t,r):rn(e,t,r)}function en(e,t,r){if(r=h(r)?0:r,a(_(t),"When sorting a DataFrame using a function, the first argument to the `sort` method must be a function!"),a(p(r),"When sorting a DataFrame using a function, the second argument to the `sort` method must be null, undefined, 0, or 1 to indicate the axis along which the data should be sorted! An axis of 0 means that the rows will be sorted relative to each other, whereas an axis of 1 means that the columns will be sorted relative to each other."),r===0){let n=L(e.index,(o,i)=>t(e.get(o,null),e.get(i,null)));return e.get(n,null)}else{let n=L(e.columns,(o,i)=>t(e.get(null,o),e.get(null,i)));return e.get(null,n)}}function rn(e,t,r){let n=e.copy(),o=W().toString();n=n.assign(o,n.index),h(t)&&(t=[o],r=[!0]),(p(t)||O(t))&&(t=[t],(tt(r)||O(r))&&(r=[r])),a(f(t),"The first parameter of the `sort` method must be (1) a string or index representing a column name or index, respectively; (2) a 1-dimensional array of strings and/or indices; or (3) null."),a(v(t).length===1,"The first parameter of the `sort` method must be (1) a string or index representing a column name or index, respectively; (2) a 1-dimensional array of strings and/or indices; or (3) null."),h(r)&&(r=D(0,t.length).map(()=>!0)),a(f(r),"The second parameter of the `sort` method must be (1) a string or boolean representing the sort direction ('ascending' / 'descending', or true / false); (2) a 1-dimensional array of strings and/or booleans; or (3) null."),a(v(r).length===1,"The second parameter of the `sort` method must be (1) a string or boolean representing the sort direction ('ascending' / 'descending', or true / false); (2) a 1-dimensional array of strings and/or booleans; or (3) null."),a(t.length===r.length,"The arrays passed into the `sort` method must be equal in length."),t=d(t,m=>{if(a(O(m)||p(m),"Column references can either be column names (as strings) or column indices (as whole numbers)."),O(m)){let s=n.columns.indexOf(m);return a(s>-1,`The column "${m}" does not exist!`),s}if(p(m))return a(G(m),"Column indices must be whole numbers!"),a(m<n.columns.length,`The index ${m} is out of bounds!`),m}),r=d(r,m=>{if(a(O(m)||tt(m),"Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."),O(m)){let s=m.trim().toLowerCase();return a(s==="ascending"||s==="descending","Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."),s==="ascending"}if(tt(m))return m}),n.values=L(n.values,(m,s)=>{let u=0;for(;m[t[u]]===s[t[u]]&&u<t.length;)u++;let l=r[u];if(m[t[u]]===s[t[u]])return 0;if(m[t[u]]<s[t[u]])return l?-1:1;if(m[t[u]]>s[t[u]])return l?1:-1});let i=n.columns.indexOf(o);return n.index=d(n.values,m=>m[i]),n=n.dropColumns(o),n}function Ae(e,t){h(t)?t=0:a(t===0||t===1,"The axis parameter of the `toDetailedObject` method must be undefined, 0, or 1. An axis of 0 indicates that the returned object should be organized first by rows and then by columns. An axis of 1 indicates that the returned object should be organized first by columns and then by rows.");let r={};return t===0?N(e.index,(n,o)=>{let i={};N(e.columns,(m,s)=>{i[m]=e.values[o][s]}),r[n]=i}):N(e.columns,(n,o)=>{let i={};N(e.index,(m,s)=>{i[m]=e.values[s][o]}),r[n]=i}),r}function xt(e,t){return JSON.stringify(e.toObject(t))}async function Fe(e,t){return JSON.parse(xt(e,t))}function xe(e){let t={};return N(e.columns,r=>{t[r]=e.get(r).values}),t}function q(e){if(b(e)||g(e)){let r=e.copy();return r.values=q(r.values),r.index=q(r.index),r}a(f(e),"The `reverse` function only works on arrays, Series, and DataFrames!");let t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function R(e){if(b(e)||g(e))return e.transpose();a(f(e),"The `transpose` function only works on arrays, Series, and DataFrames!");let t=v(e);if(a(t.length<=2,"I'm not smart enough to know how to transpose arrays that have more than 2 dimensions. Sorry for the inconvenience! Please only pass 1- or 2-dimensional arrays into the `transpose` function!"),t.length===1)return q(e);if(t.length===2){let r=z(q(t));for(let n=0;n<t[0];n++)for(let o=0;o<t[1];o++)r[o][n]=e[n][o];return r}}function ne(e,t,r){if(g(r))return new e(t.values.concat(r.values));if(f(r)){let n=v(r);a(n.length===1&&!mt(n),"Only vectors can be appended to Series!");let o=t.copy();return N(r,(i,m)=>{o._values.push(i),o._index.push("item"+(t.values.length+m))}),o}return ne(t,[r])}function Me(e,t){a(_(t),"The parameter to the `apply` method must be a function.");let r=e.copy();return r._values=d(r._values,(n,o)=>t(n,o)),r}function je(e){let t=e.copy(),r=[];return t._values=x(t.values,(n,o)=>h(n)?!1:(r.push(t.index[o]),!0)),t._index=r,t}function Ee(e,t){let r=[],n=[];N(t.values,(i,m)=>{p(i)&&(n.push(i),r.push(t.index[m]))});let o=new e(n);return o.name=t.name,o.index=r,o}function Be(e,t,r){let n=t.copy(),o=F(n.index),i=[],m=x(n.values,(s,u)=>{let l=r(s,u,n.values);return l||i.push(n.index[u]),l});return N(i,s=>{o.splice(o.indexOf(s),1)}),m.length===0?(n=new e,n.name=t.name,n):(n.values=m,n.index=o,n)}function Ue(e,t){(O(t)||p(t))&&(t=[t]);for(let n in t)typeof t[n]=="bigint"&&(t[n]=Number(t[n]));let r=B(d(t||[],n=>typeof n));return a(r.length<=2,"Only whole numbers and/or strings are allowed in `get` arrays!"),r.length===1&&a(r[0]==="string"||r[0]==="number","Only whole numbers and/or strings are allowed in `get` arrays!"),r.length===2&&(a(r.indexOf("string")>-1,"Only whole numbers and/or strings are allowed in `get` arrays!"),a(r.indexOf("number")>-1,"Only whole numbers and/or strings are allowed in `get` arrays!")),h(t)||(t=d(t,n=>{if(typeof n=="string")return a(e.index.indexOf(n)>-1,`Index "${n}" does not exist!`),n;if(typeof n=="number")return a(n>=0,`Index ${n} is out of bounds!`),a(Math.floor(n)===n,"Indices must be integers!"),a(n<e.index.length,`Index ${n} is out of bounds!`),e.index[n]})),e.getSubsetByNames(t)}function Pe(e,t){let r=e.shape;h(t)&&(t=D(0,r[0]).toArray()),a(f(t),"The `indices` array must be 1-dimensional array of whole numbers."),a(v(t).length===1,"The `indices` array must be a 1-dimensional array of whole numbers."),a(t.length>0,"The `indices` array must contain at least one index."),N(t,o=>{a(G(o),"The `indices` array must be a 1-dimensional array of whole numbers."),a(o<e.index.length,`The row index ${o} is out of bounds.`)});let n=d(t,o=>e.index[o]);return e.getSubsetByNames(n)}function ke(e,t,r){h(r)&&(r=t.index),a(f(r),"The `indices` array must be a 1-dimensional array of strings."),a(v(r).length===1,"The `indices` array must be a 1-dimensional array of strings."),a(r.length>0,"The `indices` array must contain at least one index name."),N(r,i=>{a(O(i),"The `indices` array must contain only strings."),a(t.index.indexOf(i)>-1,`The name "${i}" does not exist in the index.`)});let n=d(r,i=>t.values[t.index.indexOf(i)]);if(n.length===1)return n[0];let o=new e(n);return o.index=r,o.name=t.name,o}function ze(e){let t=e.copy(),r=typeof window>"u"?20:10;if(t.index.length>r){t=t.get(D(0,r/2).toArray().concat(D(t.index.length-r/2,t.index.length).toArray()));let o=F(t.index);o.splice(Math.floor(o.length/2),0,"..."),t.values.push("..."),t.index.push("..."),t=t.get(o)}let n={};return N(t.values,(o,i)=>{let m={};m[t.name]=o,n[t.index[i]]=m}),console.table(n),console.log("Shape:",e.shape,`
`),e}function Ce(e){let t=e.copy();return t.get(at(t.index))}function Je(e,t,r){r=r||((u,l)=>u<l?-1:1),a(h(r)||_(r),"You must pass undefined, null, or a comparison function as the second argument to the `sort` method!");let n=R([t.values,t.index]),o=L(n,(u,l)=>r(u[0],l[0])),i=[],m=[];N(o,u=>{i.push(u[0]),m.push(u[1])});let s=new e;return s._values=i,s._index=m,s.name=t.name,s}function Ye(e,t){let r=R([t.values,t.index]);r=R(L(r,(o,i)=>{if(o[1]===i[1])return 0;if(o[1]<i[1])return-1;if(o[1]>i[1])return 1}));let n=new e(r[0]);return n.index=r[1],n.name=t.name,n}function Re(e){let t={};return t[e.name]={},N(e.index,(r,n)=>{t[e.name][r]=e.values[n]}),t}var $e=Symbol.for("@jrc03c/js-math-tools/series");function Ke(e){class t{static[Symbol.hasInstance](n){try{return!!n._symbol&&n._symbol===$e}catch{return!1}}constructor(n){if(this.name="data",Object.defineProperty(this,"_symbol",{configurable:!1,enumerable:!1,writable:!1,value:$e}),Object.defineProperty(this,"_values",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"values",{configurable:!0,enumerable:!0,get(){return this._values},set(o){a(f(o),"The new values must be a 1-dimensional array!");let i=v(o);if(a(i.length===1,"The new array of values must be 1-dimensional!"),i[0]<this._index.length)this._index=this._index.slice(0,i[0]);else if(i[0]>this._index.length){let m=(o.length-1).toString().length;this._index=this._index.concat(D(this._index.length,i[0]).map(s=>"item"+s.toString().padStart(m,"0")))}this._values=o}}),Object.defineProperty(this,"_index",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"index",{configurable:!0,enumerable:!0,get(){return this._index},set(o){a(f(o),"The new index must be a 1-dimensional array of strings!"),a(o.length===this.shape[0],"The new index must be the same length as the old index!"),a(v(o).length===1,"The new index must be a 1-dimensional array of strings!"),N(o,i=>{a(O(i),"All of the row names must be strings!")}),this._index=o}}),n){if(n instanceof t)this.name=n.name,this.values=F(n.values),this.index=F(n.index);else if(f(n)){let o=v(n);a(o.length===1,"When passing an array into the constructor of a Series, the array must be 1-dimensional!"),this.values=n}else if(n instanceof Object){let o=d(Object.keys(n).concat(Object.getOwnPropertySymbols(n)),s=>s.toString());a(o.length===1,"When passing an object into the constructor of a Series, the object must have only 1 key-value pair, where the key is the name of the data and the value is the 1-dimensional array of values!");let i=o[0],m=n[i];a(v(m).length===1,"When passing an object into the constructor of a Series, the object must have only 1 key-value pair, where the key is the name of the data and the value is the 1-dimensional array of values!"),this.name=i,this.values=m.slice()}}}get shape(){return v(this.values)}get length(){return this.shape[0]}get isEmpty(){return x(this.values,n=>!h(n)).length===0}clear(){let n=this.copy();return N(n.values,(o,i)=>{n.values[i]=void 0}),n}get(n){return Ue(this,n)}getSubsetByNames(n){return ke(t,this,n)}getSubsetByIndices(n){return Pe(this,n)}loc(n){return this.getSubsetByNames(n)}iloc(n){return this.getSubsetByIndices(n)}reverse(){let n=new t(q(this.values));return n.index=q(this.index),n.name=this.name,n}resetIndex(){let n=this.copy(),o=(n.index.length-1).toString().length;return n.index=D(0,this.shape[0]).map(i=>"item"+i.toString().padStart(o,"0")),n}copy(){let n=new t;return n._values=F(this.values),n._index=F(this.index),n.name=this.name,n}append(n){return ne(t,this,n)}apply(n){return Me(this,n)}concat(n){return this.append(n)}dropMissing(n,o){return je(this,n,o)}dropNaN(){return Ee(t,this)}toObject(){return Re(this)}print(){return ze(this)}shuffle(){return Ce(this)}sort(n){return Je(t,this,n)}sortByIndex(){return Ye(t,this)}filter(n){return Be(t,this,n)}toDataFrame(){let n=new e(R([this.values]));return n.columns=[this.name],n.index=this.index,n}transpose(){let n=this.copy();return n.values=q(n.values),n.index=q(n.index),n}getDummies(){return this.toDataFrame().getDummies()}oneHotEncode(){return this.getDummies()}}return t}var Le=Symbol.for("@jrc03c/js-math-tools/dataframe");function Mt(e){let t="abcdefghijklmnopqrstuvwxyz1234567890",r="";for(let n=0;n<e;n++)r+=t[Math.floor(W()*t.length)];return r}var Y=class e{static[Symbol.hasInstance](t){try{return!!t._symbol&&t._symbol===Le}catch{return!1}}constructor(t){if(Object.defineProperty(this,"_symbol",{configurable:!1,enumerable:!1,writable:!1,value:Le}),Object.defineProperty(this,"_values",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"values",{configurable:!0,enumerable:!0,get(){return this._values.length===0||!h(this._values[0])&&this._values[0].length===0?[[]]:this._values},set(r){a(f(r),"The new values must be a 2-dimensional array!");let n=v(r);if(a(n.length===2,"The new array of values must be 2-dimensional!"),n[0]<this._index.length)this._index=this._index.slice(0,n[0]);else if(n[0]>this._index.length){let o=(n[0]-1).toString().length;this._index=this._index.concat(D(this._index.length,n[0]).map(i=>"row"+i.toString().padStart(o,"0")))}if(n[1]<this._columns.length)this._columns=this._columns.slice(0,n[1]);else if(n[1]>this._columns.length){let o=(n[1]-1).toString().length;this._columns=this._columns.concat(D(this._columns.length,n[1]).map(i=>"col"+i.toString().padStart(o,"0")))}this._values=r}}),Object.defineProperty(this,"_columns",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"columns",{configurable:!0,enumerable:!0,get(){return this._columns},set(r){a(f(r),"The new columns list must be a 1-dimensional array of strings!"),a(this.isEmpty||r.length===this.shape[1],"The new columns list must be the same length as the old columns list!"),a(v(r).length===1,"The new columns list must be a 1-dimensional array of strings!"),r=d(r,o=>(typeof o!="string"&&(o=JSON.stringify(o)||o.toString()),o.trim().length===0?"untitled_"+Mt(8):o.trim()));let n=(()=>{let o=st(r),i={};return N(o.values,m=>{i[m]=o.get(m)}),i})();r=d(r,o=>n[o]>1?o+"_"+Mt(8):o),this._columns=r}}),Object.defineProperty(this,"_index",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"index",{configurable:!0,enumerable:!0,get(){return this._index},set(r){a(f(r),"The new index must be a 1-dimensional array of strings!"),a(this.isEmpty||r.length===this.shape[0],"The new index must be the same length as the old index!"),a(v(r).length===1,"The new index must be a 1-dimensional array of strings!"),r=d(r,o=>(typeof o!="string"&&(o=JSON.stringify(o)||o.toString()),o.trim().length===0?"untitled_"+Mt(8):o.trim()));let n=(()=>{let o=st(r),i={};return N(o.values,m=>{i[m]=o.get(m)}),i})();r=d(r,o=>n[o]>1?o+"_"+Mt(8):o),this._index=r}}),a(h(t)||M(t)||f(t),"The `data` passed into the constructor of a DataFrame must be either (1) an object where the key-value pairs are (respectively) column names and 1-dimensional arrays of values, or (2) a 2-dimensional array of values."),t)if(t instanceof e)this.values=F(t.values),this.columns=F(t.columns),this.index=F(t.index);else if(f(t)){let r=v(t);a(r.length===2,"The `data` array passed into the constructor of a DataFrame must be 2-dimensional!"),a(!Z(t),"The 2-dimensional array passed into the constructor of a DataFrame must not contain sub-arrays (i.e., rows) of different lengths!"),this.values=t}else{this._columns=d(Object.keys(t).concat(Object.getOwnPropertySymbols(t)),s=>s.toString());let r=[],n=null,o=null;N(this._columns,s=>{h(o)&&(n=s,o=t[s].length),a(t[s].length===o,`The object passed into the DataFrame constructor contains arrays of different lengths! The key "${n}" points to an array containing ${o} items, and the key "${s}" points to an array containing ${t[s].length} items.`),o=t[s].length;let u=t[s];r.push(u)}),this._values=R(r);let i=v(this.values),m=(i[0]-1).toString().length;this._index=D(0,i[0]).map(s=>"row"+s.toString().padStart(m,"0"))}}get shape(){return v(this.values)}get length(){return this.shape[0]}get width(){return this.shape[1]}get rows(){return this.index}set rows(t){this.index=t}get isEmpty(){return this.values.length===0||this.values.every(t=>t.length===0)}clear(){let t=new e(z(this.shape));return t.columns=this.columns.slice(),t.index=this.index.slice(),t}get(t,r){if(arguments.length===0)return this;if(arguments.length===1)try{return this.get(null,t)}catch{return this.get(t,null)}return ye(this,t,r)}getSubsetByNames(t,r){return Ne(e,U,this,t,r)}getSubsetByIndices(t,r){return be(this,t,r)}getDummies(t){return ee(e,this,t)}oneHotEncode(t){return ee(e,this,t)}transpose(){let t=new e(R(this.values));return t.columns=this.index.slice(),t.index=this.columns.slice(),t}get T(){return this.transpose()}resetIndex(t){return Se(this,t)}copy(){return le(e,this)}assign(t,r){return fe(e,U,this,t,r)}apply(t,r){return ue(e,U,this,t,r)}dropMissing(t,r,n){return ce(e,U,this,t,r,n)}dropNaN(t,r,n){return he(e,this,t,r,n)}drop(t,r){return pe(e,U,this,t,r)}dropColumns(t){return this.drop(null,t)}dropRows(t){return this.drop(t,null)}toDetailedObject(t){return Ae(this,t)}toObject(){return xe(this)}toJSONString(t){return xt(this,t)}saveAsJSON(t,r){return Fe(this,t,r)}print(){return ve(e,U,this)}sort(t,r){return Ie(this,t,r)}sortByIndex(){return this.sort()}filter(t,r){return ge(e,U,this,t,r)}shuffle(t){return De(this,t)}append(t,r){return te(this,t,r)}concat(t,r){return this.append(t,r)}join(t,r){return this.append(t,r)}toString(){return JSON.stringify(this)}},U=Ke(Y);function ot(e,t){return I(e,{shouldDropNaNs:t}).max}function w(e){return a(_(e),"You must pass a function into the `vectorize` function!"),function t(){let r,n,o=[],i=[],m=d(x(Object.keys(arguments),s=>{let u=arguments[s];return f(u)?!0:g(u)?(r=!0,o.push(u),!0):b(u)?(n=!0,i.push(u),!0):!1}),s=>arguments[s]);if(N(m.slice(0,-1),(s,u)=>{a(P(f(s)?v(s):s.shape,f(m[u+1])?v(m[u+1]):m[u+1].shape),`When passing multiple arrays into the \`${e.name}\` function, all of the arrays must have the same shape!`)}),m.length>0){let s=ot(d(m,l=>l.length?l.length:l.values.length)),u=D(0,s).map(l=>{let c=d(Object.keys(arguments),y=>f(arguments[y])?arguments[y][l]:g(arguments[y])||b(arguments[y])?arguments[y].values[l]:arguments[y]);return t(...c)});if(n)try{if(i.length===1&&P(v(i[0]),v(u))){let l=new Y(u);return l.index=i[0].index.slice(),l.columns=i[0].columns.slice(),l}else return new Y(u)}catch{return u}if(r)try{if(o.length===1&&o[0].length===u.length){let l=new U(u);return l.name=o[0].name,l.index=o[0].index.slice(),l}else return new U(u)}catch{return u}return u}else return e(...arguments)}}function nn(e){try{return p(e)?typeof e=="bigint"?e<0?-e:e:Math.abs(e):NaN}catch{return NaN}}var ct=w(nn);function on(){try{let e=0,t=!1,r=Object.values(arguments);for(let n of r){if(!p(n))return NaN;typeof n=="bigint"&&(t=!0,n=Number(n)),e+=n}if(t)try{return BigInt(e)}catch{}return e}catch{return NaN}}var ut=w(on);function sn(e,t){try{return t(e)}catch{return NaN}}var it=w(sn);function mn(e){try{return p(e)?(typeof e=="bigint"&&(e=Number(e)),Math.acos(e)):NaN}catch{return NaN}}var qe=w(mn);function an(e){try{return p(e)?(typeof e=="bigint"&&(e=Number(e)),Math.asin(e)):NaN}catch{return NaN}}var Ve=w(an);function un(e){try{return p(e)?(typeof e=="bigint"&&(e=Number(e)),Math.atan(e)):NaN}catch{return NaN}}var Ge=w(un);function jt(e,t){if(b(e)){let r=jt(e.values,t);return[e.index[r[0]],e.columns[r[1]]]}if(g(e)){let r=jt(e.values,t);return e.index[r]}a(f(e),"The `argmax` function only works on arrays, Series, and DataFrames!");try{let r=Q(e,ot(e,t));return r?r.length===0?void 0:r.length===1?r[0]:r:void 0}catch{return}}function Et(e,t){return I(e,{shouldDropNaNs:t}).min}function Bt(e,t){if(b(e)){let r=Bt(e.values,t);return[e.index[r[0]],e.columns[r[1]]]}if(g(e)){let r=Bt(e.values,t);return e.index[r]}a(f(e),"The `argmin` function only works on arrays, Series, and DataFrames!");try{let r=Q(e,Et(e,t));return r?r.length===0?void 0:r.length===1?r[0]:r:void 0}catch{return}}function $(e,t){if(b(e)||g(e))return e.apply(r=>$(r,t));if(f(e))return d(e,r=>$(r,t));if(t==="null")return null;if(t==="number"){if(h(e))return NaN;let r=$(e,"boolean");if(tt(r))return r?1:0;try{JSON.parse(e)}catch{let i=$(e,"date");if(K(i))return i.getTime()}let n=parseFloat(e);return isNaN(n)?NaN:n}if(t==="int"){let r=$(e,"number");return r>=0?Math.floor(r):Math.ceil(r)}if(t==="float")return $(e,"number");if(t==="bigint")return typeof e=="bigint"?e: