jsdataframe
Advanced tools
+9
-1
@@ -0,1 +1,10 @@ | ||
| ## 0.2.0 | ||
| * Implement `df.melt` and `df.pivot` for reshaping data frames | ||
| * Implement `vector.pack`, `df.pack`, and `jd.unpack` for JSON serialization | ||
| * Implement set operations for vectors (union, intersect, setdiff) | ||
| * Implement `vector.indexOf` and `df.locAt` for efficient single-element lookup | ||
| * Implement `df.mapRowDfs` to map over rows as 1-row data frames | ||
| ## 0.1.1 | ||
@@ -10,2 +19,1 @@ | ||
| * Initial version | ||
@@ -1,3 +0,3 @@ | ||
| !function(t,e){"function"==typeof define&&define.amd?define(["exports"],e):e("object"==typeof exports&&"string"!=typeof exports.nodeName?exports:t.jsdataframe={})}(this,function(t){"use strict";function e(t){return String.fromCharCode(t)}function r(t,e,r){var n,i=r.size(),o=t.length-e,u=ot(i);for(n=0;i>n;n++)u[n]=ot(o);for(var s=0;o>s;s++){var a=t[s+e];if(a.length!==i)throw new Error("all row arrays must be of the same size");for(n=0;i>n;n++)u[n][s]=a[n]}return mt(u,r)}function n(t){return 0!==t&&Math.abs(t)<pe}function i(t){return Math.abs(t)>de}function o(t){var e=t.nChar().max(),r=Pt.rep(" ",e).strJoin("");return t.map(function(t){return(r+t).slice(-r.length)})}function u(t,e){var r=Pt.seq(t)._toTruncatedPrintVector(e);return r.map(function(t){return t===ye?t:t+ge})}function s(t){if(Ut(t))return"undefined";if(null===t)return"null";if(Number.isNaN(t))return"NaN";var e=xt(t),r=e.split("\n",2);return r.length>1&&(e=r[0]+"..."),e.length>he&&(e=e.slice(0,he-3)+"..."),e}function a(t,e,r){if("number"!=typeof t||Number.isNaN(t))throw new Error('"'+r+'" must be a number');if(e>t)throw new Error('"'+r+'" too small')}function l(t){var e=t.toString().split(".");return e.length>1?e[1].length:0}function c(t){return!it(t)}function h(t,e,r,n){return it(e)?n:e?t:r}function f(t,e){return 0===Ot(t,e)}function v(t,e){return Number.isNaN(t)&&Number.isNaN(e)||t===e}function p(t,e){return Ot(t,e)<0}function d(t,e){return Ot(t,e)>0}function m(t,e){return Number.isNaN(t)&&Number.isNaN(e)||Math.abs(t-e)<=1e-7}function y(t,e){return Ot(e,t)<0?e:t}function g(t,e){return Ot(e,t)>0?e:t}function b(t,e,r){var n=it(e),i=it(r);if(!n&&!i&&e>r)throw new Error("invalid range: lower ("+e+") > upper ("+r+")");return it(t)?t:!n&&e>t?e:!i&&t>r?r:t}function w(t,e){return t+e}function _(t,e){return t-e}function x(t,e){return t*e}function N(t,e){return t/e}function E(t,e){return t%e}function O(t,e){return t.n++,t.sum+=e,t}function j(t,e){t.n++;var r=e-t.mean;return t.mean+=r/t.n,t.M2+=r*(e-t.mean),t}function A(t,e){return t===!1||e===!1?!1:null===t||null===e?null:!0}function C(t,e){return t===!0||e===!0?!0:null===t||null===e?null:!1}function M(t){return!t}function z(t,e){return null===t||null===e?null:t!==e}function S(t,e){return+t+ +e}function k(t){return t.length}function I(t,e,r){return null===t?null:t.includes(e,r)}function R(t,e,r){return null===t?null:t.startsWith(e,r)}function T(t,e,r){return null===t?null:t.endsWith(e,r)}function q(t,e,r){return null===t?NaN:t.indexOf(e,r)}function L(t,e,r){return null===t?NaN:t.lastIndexOf(e,r)}function V(t,e){return null===t?NaN:t.search(e)}function D(t,e){return null===e||null===t?null:e.test(t)}function B(t){return null===t?null:t.toLowerCase()}function W(t){return null===t?null:t.toUpperCase()}function F(t){return function(){var e=t.apply(null,arguments);if(null===e)return e;var r=this[e];return Ut(r)&&(this[e]=e,r=e),r}}function K(t,e,r,n,i,o,u,s){var a,l,c=s?o:i,h=0;for(l=e.nCol(),a=0;l>a;a++)t[h].push(e._cols[a].values[c]),h++;for(l=r.nCol(),a=0;l>a;a++){var f=null===i?null:r._cols[a].values[i];t[h].push(f),h++}for(l=n.nCol(),a=0;l>a;a++){var v=null===o?null:n._cols[a].values[o];t[h].push(v),h++}h<t.length&&t[h].push(u)}function U(t,e,r){var n,i;if(Ut(r)||Ut(r.by)&&Ut(r.leftBy)&&Ut(r.rightBy)){var o=t.names().s(t.names().isIn(e.names()));if(o.nUnique()!==o.size())throw new Error("duplicate names found for key columns");n=Y(o,t._names,t._dtypesVector()),i=Y(o,e._names,e._dtypesVector())}else if(Ut(r.by)){if(Ut(r.leftBy)||Ut(r.rightBy))throw new Error("must specify both opts.leftBy and "+"opts.rightBy together");n=Y(r.leftBy,t._names,t._dtypesVector()),i=Y(r.rightBy,e._names,e._dtypesVector())}else{if(!Ut(r.leftBy)||!Ut(r.rightBy))throw new Error("cannot define opts.by, opts.leftBy, and "+"opts.rightBy all together");if(null!==r.by&&"object"==typeof r.by&&r.by.type!==Yt.type){var u=Object.keys(r.by),s=u.map(function(t){return r.by[t]});n=Y(u,t._names,t._dtypesVector()),i=Y(s,e._names,e._dtypesVector())}else{var a=Vt(r.by,"string");if(n=Y(a,t._names,t._dtypesVector()),i=Y(a,e._names,e._dtypesVector()),a.size()!==n.size())throw new Error("duplicate names found for key columns")}}if(dt(n),dt(i),n.size()!==i.size())throw new Error("must select the same number of key columns on the "+"left and right side; instead got "+n.size()+", "+i.size());if(0===n.size()||0===i.size())throw new Error("must select at least one key column to join by");return{left:n,right:i}}function P(t,e){if(Ut(t)||null===t)return null;var r=H(t,e);if(!Ut(r))return r;var n=G(Ce.INT,e);return Q(t,n)}function Y(t,e,r){if(Ut(t)||null===t)return null;var n=e.size(),i=H(t,n);if(!Ut(i))return i;var o=G(Ce.COL,n,e._getIndex(),r);return Q(t,o)}function H(t,e){if(t.type===te.type){var r=H(t._selector,e);return Ut(r)?void 0:J(r,e)}if(Array.isArray(t)&&(t=bt(t.slice(),"object")),t.type===Yt.type&&"boolean"===t.dtype){if(t.size()!==e)throw new Error("inappropriate boolean indexer length ("+t.size()+"); expected length to be "+e);return t.which()}}function J(t,e){return Pt.seq(e).isIn(t).not().which()}function G(t,e,r,n){return r=Ut(r)?null:r,n=Ut(n)?null:n,{resolveMode:t,maxLen:e,index:r,dtypes:n}}function Q(t,e){var r=[];return X(t,e,r),ut(r,"number")}function X(t,e,r){if(null!==t&&"object"==typeof t){if("function"==typeof t._resolveSelectorHelper)return void t._resolveSelectorHelper(e,r);if(Array.isArray(t)){for(var n=0;n<t.length;n++)X(t[n],e,r);return}}var i;switch(e.resolveMode){case Ce.INT:r.push($(t,e.maxLen));break;case Ce.COL:if(Bt(t))r.push($(t,e.maxLen));else{if(!Ft(t)&&null!==t)throw new Error("expected integer or string selector but got: "+t);i=e.index.lookupKey([t]),tt(i,t,e,r)}break;case Ce.KEY:if(1!==e.index.arity)throw new Error("unimplemented case (TODO)");var o=e.index.initVectors[0].dtype;kt(t,o),i=e.index.lookupKey([t]),tt(i,t,e,r);break;default:throw new Error("Unrecognized RESOLVE_MODE: "+e.resolveMode)}}function Z(t,e,r,n){var i;if(Ut(t))return r?e.maxLen:0;var o=e.resolveMode===Ce.INT||e.resolveMode===Ce.COL&&"number"==typeof t;if(null===n&&(n=!o),o)return i=$(t,e.maxLen,!1),r&&n?i+1:i;if(1===e.index.arity){if(i=e.index.lookupKey([t]),null===i)throw new Error("could not find entry for range bound: "+t);return"number"==typeof i?r&&n?i+1:i:r&&n?i[i.length-1]+1:i[0]}throw new Error("unimplemented case (TODO)")}function $(t,e,r){if(Ut(r)&&(r=!0),!Number.isInteger(t))throw new Error("expected integer selector for integer indexing "+"but got non-integer: "+t);var n=0>t?e+t:t;if(r&&(0>n||n>=e))throw new Error("integer index out of bounds");return n}function tt(t,e,r,n){if(null===t)throw r.resolveMode===Ce.COL?new Error('could not find column named "'+e+'"'):new Error("could find entry for key: "+e);if("number"==typeof t)n.push(t);else for(var i=0;i<t.length;i++)n.push(t[i])}function et(t,e){if(Ut(t))throw new Error("selector must not be undefined");if(t=Lt(t),Bt(t))return $(t,e.values.length);if(Ft(t)||null===t){var r=e._getIndex().lookupKey([t]);if(null===r)throw new Error("invalid column name: "+t);return"number"!=typeof r&&(r=r[0]),r}throw new Error("column selector must be an integer or string")}function rt(t,e){return null===t?Me["null"]:Ut(t)?Me.undefined:"date"===e?t.valueOf():t}function nt(t){var e=t.length;if(0===e)throw new Error("cannot index an empty list of vectors");var r=t[0].size(),n=Object.create(re);n.initVectors=t,n.size=0,n.arity=e,n._dtypes=t.map(function(t){return t.dtype}),n._map=Object.create(null);for(var i=n._map,o=e-1,u=0;r>u;u++){for(var s,a,l=i,c=0;o>c;c++){s=t[c],a=rt(s.values[u],s.dtype);var h=l[a];Ut(h)&&(l[a]=h=Object.create(null)),l=h}s=t[o],a=rt(s.values[u],s.dtype);var f=l[a];Ut(f)?(l[a]=u,n.size++):"number"==typeof f?l[a]=[f,u]:f.push(u)}return n}function it(t){return null===t||Ut(t)||Number.isNaN(t)}function ot(t){return 64e3>t?new Array(t):[]}function ut(t,e){Ct(e);var r=oe[e],n=Object.create(r);return n._init(t),n}function st(t,e,r){for(var n=t.length,i=ot(n),o=0;n>o;o++){var u=t[o];i[o]=it(u)?e:r(u)}return i}function at(t,e,r){for(var n=e,i=0;i<t.length;i++){var o=t[i];it(o)||(n=r(n,o))}return n}function lt(t,e,r,n){for(var i=e,o=0;o<t.length;o++){var u=t[o];if(r(u))return u;i=n(i,u)}return i}function ct(t,e,r,n){var i=!0;Ut(n)&&(n=r,i=!1);for(var o=t.length,u=e.length,s=qt(o,u),a=1===o,l=1===u,c=ot(s),h=0;s>h;h++){var f=a?t[0]:t[h],v=l?e[0]:e[h];i&&(it(f)||it(v))?c[h]=r:c[h]=n(f,v)}return c}function ht(t,e,r){if(0===t.length)throw new Error("cannot combine an empty list of arrays");r=Ut(r)?null:r;var n,i=t.length,o=ot(i),u=1;for(n=0;i>n;n++)if(1===t[n].length)o[n]=!0;else if(o[n]=!1,1===u)u=t[n].length;else if(u!==t[n].length)throw new Error("length mismatch: expected "+u+" elements but found "+t[n].length);for(var s=ot(u),a=ot(i),l=0;u>l;l++){for(n=0;i>n;n++)a[n]=o[n]?t[n][0]:t[n][l];s[l]=e.apply(r,a)}return s}function ft(t,e,r){var n=!1;Ut(r)&&(r=e,n=!0);for(var i=t.length,o=ot(i),u=null,s=!1,a=0;i>a;a++){var l=t[a];if(it(l)){if(o[a]=l,!n){for(var c=a+1;i>c;c++)o[c]=e;break}}else u=s?r(u,l):l,s=!0,o[a]=u}return o}function vt(t,e){for(var r=ot(e.length),n=0;n<e.length;n++)r[n]=t[e[n]];return r}function pt(t){return Pt.strCat("c",Pt.seq(t))}function dt(t){if(t.nUnique()!==t.values.length)throw new Error("duplicate occurrence of one or more columns "+"in selection")}function mt(t,e,r){var n,i=t.length;if(r=Ut(r)?!0:r){var o=1;for(n=0;i>n;n++){t[n]=Vt(t[n]);var u=t[n].values.length;if(1!==u)if(1===o)o=u;else if(u!==o)throw new Error("incompatible column lengths found during "+"data frame construction: "+o+", "+u)}if(1!==o)for(n=0;i>n;n++)if(1===t[n].values.length){for(var s=t[n].values[0],a=ot(o),l=0;o>l;l++)a[l]=s;t[n]=ut(a,t[n].dtype)}}var c=null;if(i>0)for(c=t[0].dtype,n=1;i>n;n++)if(t[n].dtype!==c){c=null;break}var h=Object.create(Xt);return h._cols=t,h._names=e,h._index=null,h.allDtype=c,h}function yt(t){return null===t||Ut(t)?null:Bt(t)?"number":Wt(t)?"boolean":Ft(t)?"string":Kt(t)?"date":"object"}function gt(t,e){Ct(e);for(var r=ue[e],n=0;n<t.length;n++)t[n]=r(t[n]);return ut(t,e)}function bt(t,e){Ut(e)&&(e="object");for(var r=null,n=0;n<t.length;n++){var i=yt(t[n]);if(null!==i&&(null===r&&(r=i),r!==i||"object"===i))return ut(t,"object")}var o;if(null===r){if(r=e,"object"!==r)for(o=ie[r],n=0;n<t.length;n++)t[n]=o;return ut(t,r)}if("object"!==r)for(o=ie[r],n=0;n<t.length;n++)it(t[n])&&(t[n]=o);return ut(t,r)}function wt(t){return it(t)?ie.number:+t}function _t(t){return it(t)?ie["boolean"]:!!t}function xt(t){return it(t)?ie.string:"object"!=typeof t?t.toString():Kt(t)?t.toISOString():t.toString()}function Nt(t){if(it(t))return ie.date;var e=new Date(t);return Number.isNaN(e.getTime())?null:e}function Et(t){return null===t?"null":Ut(t)?"undefined":"object"!=typeof t?t.toString():Kt(t)?t.toISOString():t.toString()}function Ot(t,e){var r=it(t),n=it(e);if(r&&n)t=ze[t],e=ze[e];else{if(r)return-1;if(n)return 1}return e>t?-1:t>e?1:0}function jt(t){return function(e,r){return-t(e,r)}}function At(t,e){if(t.length!==e.length)throw new Error('length of "ascending" must match the number of '+"sort columns");if(0===t.length)return null;for(var r=t[0].size(),n=ot(r),i=0;r>i;i++)n[i]=i;var o=e.map(function(t){return t?Ot:Se}),u=function(e,r){for(var n=0,i=0;i<o.length;i++){var u=t[i].values[e],s=t[i].values[r];if(n=o[i](u,s),0!==n)return n}return Ot(e,r)};return n.sort(u),n}function Ct(t){if(!(t in ne))throw new Error('invalid dtype: "'+t+'"')}function Mt(t,e){if(!Number.isInteger(t))throw new Error('expected an integer for "'+e+'" but got: '+t)}function zt(t,e){if(!Number.isInteger(t)||0>t)throw new Error('"'+e+'" must be a nonnegative integer')}function St(t,e){if("function"!=typeof t)throw new Error('"'+e+'" must be a function')}function kt(t,e){var r=yt(t);if(null!==r&&r!==e)throw new Error('expected scalar to match dtype "'+e+'" but instead got '+t+', which has dtype "'+r+'"')}function It(t,e){if(t.dtype!==e)throw new Error('expected vector dtype to be "'+e+'" but got "'+t.dtype+'"')}function Rt(t,e){if(t.dtype===e)throw new Error('unsupported operation for dtype "'+e+'"')}function Tt(t){if(t._dtypesVector().contains("object"))throw new Error("unsupported operation over data frame columns "+'with "object" dtype')}function qt(t,e){var r=t;if(t!==e)if(1===t)r=e;else if(1!==e)throw new Error("incompatible array lengths: "+t+" and "+e);return r}function Lt(t){if(Ut(t)||null===t)return t;var e=1,r="a scalar";if(t.type===Yt.type?(e=t.size(),t=t.values[0],r="a vector"):Array.isArray(t)&&(e=t.length,t=t[0],r="an array"),1!==e)throw new Error("expected a single scalar value but got "+r+" of length "+e);return t}function Vt(t,e){return(it(t)||t.type!==Yt.type)&&(t=Array.isArray(t)?bt(t.slice(),e):bt([t],e)),t}function Dt(t){return t=Vt(t,"string"),"string"!==t.dtype?t.toDtype("string"):t}function Bt(t){return"number"==typeof t}function Wt(t){return"boolean"==typeof t}function Ft(t){return"string"==typeof t}function Kt(t){return"[object Date]"===Object.prototype.toString.call(t)}function Ut(t){return"undefined"==typeof t}var Pt=t;Pt.version="0.1.1",Number.isNaN=Number.isNaN||function(t){return t!==t},Number.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},Array.prototype.findIndex||(Array.prototype.findIndex=function(t){if(null===this)throw new TypeError("Array.prototype.findIndex called on null or undefined");if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var e,r=Object(this),n=r.length>>>0,i=arguments[1],o=0;n>o;o++)if(e=r[o],t.call(i,e,o,r))return o;return-1}),String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),e+t.length>this.length?!1:this.indexOf(t,e)!==-1}),String.prototype.startsWith||(String.prototype.startsWith=function(t,e){return e=e||0,this.substr(e,t.length)===t}),String.prototype.endsWith||(String.prototype.endsWith=function(t,e){var r=this.toString();("number"!=typeof e||!isFinite(e)||Math.floor(e)!==e||e>r.length)&&(e=r.length),e-=t.length;var n=r.indexOf(t,e);return n!==-1&&n===e});var Yt={};Yt.type="jsdataframe.Vector";var Ht=Object.create(Yt),Jt=Object.create(Yt),Gt=Object.create(Yt),Qt=Object.create(Yt),Xt={};Xt.type="jsdataframe.DataFrame";var Zt={};Zt.type="jsdataframe.Range";var $t={};$t.type="jsdataframe.ByDtype";var te={};te.type="jsdataframe.Exclusion";var ee={};ee.type="jsdataframe.AbstractIndex";var re=Object.create(ee);re.type="jsdataframe.NestedIndex";var ne=Object.create(null);ne.number=!0,ne["boolean"]=!0,ne.string=!0,ne.date=!0,ne.object=!0;var ie={number:NaN,"boolean":null,string:null,date:null,object:null},oe={number:Ht,"boolean":Jt,string:Gt,date:Qt,object:Yt},ue={number:wt,"boolean":_t,string:xt,date:Nt,object:function(t){return t}};Pt._private_export={},Pt.vector=function(t,e,r){if(!Array.isArray(t))throw new Error('"array" argument must be an Array');return(Ut(r)||r)&&(t=t.slice()),Ut(e)&&(e=null),null===e?bt(t):gt(t,e)},Pt.seq=function(t,r,n,i){if(1===arguments.length){if(!Bt(t))throw new Error('both "start" and "stop" arguments must be '+"specified for non-numeric sequences");r=t,t=0}else if(yt(t)!==yt(r))throw new Error('"start" and "stop" must have the same dtype');if(n=Ut(n)?1:n,i=Ut(i)?!1:i,Ft(t)){if(1!==t.length||1!==r.length)throw new Error('both "start" and "stop" must be single characters '+"for character sequences");var o=Pt.seq(t.charCodeAt(0),r.charCodeAt(0),n,i);return o.map(e)}if(0===n)throw new Error('"step" must be nonzero');if(r>t&&0>n)throw new Error('"step" must be positive when start < stop');if(t>r&&n>0)throw new Error('"step" must be negative when start > stop');for(var u=[],s=t;n>0?i?r>=s:r>s:i?s>=r:s>r;)u.push(s),s+=n;return ut(u,"number")},Pt.seqOut=function(t,r,n){if(arguments.length<3&&(n=1),n=+n,zt(r,"lengthOut"),Ft(t)){if(1!==t.length)throw new Error('"start" must be a single character '+"for character sequences");var i=Pt.seqOut(t.charCodeAt(0),r,n);return i.map(e)}for(var o=ot(r),u=t,s=0;r>s;s++)o[s]=u,u+=n;return ut(o,"number")},Pt.linspace=function(t,e,r){t=+t,e=+e,zt(r,"length");for(var n=ot(r),i=1===r?0:(e-t)/(r-1),o=0;r>o;o++)n[o]=t+o*i;return ut(n,"number")},Pt.rep=function(t,e){zt(e,"times"),t=Vt(t);for(var r=t.values,n=r.length,i=ot(n*e),o=0;e>o;o++)for(var u=o*n,s=0;n>s;s++)i[u+s]=r[s];return ut(i,t.dtype)},Pt.repEach=function(t,e){zt(e,"times"),t=Vt(t);for(var r=t.values,n=r.length,i=ot(n*e),o=0;n>o;o++)for(var u=o*e,s=0;e>s;s++)i[u+s]=r[o];return ut(i,t.dtype)},Pt.repNa=function(t,e){zt(t,"times"),Ct(e);for(var r=ie[e],n=ot(t),i=0;t>i;i++)n[i]=r;return ut(n,e)},Pt.df=function(t,e){Ut(e)||(e=Dt(e));var r;if(t.type===Yt.type)throw new Error('"columns" should not itself be a vector');if(Array.isArray(t)){if(r=t.length,Ut(e))e=pt(r);else if(e.size()!==r)throw new Error('the length of "colNames" ('+e.size()+') does not match the length of "columns" ('+r+")")}else{if("object"!=typeof t)throw new Error('expected "columns" to be an array or object but got: ',t);var n=Object.keys(t);r=n.length;var i=t;if(Ut(e))e=ut(n,"string");else{if(e.isNa().any())throw new Error('"colNames" cannot have null entries when '+'"columns" is an object');if(e.duplicated().any())throw new Error('"colNames" cannot have duplicate entries when '+'"columns" is an object');if(e.size()!==r||e.isIn(n).not().any())throw new Error('"colNames" must match all the keys in '+'"columns" if "columns" is an object')}t=ot(r);for(var o=0;r>o;o++)t[o]=i[e.values[o]]}return mt(t,e)},Pt.dfFromObjArray=function(t,e){if(!Array.isArray(t))throw new Error('"objArray" must be an array');var r,n,i=t.length,o=!0;if(Ut(e))e=[],n=[],o=!1;else{if(e=Dt(e),e.isNa().any())throw new Error('"colOrder" cannot have null entries');if(e.duplicated().any())throw new Error('"colOrder" cannot have duplicate entries');for(e=e.values,n=ot(e.length),r=0;r<e.length;r++)n[r]=ot(i)}for(var u=Object.create(null),s=0;i>s;s++){var a=t[s];if(!o){var l=Object.keys(a);for(r=0;r<l.length;r++){var c=l[r];if(!(c in u)){e.push(c);for(var h=ot(i),f=0;s>f;f++)h[f]=null;n.push(h),u[c]=c}}}for(r=0;r<e.length;r++)n[r][s]=a.propertyIsEnumerable(e[r])?a[e[r]]:null}return mt(n,ut(e,"string"))},Pt.dfFromMatrix=function(t,e){if(!Array.isArray(t))throw new Error('"matrix" must be an array');var n=t.length>0?t[0].length:0;if(e=Ut(e)?pt(n):Dt(e),n>0&&n!==e.size())throw new Error('"colNames" must have the same length as each '+"row array");return r(t,0,e)},Pt.dfFromMatrixWithHeader=function(t){if(!Array.isArray(t))throw new Error('"matrix" must be an array');if(0===t.length)throw new Error('"matrix" must not have length 0');var e=Dt(t[0]);if(t.length>1&&e.size()!==t[1].length)throw new Error("header row must have the same length as other "+"row arrays");return r(t,1,e)},Pt.vCat=function(){for(var t=arguments.length,e=ot(t),r=null,n=0,i=0;t>i;i++){var o=arguments[i];if(!Ut(o)&&null!==o&&o.type===Xt.type)throw new Error("cannot pass data frame arguments to jd.vCat");var u=Vt(o);null===r&&"object"!==u.dtype&&(r=u.dtype),n+=u.size(),e[i]=u}r=null===r?"object":r;var s=ot(n),a=0;for(i=0;t>i;i++)for(var l=e[i].values,c=l.length,h=0;c>h;h++)s[a]=l[h],a++;return bt(s,r)},Pt.colCat=function(){for(var t=arguments.length,e=ot(t),r=0;t>r;r++)e[r]=arguments[r];return Pt._colCatArray(e)},Pt._colCatArray=function(t){for(var e,r=t.length,n=[],i=[],o=0;r>o;o++){var u=t[o];if(Ut(u)||null===u)n.push(u),i.push(null);else if(u.type===Xt.type){var s=u._cols.length;for(e=0;s>e;e++)n.push(u._cols[e]),i.push(u._names.values[e])}else if("object"!=typeof u||u.type===Yt.type||Array.isArray(u))n.push(u),i.push(null);else{var a=Object.keys(u);for(e=0;e<a.length;e++){var l=a[e];n.push(u[l]),i.push(l)}}}return mt(n,ut(i,"string"))},Pt.rowCat=function(){for(var t=arguments.length,e=ot(t),r=0;t>r;r++)e[r]=arguments[r];return Pt._rowCatArray(e)};var se={SCALAR:0,ARRAY:1,VECTOR:2,DATA_FRAME:3};Pt._rowCatArray=function(t){var e,r,n,i=t.length,o=ot(i),u=null,s=0,a=-1;for(r=0;i>r;r++){e=t[r];var l;if(Ut(e)||null===e||"object"!=typeof e)o[r]=se.SCALAR,s++,l=a;else if(e.type===Xt.type){if(o[r]=se.DATA_FRAME,l=e.nCol(),0===l)continue;if(s+=e.nRow(),null===u)u=e._names.values.slice();else{var c=Math.min(u.length,l),h=e._names.values;for(n=0;c>n;n++)h[n]!==u[n]&&(u[n]=null)}}else e.type===Yt.type?(o[r]=se.VECTOR,s++,l=e.values.length):Array.isArray(e)?(o[r]=se.ARRAY,s++,l=e.length):(o[r]=se.SCALAR,s++,l=a);if(a===-1)a=l;else if(a!==l)throw new Error("arguments imply differing number of columns: "+a+", "+l)}if(0===s)return Pt.df([]);a===-1&&(a=1);var f=null===u?Pt.repNa(a,"string"):ut(u,"string"),v=ot(a);for(n=0;a>n;n++)v[n]=ot(s);var p=0;for(r=0;i>r;r++)switch(e=t[r],o[r]){case se.SCALAR:for(n=0;a>n;n++)v[n][p]=e;p++;break;case se.VECTOR:e=e.values;case se.ARRAY:for(n=0;a>n;n++)v[n][p]=e[n];p++;break;case se.DATA_FRAME:var d=e.nRow();for(n=0;a>n;n++)for(var m=0;d>m;m++)v[n][p+m]=e._cols[n].values[m];p+=d}return mt(v,f)},Pt.strCat=function(){var t=arguments.length;if(0===t)throw new Error('"strCat" must be called with at least one argument');for(var e=ot(t),r=0;t>r;r++)e[r]=Vt(arguments[r]).values;var n=Object.create(null),i=ht(e,ae,n);return ut(i,"string")};var ae=F(function(){for(var t=arguments.length,e=ot(t),r=0;t>r;r++){var n=arguments[r];if(it(n))return null;e[r]=Et(n)}return e.join("")}),le=55,ce=4,he=45,fe=6,ve=6,pe=Math.pow(10,1-fe),de=1e7-1e-9,me=" ",ye="..",ge=":";Pt.printingOpts={},Pt.printingOpts._maxWidth=79,Pt.printingOpts._maxLines=10,Pt.printingOpts._printCallback=function(t){console.log(t)},Pt.printingOpts.getMaxWidth=function(){return this._maxWidth},Pt.printingOpts.setMaxWidth=function(t){a(t,le,"maxWidth"),this._maxWidth=t},Pt.printingOpts.getMaxLines=function(){return this._maxLines},Pt.printingOpts.setMaxLines=function(t){a(t,ce,"maxLines"),this._maxLines=t},Pt.printingOpts.setPrintFunction=function(t){St(t,"callback"),this._printCallback=t},Yt.p=function(t){var e=this.printToString(t);Pt.printingOpts._printCallback(e)},Yt.printToString=function(t){if(Ut(t)?t=Pt.printingOpts._maxLines:a(t,ce,"maxLines"),0===this.values.length)return this.toString();var e=o(u(this.values.length,t)),r=o(this._toTruncatedPrintVector(t)),n=Pt.strCat(e,me,r);return this.toString()+"\n"+n.strJoin("\n")},Xt.p=function(t){var e=this.printToString(t);Pt.printingOpts._printCallback(e)},Xt.printToString=function(t){Ut(t)?t=Pt.printingOpts._maxLines:a(t,ce,"maxLines");for(var e=o(Pt.vCat("",u(this.nRow(),t))),r=[e],n=0,i=e.at(0).length,l=Pt.printingOpts._maxWidth-ye.length-me.length;l>=i&&n<this.nCol();){var c=this._cols[n]._toTruncatedPrintVector(t),h=o(Pt.vCat(s(this._names.at(n)),c));r.push(me),r.push(h),i+=me.length+h.at(0).length,n++}i>l&&(r.pop(),r.push(ye));var f=Pt.strCat.apply(Pt,r);return this.toString()+"\n"+f.strJoin("\n")},Yt._toTruncatedPrintVector=function(t){if(this.values.length>t){var e=Math.ceil(t/2-1),r=Pt.rng(0,e),n=Pt.rng(-e),i=this.s([r,n])._toPrintVector();return Pt.vCat(i.s(r),ye,i.s(n))}return this._toPrintVector()},Yt._toPrintVector=function(){return this.map(s)},Ht._toPrintVector=function(){if(this.values.some(n)||this.values.some(i))return this.map(function(t){return t.toExponential(ve)});var t=Math.min(fe,this.map(l).max());return this.map(function(e){return e.toFixed(t)})},Pt._private_export.toPrintString=s,Pt._private_export.fractionDigits=l,Yt.dtype="object",Yt._init=function(t){this.values=t,this._index=null},Yt.size=function(){return this.values.length},Yt.toString=function(){return"Vector[dtype:"+this.dtype+", size:"+this.values.length+"]"},Yt.toArray=function(){return this.values.slice()},Yt.toDtype=function(t){if(this.dtype===t)return this;if("string"===t){var e=Object.create(null),r=ht([this.values],be,e);return ut(r,"string")}return Pt.vector(this.values,t)};var be=F(xt);Yt.serialize=function(){throw new Error("unimplemented method (TODO)")},Yt.isNa=function(){return ut(this.values.map(it),"boolean")},Yt.dropNa=function(){return this.filter(c)},Yt.replaceNa=function(t){var e=ue[this.dtype];t=e(t);for(var r=this.values.slice(),n=0;n<r.length;n++)it(r[n])&&(r[n]=t);return ut(r,this.dtype)},Yt.s=function(t){var e=P(t,this.values.length);if(null===e)return this;var r=vt(this.values,e.values);return ut(r,this.dtype)},Yt.sMod=function(t,e){var r=P(t,this.values.length);null===r&&(r=Pt.seq(this.values.length)),e=Vt(e,this.dtype),It(e,this.dtype);var n=1===e.size();if(!n&&e.size()!==r.size())throw new Error("length mismatch: cannot assign "+e.size()+" values to a selection of length "+r.size());for(var i=r.values,o=this.values.slice(),u=0;u<i.length;u++)o[i[u]]=n?e.values[0]:e.values[u];return ut(o,this.dtype)},Yt.at=function(t){return t=Lt(t),t=$(t,this.size()),this.values[t]},Yt.head=function(t){return Ut(t)&&(t=6),Mt(t,"n"),this.s(Pt.rng(0,t))},Yt.tail=function(t){Ut(t)&&(t=6),Mt(t,"n");var e=0>t?-t:this.size()-t;return this.s(Pt.rng(e,void 0))},Yt.ifElse=function(t,e){if(t=Vt(t,"boolean"),t.size()!==this.size())throw new Error('"cond" must be the same length as this vector');It(t,"boolean"),e=Vt(e,this.dtype),It(e,this.dtype);var r=ht([this.values,t.values,e.values,[ie[this.dtype]]],h);return ut(r,this.dtype)},Yt.ex=function(){return Pt.ex(this)},Yt.map=function(){var t=Array.prototype.map.apply(this.values,arguments);return bt(t,this.dtype)},Yt.reduce=function(){return Array.prototype.reduce.apply(this.values,arguments)},Yt.reduceRight=function(){return Array.prototype.reduceRight.apply(this.values,arguments)},Yt.findIndex=function(){return Array.prototype.findIndex.apply(this.values,arguments)},Yt.sort=function(t){Ut(t)&&(t=Ot);var e=this.values.slice();return Array.prototype.sort.call(e,t),ut(e,this.dtype)},Yt.reverse=function(){var t=this.values.slice();return Array.prototype.reverse.call(t),ut(t,this.dtype)},Yt.filter=function(){var t=Array.prototype.filter.apply(this.values,arguments);return ut(t,this.dtype)},Yt.strJoin=function(t){return this.values.map(Et).join(t)},Yt.combine=function(){var t=arguments.length;if(2>t)throw new Error('must supply at least one "varg"');var e=arguments[t-1];if("function"!=typeof e)throw new Error('the last argument to "combine" must be a function');var r=ot(t);r[0]=this.values;for(var n=1;t>n;n++)r[n]=Vt(arguments[n-1]).values;var i=ht(r,e);return Pt.vector(i)},Yt.eq=function(t){t=Vt(t,this.dtype);var e=qt(this.size(),t.size());if(this.dtype!==t.dtype)return Pt.repNa(e,"boolean");var r="object"===this.dtype?ct(this.values,t.values,null,v):ct(this.values,t.values,null,f);return ut(r,"boolean")},Yt.neq=function(t){return this.eq(t).not()},Yt.lt=function(t){t=Vt(t,this.dtype);var e=qt(this.size(),t.size());if(this.dtype!==t.dtype)return Pt.repNa(e,"boolean");var r=ct(this.values,t.values,null,p);return ut(r,"boolean")},Yt.gt=function(t){t=Vt(t,this.dtype);var e=qt(this.size(),t.size());if(this.dtype!==t.dtype)return Pt.repNa(e,"boolean");var r=ct(this.values,t.values,null,d);return ut(r,"boolean")},Yt.lte=function(t){return this.lt(t).or(this.eq(t))},Yt.gte=function(t){return this.gt(t).or(this.eq(t))},Yt.between=function(t,e,r){throw new Error("unimplemented method (TODO)")},Yt.equals=function(t,e){if(it(t)||t.type!==Yt.type||this.size()!==t.size()||this.dtype!==t.dtype)return!1;if(this===t)return!0;var r=f;"number"===this.dtype?r=Ut(e)?m:function(t,r){return Number.isNaN(t)&&Number.isNaN(r)||Math.abs(t-r)<=e}:"object"===this.dtype&&(r=v);for(var n=this.values,i=t.values,o=0;o<n.length;o++)if(!r(n[o],i[o]))return!1;return!0},Yt.min=function(t){var e=this.idxMin(t);return Number.isNaN(e)?ie[this.dtype]:this.values[e]},Yt.max=function(t){var e=this.idxMax(t);return Number.isNaN(e)?ie[this.dtype]:this.values[e]},Yt.cuMin=function(t){Ut(t)&&(t=!0);var e=t?ft(this.values,y):ft(this.values,ie[this.dtype],y);return ut(e,this.dtype)},Yt.cuMax=function(t){Ut(t)&&(t=!0);var e=t?ft(this.values,g):ft(this.values,ie[this.dtype],g);return ut(e,this.dtype)},Yt.idxMin=function(t){Ut(t)&&(t=!0);for(var e=this.values,r=NaN,n=null,i=0;i<e.length;i++){var o=e[i];if(it(o)){if(!t)return NaN}else(Ot(o,n)<0||Number.isNaN(r))&&(n=o,r=i)}return r},Yt.idxMax=function(t){Ut(t)&&(t=!0);for(var e=this.values,r=NaN,n=null,i=0;i<e.length;i++){var o=e[i];if(it(o)){if(!t)return NaN}else(Ot(o,n)>0||Number.isNaN(r))&&(n=o,r=i)}return r},Yt.pMin=function(t){t=Vt(t,this.dtype),It(t,this.dtype);var e=ct(this.values,t.values,ie[this.dtype],y);return ut(e,this.dtype)},Yt.pMax=function(t){t=Vt(t,this.dtype),It(t,this.dtype);var e=ct(this.values,t.values,ie[this.dtype],g);return ut(e,this.dtype)},Yt.clip=function(t,e){t=Vt(t,this.dtype),e=Vt(e,this.dtype),It(t,this.dtype),It(e,this.dtype);var r=ht([this.values,t.values,e.values],b);return ut(r,this.dtype)},Yt.rank=function(){throw new Error("unimplemented method (TODO)")},Yt.contains=function(t){Rt(this,"object"),t=Lt(t);var e=yt(t);if(e!==this.dtype&&null!==e)throw new Error('"value" does not match the dtype of this vector');return null!==this._getIndex().lookupKey([t])},Yt.isIn=function(t){return Rt(this,"object"),t=Vt(t,this.dtype),It(t,this.dtype),t._getIndex().has([this])},Yt.valueCounts=function(){Rt(this,"object");var t=this._getIndex().valueCounts(),e=Pt.df([t.vectors[0],t.counts],["value","count"]);return e.sort(["count","value"],[!1,!0])},Yt.unique=function(){return Rt(this,"object"),this._getIndex().unique()[0]},Yt.nUnique=function(){return Rt(this,"object"),this._getIndex().size},Yt.duplicated=function(t){return Rt(this,"object"),this._getIndex().duplicated(t)},Yt.intersect=function(){throw new Error("unimplemented method (TODO)")},Yt.replace=function(){throw new Error("unimplemented method (TODO)")},Yt.describe=function(){throw new Error("unimplemented method (TODO)")},Yt._getIndex=function(){return null===this._index&&(this._index=nt([this])),this._index},Ht.dtype="number",Ht.add=function(t){t=Vt(t,"number"),It(t,"number");var e=ct(this.values,t.values,NaN,w);return ut(e,"number")},Ht.sub=function(t){t=Vt(t,"number"),It(t,"number");var e=ct(this.values,t.values,NaN,_);return ut(e,"number")},Ht.mul=function(t){t=Vt(t,"number"),It(t,"number");var e=ct(this.values,t.values,NaN,x);return ut(e,"number")},Ht.div=function(t){t=Vt(t,"number"),It(t,"number");var e=ct(this.values,t.values,NaN,N);return ut(e,"number")},Ht.mod=function(t){t=Vt(t,"number"),It(t,"number");var e=ct(this.values,t.values,NaN,E);return ut(e,"number")},Ht.pow=function(t){t=Vt(t,"number"),It(t,"number");var e=ct(this.values,t.values,NaN,Math.pow);return ut(e,"number")},Ht.abs=function(){return ut(this.values.map(Math.abs),"number")},Ht.sqrt=function(){return ut(this.values.map(Math.sqrt),"number")},Ht.sign=function(){return ut(this.values.map(Math.sign),"number")},Ht.ceil=function(){return ut(this.values.map(Math.ceil),"number")},Ht.floor=function(){return ut(this.values.map(Math.floor),"number")},Ht.round=function(){return ut(this.values.map(Math.round),"number")},Ht.exp=function(){return ut(this.values.map(Math.exp),"number")},Ht.log=function(){return ut(this.values.map(Math.log),"number")},Ht.sin=function(){return ut(this.values.map(Math.sin),"number")},Ht.cos=function(){return ut(this.values.map(Math.cos),"number")},Ht.tan=function(){return ut(this.values.map(Math.tan),"number")},Ht.asin=function(){return ut(this.values.map(Math.asin),"number")},Ht.acos=function(){return ut(this.values.map(Math.acos),"number")},Ht.atan=function(){return ut(this.values.map(Math.atan),"number")},Ht.sum=function(t){return Ut(t)&&(t=!0),t?at(this.values,0,w):lt(this.values,0,it,w)},Ht.cuSum=function(t){Ut(t)&&(t=!0);var e=t?ft(this.values,w):ft(this.values,ie.number,w);return ut(e,"number")},Ht.mean=function(t){Ut(t)&&(t=!0);var e={n:0,sum:0},r=t?at(this.values,e,O):lt(this.values,e,it,O);return Number.isNaN(r)||0===r.n?NaN:r.sum/r.n},Ht.stdev=function(t){var e=this["var"](t);return Number.isNaN(e)?NaN:Math.sqrt(e)},Ht["var"]=function(t){Ut(t)&&(t=!0);var e={n:0,mean:0,M2:0},r=t?at(this.values,e,j):lt(this.values,e,it,j);return Number.isNaN(r)||r.n<2?NaN:r.M2/(r.n-1)},Jt.dtype="boolean",Jt.and=function(t){t=Vt(t,"boolean"),It(t,"boolean");var e=ct(this.values,t.values,A);return ut(e,"boolean")},Jt.or=function(t){t=Vt(t,"boolean"),It(t,"boolean");var e=ct(this.values,t.values,C);return ut(e,"boolean"); | ||
| },Jt.not=function(){var t=st(this.values,null,M);return ut(t,"boolean")},Jt.xor=function(t){t=Vt(t,"boolean"),It(t,"boolean");var e=ct(this.values,t.values,z);return ut(e,"boolean")},Jt.all=function(t){return Ut(t)&&(t=!1),t?at(this.values,!0,A):this.values.reduce(A,!0)},Jt.any=function(t){return Ut(t)&&(t=!1),t?at(this.values,!1,C):this.values.reduce(C,!1)},Jt.sum=function(t){if(Ut(t)&&(t=!0),t)return at(this.values,0,S);var e=lt(this.values,0,it,S);return null===e?NaN:e},Jt.which=function(){for(var t=[],e=0;e<this.values.length;e++){var r=this.values[e];r===!0&&t.push(e)}return ut(t,"number")},Gt.dtype="string",Gt.nChar=function(){var t=st(this.values,ie.number,k);return ut(t,"number")},Gt.charAt=function(t){t=Vt(t);var e=Object.create(null),r=ht([this.values,t.values],we,e);return ut(r,"string")};var we=F(function(t,e){return null===t?null:t.charAt(e)});Gt.trim=function(){var t=Object.create(null),e=ht([this.values],_e,t);return ut(e,"string")};var _e=F(function(t){return null===t?null:t.trim()});Gt.strSlice=function(t,e){t=Vt(t),e=Vt(e);var r=Object.create(null),n=ht([this.values,t.values,e.values],xe,r);return ut(n,"string")};var xe=F(function(t,e,r){return null===t?null:t.slice(e,r)});Gt.substr=function(t,e){t=Vt(t),e=Vt(e);var r=Object.create(null),n=ht([this.values,t.values,e.values],Ne,r);return ut(n,"string")};var Ne=F(function(t,e,r){return null===t?null:t.substr(e,r)});Gt.strIncludes=function(t,e){t=Vt(t),e=Vt(e);var r=ht([this.values,t.values,e.values],I);return ut(r,"boolean")},Gt.startsWith=function(t,e){t=Vt(t),e=Vt(e);var r=ht([this.values,t.values,e.values],R);return ut(r,"boolean")},Gt.endsWith=function(t,e){t=Vt(t),e=Vt(e);var r=ht([this.values,t.values,e.values],T);return ut(r,"boolean")},Gt.strIndexOf=function(t,e){t=Vt(t),e=Vt(e);var r=ht([this.values,t.values,e.values],q);return ut(r,"number")},Gt.strLastIndexOf=function(t,e){t=Vt(t),e=Vt(e);var r=ht([this.values,t.values,e.values],L);return ut(r,"number")},Gt.regexMatch=function(t){t=Vt(t);var e=Object.create(null),r=ht([this.values,t.values],Ee,e);return ut(r,"string")};var Ee=F(function(t,e){if(null===t)return null;var r=t.match(e);return null===r?null:r[0]});Gt.regexSearch=function(t){t=Vt(t);var e=ht([this.values,t.values],V);return ut(e,"number")},Gt.regexTest=function(t){t=Vt(t);var e=ht([this.values,t.values],D);return ut(e,"boolean")},Gt.strReplace=function(t,e){t=Vt(t),e=Vt(e);var r=Object.create(null),n=ht([this.values,t.values,e.values],Oe,r);return ut(n,"string")};var Oe=F(function(t,e,r){return null===t?null:t.replace(e,r)});Gt.toLowerCase=function(){var t=Object.create(null),e=ht([this.values],B,t);return ut(e,"string")},Gt.toUpperCase=function(){var t=Object.create(null),e=ht([this.values],W,t);return ut(e,"string")},Qt.dtype="date",Xt.nRow=function(){return 0===this._cols.length?0:this._cols[0].values.length},Xt.nCol=function(){return this._cols.length},Xt.dtypes=function(){return Pt.df([this.names(),this._dtypesVector()],["colName","dtype"])},Xt._dtypesVector=function(){return ut(this._cols.map(function(t){return t.dtype}),"string")},Xt.colArray=function(){return this._cols.slice()},Xt.colMap=function(){var t=this._names.dropNa().unique().values,e=t.map(function(t){return et(t,this._names)},this),r=Object.create(null);return e.forEach(function(e,n){var i=t[n];r[i]=this._cols[e]},this),r},Xt.equals=function(t,e){if(null===t||Ut(t)||t.type!==Xt.type||!t.names().equals(this.names()))return!1;for(var r=this.nCol(),n=0;r>n;n++)if(!t._cols[n].equals(this._cols[n],e))return!1;return!0},Xt.toString=function(){var t="DataFrame[nRow:"+this.nRow()+", nCol:"+this.nCol()+", allDtype:"+this.allDtype+"]";return t},Xt.toObjArray=function(){for(var t=this._names.dropNa().unique().values,e=t.map(function(t){return et(t,this._names)},this),r=this.nRow(),n=t.length,i=ot(r),o=0;r>o;o++){for(var u={},s=0;n>s;s++)u[t[s]]=this._cols[e[s]].values[o];i[o]=u}return i},Xt.toMatrix=function(t){t=Ut(t)?!1:t;var e=t?1:0,r=this.nRow(),n=ot(r+e);t&&(n[0]=this._names.values);for(var i=this.nCol(),o=0;r>o;o++){for(var u=ot(i),s=0;i>s;s++)u[s]=this._cols[s].values[o];n[o+e]=u}return n},Xt.names=function(){return this._names},Xt.setNames=function(t){if(t=Dt(t),t.size()!==this._cols.length)throw new Error('the length of "names" must match the number of columns');return mt(this._cols,t,!1)},Xt.rename=function(t){throw new Error("unimplemented method (TODO)")},Xt.resetNames=function(){return mt(this._cols,pt(this._cols.length),!1)},Xt.isNa=function(){return this.mapCols(function(t){return t.isNa()})},Xt.dropNa=function(){var t=this.nCol(),e=this.nRow();if(0===e)return this;for(var r=ot(e),n=0;e>n;n++){r[n]=!0;for(var i=0;t>i;i++)if(it(this._cols[i].values[n])){r[n]=!1;break}}return this.s(r)},Xt.s=function(t,e){var r=P(t,this.nRow()),n=Y(e,this._names,this._dtypesVector()),i=this._names.values,o=this._cols;null!==n&&(i=vt(i,n.values),o=vt(o,n.values));var u=ut(i,"string");if(null!==r){null===n&&(o=o.slice());for(var s=0;s<o.length;s++){var a=o[s].dtype,l=vt(o[s].values,r.values);o[s]=ut(l,a)}}return mt(o,u,!1)},Xt.sMod=function(t,e,r){var n=!Ut(r)&&null!==r&&r.type===Xt.type;n||(r=Lt(r));var i=P(t,this.nRow()),o=Y(e,this._names,this._dtypesVector());if(null===o?o=Pt.seq(this.nCol()):dt(o),n){var u=null===i?this.nRow():i.size();if(u!==r.nRow()||o.size()!==r.nCol())throw new Error('"values" has the wrong dimensions for selection')}for(var s=this._cols.slice(),a=0;a<o.values.length;a++){var l=o.values[a],c=n?r._cols[a]:r;s[l]=null!==i?s[l].sMod(i,c):n?c:Pt.rep(c,this.nRow())}return mt(s,this.names(),!1)},Xt.c=function(t){var e=et(t,this._names);return this._cols[e]},Xt.cMod=function(t,e){var r=this._cols.slice(),n=et(t,this._names);return r[n]=e,mt(r,this._names)},Xt.insertCol=function(t,e,r){if(t=xt(t),r=Ut(r)?this._cols.length:r,r=Lt(r),!Number.isInteger(r))throw new Error('expected "index" to be an integer but got: '+r);var n=this._cols.slice(),i=this._names.values.slice();return n.splice(r,0,e),i.splice(r,0,t),mt(n,ut(i,"string"))},Xt.at=function(t,e){if(t=Lt(t),t=$(t,this.nRow()),e=Lt(e),Bt(e))e=$(e,this.nCol());else{if(!Ft(e)&&null!==e)throw new Error('expected "j" to be an integer or string but got: '+e);e=et(e,this._names)}return this._cols[e].values[t]},Xt.head=function(t){return Ut(t)&&(t=6),Mt(t,"n"),this.s(Pt.rng(0,t))},Xt.tail=function(t){Ut(t)&&(t=6),Mt(t,"n");var e=0>t?-t:this.nRow()-t;return this.s(Pt.rng(e,void 0))},Xt.mapCols=function(t,e){arguments.length<2&&(e=t,t=null),St(e,"func");var r=Y(t,this._names,this._dtypesVector());null===r&&(r=Pt.seq(this._cols.length));for(var n=this._names.values,i=r.values.length,o=ot(i),u=ot(i),s=0;i>s;s++){var a=r.values[s],l=this._cols[a],c=n[a];u[s]=e(l,c,a,s),o[s]=c}var h=ut(o,"string");return mt(u,h)},Xt.updateCols=function(t,e){arguments.length<2&&(e=t,t=null),St(e,"func");var r=Y(t,this._names,this._dtypesVector());null===r?r=Pt.seq(this._cols.length):dt(r);for(var n=this._names.values,i=this._cols.slice(),o=r.values.length,u=0;o>u;u++){var s=r.values[u],a=this._cols[s],l=n[s];i[s]=e(a,l,s,u)}return mt(i,this._names)},Xt.mapRowObjects=function(t,e){return St(t,"func"),this.toObjArray().map(t,e)},Xt.mapRowArrays=function(t,e){return St(t,"func"),this.toMatrix().map(t,e)},Xt.mapRowVectors=function(t,e){St(t,"func");var r=this.allDtype;if(null===r)throw new Error('cannot call "mapRowVectors" on a data frame with '+'null "allDtype" property');for(var n=this.toMatrix(),i=0;i<n.length;i++)n[i]=ut(n[i],r);return n.map(t,e)},Xt.unique=function(){if(0===this.nCol())return this;Tt(this);var t=this._getIndex().unique();return mt(t,this._names,!1)},Xt.nUnique=function(){return 0===this.nCol()?0:(Tt(this),this._getIndex().size)},Xt.duplicated=function(t){return 0===this.nCol()?ut([],"boolean"):(Tt(this),this._getIndex().duplicated(t))},Xt._getIndex=function(){return 1===this._cols.length?this._cols[0]._getIndex():(null===this._index&&(this._index=nt(this._cols)),this._index)},Xt.groupApply=function(t,e,r){if(Ut(t))throw new Error('"colSelect" must not be undefined');var n=Y(t,this._names,this._dtypesVector());if(dt(n),null===n||n.size()===this.nCol())throw new Error('"colSelect" must not select every column in the '+"data frame");if(0===n.size())throw new Error('"colSelect" must select at least 1 column');var i=this.s(null,n.ex()),o=this.s(null,n);Tt(o);var u=o._getIndex(),s=o.unique();St(e,"func"),Ut(r)||(r=Vt(r,"string"),"string"!==r.dtype&&(r=r.toDtype("string")));for(var a=s.nRow(),l=ot(a),c=-1,h=0,f=0;a>f;f++){var v=s.s(f),p=u.lookup(s._cols,f),d=i.s(p),m=e(d,v);if(!Ut(m)){var y,g;if(null===m?(y=1,g=[v,m]):m.type===Xt.type?(y=m.nCol(),g=[v,m]):m.type===Yt.type?(y=m.size(),g=[v].concat(m.values)):Array.isArray(m)?(y=m.length,g=[v].concat(m)):(y=1,g=[v,m]),c===-1){if(c=y,!Ut(r)&&y!==r.size())throw new Error('length of "colNames" must match implied number '+'of columns returned by "func"')}else if(y!==c)throw new Error("inconsistent implied column counts returned from "+'"func": '+c+", ",+y);l[h]=Pt._colCatArray(g),h++}}if(0===h)return s.s([]);l.length!==h&&(l.length=h);var b=Pt._rowCatArray(l);if(!Ut(r)){var w=b.names();w=w.sMod(Pt.rng(n.size()),r),b=b.setNames(w)}return b},Xt.transpose=function(t,e){if(0===this.nRow())return Pt.df([]);if(t=Ut(t)?null:t,null!==t&&!Ft(t))throw new Error('"preservedColName" must be a string when not null or '+"undefined");var r,n,i=this.nRow();if(Ut(e))r=this,n=pt(i);else{var o=et(e,this._names);r=this.s(null,Pt.ex(o)),n=this.c(o),"string"!==n.dtype&&(n=n.toDtype("string"))}var u,s;null!==t?(n=Pt.vCat(t,n),u=1,s=ot(i+1),s[0]=r._names):(u=0,s=ot(i));for(var a=r.nCol(),l=0;i>l;l++){for(var c=ot(a),h=0;a>h;h++)c[h]=r._cols[h].values[l];s[l+u]=c}return mt(s,n)},Xt.sort=function(t,e){if(Ut(t))throw new Error('"colSelect" must not be undefined');var r=Y(t,this._names,this._dtypesVector());null===r?r=Pt.seq(this.nCol()):dt(r);var n=this.s(null,r);if(Tt(n),e=Ut(e)?!0:e,e=Vt(e,"boolean"),It(e,"boolean"),e.isNa().any())throw new Error('"ascending" must not contain missing values');1===e.size()&&(e=Pt.rep(e,n.nCol()));var i=At(n._cols,e.values);return this.s(i)};var je=Pt.vector(["by","leftBy","rightBy","leftSuffix","rightSuffix","indicator"]);Xt.join=function(t,e,r){if(Ut(t)||null===t||t.type!==Xt.type)throw new Error('"other" must be a data frame');var n=!1,i="_x",o="_y",u=!1,s=!1;switch(e){case"inner":break;case"left":u=!0;break;case"right":s=!0;break;case"outer":u=!0,s=!0;break;default:throw new Error('"how" must be one of the following strings: '+'"inner", "left", "right", "outer"')}if(!Ut(r)){var a=Pt.vector(Object.keys(r)),l=a.s(a.isIn(je).not());if(l.size()>0)throw new Error('invalid properties found int "opts": '+l.strJoin(", "));Ut(r.indicator)||(n=r.indicator),Ut(r.leftSuffix)||(i=r.leftSuffix),Ut(r.rightSuffix)||(o=r.rightSuffix)}var c=U(this,t,r),h=c.left,f=c.right,v=this.s(null,h),p=this.s(null,h.ex()),d=t.s(null,f),m=t.s(null,f.ex());if(v.dtypes().c("dtype").contains("object")||d.dtypes().c("dtype").contains("object"))throw new Error('key columns must not have "object" dtype');if(!v.dtypes().c("dtype").equals(d.dtypes().c("dtype")))throw new Error("key columns must have matching dtypes on left "+"and right");var y,g,b=p.names().s(p.names().isIn(m.names())),w=p.names().map(function(t){return b.contains(t)?t+i:t}),_=m.names().map(function(t){return b.contains(t)?t+o:t}),x=Pt.vCat(v.names(),w,_,n?["_join"]:[]),N=d._getIndex(),E=v.nRow(),O=ot(x.size());for(g=0;g<O.length;g++)O[g]=[];if(s)for(y=ot(d.nRow()),g=0;g<y.length;g++)y[g]=!0;for(g=0;E>g;g++){var j=N.lookup(v._cols,g);if(null===j)u&&K(O,v,p,m,g,null,"leftOnly");else if("number"==typeof j)K(O,v,p,m,g,j,"both"),s&&(y[j]=!1);else for(var A=0;A<j.length;A++){var C=j[A];K(O,v,p,m,g,C,"both"),s&&(y[C]=!1)}}if(s){var M=d.s(y),z=m.s(y);for(E=M.nRow(),g=0;E>g;g++)K(O,M,p,z,null,g,"rightOnly",!0)}return mt(O,x)},Pt.rng=function(t,e,r){if(r=Ut(r)?null:r,null!==r&&"boolean"!=typeof r)throw new Error('"includeStop" must be either true, false, or null');var n=Bt(t)&&Ft(e)||Ft(t)&&Bt(e);if(n&&null===r)throw new Error('"includeStop" must be set to either true or false '+"when mixing numbers and strings for start/stop");var i=Object.create(Zt);return i._start=t,i._stop=e,i._includeStop=r,i},Zt.ex=function(){return Pt.ex(this)};var Ae=Pt.vector(Object.keys(ne));Pt.byDtype=function(t){t=Vt(t),It(t,"string"),t=t.unique();var e=t.isIn(Ae);if(!e.all()){var r=t.s(e.not()).at(0);throw new Error('invalid dtype: ""'+r+'"')}var n=Object.create($t);return n._dtypes=t,n},$t.ex=function(){return Pt.ex(this)},Pt.ex=function(t){if(Ut(t))throw new Error('"selector" must not be undefined');var e=Object.create(te);return e._selector=t,e};var Ce={INT:"INT",COL:"COL",KEY:"KEY"};Yt._resolveSelectorHelper=function(t,e){var r,n,i="number"===this.dtype,o="string"===this.dtype;switch(t.resolveMode){case Ce.INT:if(!i)throw new Error("expected number vector for integer indexing "+'but got vector with dtype: "'+this.dtype+'"');for(r=0;r<this.values.length;r++)e.push($(this.values[r],t.maxLen));break;case Ce.COL:if(i)for(r=0;r<this.values.length;r++)e.push($(this.values[r],t.maxLen));else{if(!o)throw new Error("expected number or string vector for column "+'indexing but got vector with dtype: "'+this.dtype+'"');for(r=0;r<this.values.length;r++){var u=this.values[r];n=t.index.lookupKey([u]),tt(n,u,t,e)}}break;case Ce.KEY:if(1!==t.index.arity)throw new Error("unimplemented case (TODO)");var s=t.index.initVectors[0].dtype;if(this.dtype!==s)throw new Error('expected "'+s+'" vector for key '+'lookup but got vector with dtype: "'+this.dtype+'"');var a=[this];for(r=0;r<this.values.length;r++)n=t.index.lookup(a,r),tt(n,this.values[r],t,e);break;default:throw new Error("Unrecognized RESOLVE_MODE: "+t.resolveMode)}},Zt._resolveSelectorHelper=function(t,e){var r=Z(this._start,t,!1);if(!(r>=t.maxLen)){var n=Z(this._stop,t,!0,this._includeStop);if(!(0>=n)){r=0>r?0:r,n=n>t.maxLen?t.maxLen:n;for(var i=r;n>i;i++)e.push(i)}}},$t._resolveSelectorHelper=function(t,e){if(null===t.dtypes)throw new Error("ByDtype selector can only be used for column indexing");for(var r=t.dtypes.isIn(this._dtypes).which(),n=0;n<r.values.length;n++)e.push(r.values[n])},te._resolveSelectorHelper=function(t,e){var r=[];X(this._selector,t,r);for(var n=J(ut(r,"number"),t.maxLen),i=0;i<n.values.length;i++)e.push(n.values[i])},ee.lookup=function(t,e){throw new Error('abstract "lookup" method called without concrete '+"implementation")},ee.has=function(t){for(var e=t[0].size(),r=ot(e),n=0;e>n;n++)r[n]=null!==this.lookup(t,n);return ut(r,"boolean")},ee.valueCounts=function(){for(var t=this.initVectors,e=this.arity,r=this.size,n=ot(e),i=0;e>i;i++)n[i]=ot(r);for(var o=ot(r),u=t[0].size(),s=0,a=0;u>a;a++){var l=this.lookup(t,a);if(l===a||l[0]===a){for(i=0;e>i;i++)n[i][s]=t[i].values[a];o[s]=l===a?1:l.length,s++}}var c=n.map(function(e,r){return ut(e,t[r].dtype)});return{vectors:c,counts:ut(o,"number")}},ee.unique=function(){return this.valueCounts().vectors},ee.duplicated=function(t){Ut(t)&&(t="first");var e=!1,r=!1;if("first"===t)e=!0;else if("last"===t)r=!0;else if(t!==!1)throw new Error('"keep" must be either "first", "last", or false');for(var n=this.initVectors,i=n[0].size(),o=ot(i),u=0;i>u;u++)o[u]=!1;var s=e?1:0;for(u=0;i>u;u++){var a=this.lookup(n,u);if("number"!=typeof a&&a[0]===u)for(var l=a.length,c=r?l-1:l,h=s;c>h;h++)o[a[h]]=!0}return ut(o,"boolean")};var Me={"null":"_INTERNAL_JSDATAFRAME_NULL_KEY_",undefined:"_INTERNAL_JSDATAFRAME_UNDEFINED_KEY_"};Pt._private_export.newNestedIndex=nt,re.lookup=function(t,e){for(var r=this.arity,n=this._dtypes,i=this._map,o=0;r>o;o++){var u=t[o],s=rt(u.values[e],n[o]);if(i=i[s],Ut(i))return null}return i},re.lookupKey=function(t){for(var e=this.arity,r=this._dtypes,n=this._map,i=0;e>i;i++){var o=rt(t[i],r[i]);if(n=n[o],Ut(n))return null}return n},Pt._private_export.mapNonNa=st,Pt._private_export.reduceNonNa=at,Pt._private_export.reduceUnless=lt,Pt._private_export.combineArrays=ct,Pt._private_export.inferDtype=yt,Pt._private_export.inferVectorDtype=bt,Pt._private_export.coerceToNum=wt,Pt._private_export.coerceToBool=_t,Pt._private_export.coerceToStr=xt,Pt._private_export.coerceToDate=Nt;var ze={undefined:0,"null":1,NaN:2};Pt._private_export.compare=Ot;var Se=jt(Ot);Pt._private_export.reverseComp=jt,Pt._private_export.ensureVector=Vt}); | ||
| !function(t,e){"function"==typeof define&&define.amd?define(["exports"],e):e("object"==typeof exports&&"string"!=typeof exports.nodeName?exports:t.jsdataframe={})}(this,function(t){"use strict";function e(t){return String.fromCharCode(t)}function r(t,e,r){var n,i=r.size(),o=t.length-e,u=st(i);for(n=0;i>n;n++)u[n]=st(o);for(var s=0;o>s;s++){var a=t[s+e];if(a.length!==i)throw new Error("all row arrays must be of the same size");for(n=0;i>n;n++)u[n][s]=a[n]}return gt(u,r)}function n(t){return Jt.vector(t.values,t.dtype)}function i(t){return 0!==t&&Math.abs(t)<ye}function o(t){return Math.abs(t)>ge}function u(t){var e=t.nChar().max(),r=Jt.rep(" ",e).strJoin("");return t.map(function(t){return(r+t).slice(-r.length)})}function s(t,e){var r=Jt.seq(t)._toTruncatedPrintVector(e);return r.map(function(t){return t===we?t:t+_e})}function a(t){if(Ht(t))return"undefined";if(null===t)return"null";if(Number.isNaN(t))return"NaN";var e=Et(t),r=e.split("\n",2);return r.length>1&&(e=r[0]+"..."),e.length>pe&&(e=e.slice(0,pe-3)+"..."),e}function l(t,e,r){if("number"!=typeof t||Number.isNaN(t))throw new Error('"'+r+'" must be a number');if(e>t)throw new Error('"'+r+'" too small')}function c(t){var e=t.toString().split(".");return e.length>1?e[1].length:0}function h(t,e){e=Ht(e)?!0:e;var r=t.dtype;"date"===t.dtype&&(t=t.toDtype("number"));var n="number"!==t.dtype?t.values.slice():t.values.map(function(t){return Number.isNaN(t)?null:t}),i={dtype:r,values:n};return e&&(i.version=Jt.version,i.type=Gt.type),i}function f(t){return!ut(t)}function v(t,e,r,n){return ut(e)?n:e?t:r}function p(t,e){return 0===Ct(t,e)}function d(t,e){return Number.isNaN(t)&&Number.isNaN(e)||t===e}function m(t,e){return Ct(t,e)<0}function y(t,e){return Ct(t,e)>0}function g(t,e){return Number.isNaN(t)&&Number.isNaN(e)||Math.abs(t-e)<=1e-7}function b(t,e){return Ct(e,t)<0?e:t}function w(t,e){return Ct(e,t)>0?e:t}function _(t,e,r){var n=ut(e),i=ut(r);if(!n&&!i&&e>r)throw new Error("invalid range: lower ("+e+") > upper ("+r+")");return ut(t)?t:!n&&e>t?e:!i&&t>r?r:t}function x(t,e){return t+e}function N(t,e){return t-e}function E(t,e){return t*e}function O(t,e){return t/e}function j(t,e){return t%e}function C(t,e){return t.n++,t.sum+=e,t}function A(t,e){t.n++;var r=e-t.mean;return t.mean+=r/t.n,t.M2+=r*(e-t.mean),t}function z(t,e){return t===!1||e===!1?!1:null===t||null===e?null:!0}function M(t,e){return t===!0||e===!0?!0:null===t||null===e?null:!1}function S(t){return!t}function k(t,e){return null===t||null===e?null:t!==e}function I(t,e){return+t+ +e}function R(t){return t.length}function V(t,e,r){return null===t?null:t.includes(e,r)}function q(t,e,r){return null===t?null:t.startsWith(e,r)}function L(t,e,r){return null===t?null:t.endsWith(e,r)}function T(t,e,r){return null===t?NaN:t.indexOf(e,r)}function D(t,e,r){return null===t?NaN:t.lastIndexOf(e,r)}function F(t,e){return null===t?NaN:t.search(e)}function B(t,e){return null===e||null===t?null:e.test(t)}function W(t){return null===t?null:t.toLowerCase()}function K(t){return null===t?null:t.toUpperCase()}function U(t){return function(){var e=t.apply(null,arguments);if(null===e)return e;var r=this[e];return Ht(r)&&(this[e]=e,r=e),r}}function P(t,e,r,n,i,o,u,s){var a,l,c=s?o:i,h=0;for(l=e.nCol(),a=0;l>a;a++)t[h].push(e._cols[a].values[c]),h++;for(l=r.nCol(),a=0;l>a;a++){var f=null===i?null:r._cols[a].values[i];t[h].push(f),h++}for(l=n.nCol(),a=0;l>a;a++){var v=null===o?null:n._cols[a].values[o];t[h].push(v),h++}h<t.length&&t[h].push(u)}function Y(t,e,r){var n,i;if(Ht(r)||Ht(r.by)&&Ht(r.leftBy)&&Ht(r.rightBy)){var o=t.names().s(t.names().isIn(e.names()));if(o.nUnique()!==o.size())throw new Error("duplicate names found for key columns");n=J(o,t._names,t._dtypesVector()),i=J(o,e._names,e._dtypesVector())}else if(Ht(r.by)){if(Ht(r.leftBy)||Ht(r.rightBy))throw new Error("must specify both opts.leftBy and "+"opts.rightBy together");n=J(r.leftBy,t._names,t._dtypesVector()),i=J(r.rightBy,e._names,e._dtypesVector())}else{if(!Ht(r.leftBy)||!Ht(r.rightBy))throw new Error("cannot define opts.by, opts.leftBy, and "+"opts.rightBy all together");if(null!==r.by&&"object"==typeof r.by&&r.by.type!==Gt.type){var u=Object.keys(r.by),s=u.map(function(t){return r.by[t]});n=J(u,t._names,t._dtypesVector()),i=J(s,e._names,e._dtypesVector())}else{var a=Bt(r.by,"string");if(n=J(a,t._names,t._dtypesVector()),i=J(a,e._names,e._dtypesVector()),a.size()!==n.size())throw new Error("duplicate names found for key columns")}}if(yt(n),yt(i),n.size()!==i.size())throw new Error("must select the same number of key columns on the "+"left and right side; instead got "+n.size()+", "+i.size());if(0===n.size()||0===i.size())throw new Error("must select at least one key column to join by");return{left:n,right:i}}function H(t,e){if(Ht(t)||null===t)return null;var r=G(t,e);if(!Ht(r))return r;var n=X(Se.INT,e);return Z(t,n)}function J(t,e,r){if(Ht(t)||null===t)return null;var n=e.size(),i=G(t,n);if(!Ht(i))return i;var o=X(Se.COL,n,e._getIndex(),r);return Z(t,o)}function G(t,e){if(t.type===ne.type){var r=G(t._selector,e);return Ht(r)?void 0:Q(r,e)}if(Array.isArray(t)&&(t=_t(t.slice(),"object")),t.type===Gt.type&&"boolean"===t.dtype){if(t.size()!==e)throw new Error("inappropriate boolean indexer length ("+t.size()+"); expected length to be "+e);return t.which()}}function Q(t,e){return Jt.seq(e).isIn(t).not().which()}function X(t,e,r,n){return r=Ht(r)?null:r,n=Ht(n)?null:n,{resolveMode:t,maxLen:e,index:r,dtypes:n}}function Z(t,e){var r=[];return $(t,e,r),at(r,"number")}function $(t,e,r){if(null!==t&&"object"==typeof t){if("function"==typeof t._resolveSelectorHelper)return void t._resolveSelectorHelper(e,r);if(Array.isArray(t)){for(var n=0;n<t.length;n++)$(t[n],e,r);return}}var i;switch(e.resolveMode){case Se.INT:r.push(et(t,e.maxLen));break;case Se.COL:if(Kt(t))r.push(et(t,e.maxLen));else{if(!Pt(t)&&null!==t)throw new Error("expected integer or string selector but got: "+t);i=e.index.lookupKey([t]),rt(i,t,e,r)}break;case Se.KEY:if(1!==e.index.arity)throw new Error("unimplemented case (TODO)");var o=e.index.initVectors[0].dtype;Rt(t,o),i=e.index.lookupKey([t]),rt(i,t,e,r);break;default:throw new Error("Unrecognized RESOLVE_MODE: "+e.resolveMode)}}function tt(t,e,r,n){var i;if(Ht(t))return r?e.maxLen:0;var o=e.resolveMode===Se.INT||e.resolveMode===Se.COL&&"number"==typeof t;if(null===n&&(n=!o),o)return i=et(t,e.maxLen,!1),r&&n?i+1:i;if(1===e.index.arity){if(i=e.index.lookupKey([t]),null===i)throw new Error("could not find entry for range bound: "+t);return"number"==typeof i?r&&n?i+1:i:r&&n?i[i.length-1]+1:i[0]}throw new Error("unimplemented case (TODO)")}function et(t,e,r){if(Ht(r)&&(r=!0),!Number.isInteger(t))throw new Error("expected integer selector for integer indexing "+"but got non-integer: "+t);var n=0>t?e+t:t;if(r&&(0>n||n>=e))throw new Error("integer index out of bounds");return n}function rt(t,e,r,n){if(null===t)throw r.resolveMode===Se.COL?new Error('could not find column named "'+e+'"'):new Error("could find entry for key: "+e);if("number"==typeof t)n.push(t);else for(var i=0;i<t.length;i++)n.push(t[i])}function nt(t,e){if(Ht(t))throw new Error("selector must not be undefined");if(t=Ft(t),Kt(t))return et(t,e.values.length);if(Pt(t)||null===t){var r=e._getIndex().lookupKey([t]);if(null===r)throw new Error("invalid column name: "+t);return"number"!=typeof r&&(r=r[0]),r}throw new Error("column selector must be an integer or string")}function it(t,e){return null===t?ke["null"]:Ht(t)?ke.undefined:"date"===e?t.valueOf():t}function ot(t){var e=t.length;if(0===e)throw new Error("cannot index an empty list of vectors");var r=t[0].size(),n=Object.create(oe);n.initVectors=t,n.size=0,n.arity=e,n._dtypes=t.map(function(t){return t.dtype}),n._map=Object.create(null);for(var i=n._map,o=e-1,u=0;r>u;u++){for(var s,a,l=i,c=0;o>c;c++){s=t[c],a=it(s.values[u],s.dtype);var h=l[a];Ht(h)&&(l[a]=h=Object.create(null)),l=h}s=t[o],a=it(s.values[u],s.dtype);var f=l[a];Ht(f)?(l[a]=u,n.size++):"number"==typeof f?l[a]=[f,u]:f.push(u)}return n}function ut(t){return null===t||Ht(t)||Number.isNaN(t)}function st(t){return 64e3>t?new Array(t):[]}function at(t,e){Mt(e);var r=ae[e],n=Object.create(r);return n._init(t),n}function lt(t,e,r){for(var n=t.length,i=st(n),o=0;n>o;o++){var u=t[o];i[o]=ut(u)?e:r(u)}return i}function ct(t,e,r){for(var n=e,i=0;i<t.length;i++){var o=t[i];ut(o)||(n=r(n,o))}return n}function ht(t,e,r,n){for(var i=e,o=0;o<t.length;o++){var u=t[o];if(r(u))return u;i=n(i,u)}return i}function ft(t,e,r,n){var i=!0;Ht(n)&&(n=r,i=!1);for(var o=t.length,u=e.length,s=Dt(o,u),a=1===o,l=1===u,c=st(s),h=0;s>h;h++){var f=a?t[0]:t[h],v=l?e[0]:e[h];i&&(ut(f)||ut(v))?c[h]=r:c[h]=n(f,v)}return c}function vt(t,e,r){if(0===t.length)throw new Error("cannot combine an empty list of arrays");r=Ht(r)?null:r;var n,i=t.length,o=st(i),u=1;for(n=0;i>n;n++)if(1===t[n].length)o[n]=!0;else if(o[n]=!1,1===u)u=t[n].length;else if(u!==t[n].length)throw new Error("length mismatch: expected "+u+" elements but found "+t[n].length);for(var s=st(u),a=st(i),l=0;u>l;l++){for(n=0;i>n;n++)a[n]=o[n]?t[n][0]:t[n][l];s[l]=e.apply(r,a)}return s}function pt(t,e,r){var n=!1;Ht(r)&&(r=e,n=!0);for(var i=t.length,o=st(i),u=null,s=!1,a=0;i>a;a++){var l=t[a];if(ut(l)){if(o[a]=l,!n){for(var c=a+1;i>c;c++)o[c]=e;break}}else u=s?r(u,l):l,s=!0,o[a]=u}return o}function dt(t,e){for(var r=st(e.length),n=0;n<e.length;n++)r[n]=t[e[n]];return r}function mt(t){return Jt.strCat("c",Jt.seq(t))}function yt(t){if(t.nUnique()!==t.values.length)throw new Error("duplicate occurrence of one or more columns "+"in selection")}function gt(t,e,r){var n,i=t.length;if(r=Ht(r)?!0:r){var o=1;for(n=0;i>n;n++){t[n]=Bt(t[n]);var u=t[n].values.length;if(1!==u)if(1===o)o=u;else if(u!==o)throw new Error("incompatible column lengths found during "+"data frame construction: "+o+", "+u)}if(1!==o)for(n=0;i>n;n++)if(1===t[n].values.length){for(var s=t[n].values[0],a=st(o),l=0;o>l;l++)a[l]=s;t[n]=at(a,t[n].dtype)}}var c=null;if(i>0)for(c=t[0].dtype,n=1;i>n;n++)if(t[n].dtype!==c){c=null;break}var h=Object.create(te);return h._cols=t,h._names=e,h._index=null,h.allDtype=c,h}function bt(t){return null===t||Ht(t)?null:Kt(t)?"number":Ut(t)?"boolean":Pt(t)?"string":Yt(t)?"date":"object"}function wt(t,e){Mt(e);for(var r=le[e],n=0;n<t.length;n++)t[n]=r(t[n]);return at(t,e)}function _t(t,e){Ht(e)&&(e="object");for(var r=null,n=0;n<t.length;n++){var i=bt(t[n]);if(null!==i&&(null===r&&(r=i),r!==i||"object"===i))return at(t,"object")}var o;if(null===r){if(r=e,"object"!==r)for(o=se[r],n=0;n<t.length;n++)t[n]=o;return at(t,r)}if("object"!==r)for(o=se[r],n=0;n<t.length;n++)ut(t[n])&&(t[n]=o);return at(t,r)}function xt(t){return ut(t)?se.number:+t}function Nt(t){return ut(t)?se["boolean"]:!!t}function Et(t){return ut(t)?se.string:"object"!=typeof t?t.toString():Yt(t)?t.toISOString():t.toString()}function Ot(t){if(ut(t))return se.date;var e=new Date(t);return Number.isNaN(e.getTime())?null:e}function jt(t){return null===t?"null":Ht(t)?"undefined":"object"!=typeof t?t.toString():Yt(t)?t.toISOString():t.toString()}function Ct(t,e){var r=ut(t),n=ut(e);if(r&&n)t=Ie[t],e=Ie[e];else{if(r)return-1;if(n)return 1}return e>t?-1:t>e?1:0}function At(t){return function(e,r){return-t(e,r)}}function zt(t,e){if(t.length!==e.length)throw new Error('length of "ascending" must match the number of '+"sort columns");if(0===t.length)return null;for(var r=t[0].size(),n=st(r),i=0;r>i;i++)n[i]=i;var o=e.map(function(t){return t?Ct:Re}),u=function(e,r){for(var n=0,i=0;i<o.length;i++){var u=t[i].values[e],s=t[i].values[r];if(n=o[i](u,s),0!==n)return n}return Ct(e,r)};return n.sort(u),n}function Mt(t){if(!(t in ue))throw new Error('invalid dtype: "'+t+'"')}function St(t,e){if(!Number.isInteger(t))throw new Error('expected an integer for "'+e+'" but got: '+t)}function kt(t,e){if(!Number.isInteger(t)||0>t)throw new Error('"'+e+'" must be a nonnegative integer')}function It(t,e){if("function"!=typeof t)throw new Error('"'+e+'" must be a function')}function Rt(t,e){var r=bt(t);if(null!==r&&r!==e)throw new Error('expected scalar to match dtype "'+e+'" but instead got '+t+', which has dtype "'+r+'"')}function Vt(t,e){if(t.dtype!==e)throw new Error('expected vector dtype to be "'+e+'" but got "'+t.dtype+'"')}function qt(t,e){if(t.dtype===e)throw new Error('unsupported operation for dtype "'+e+'"')}function Lt(t){if(t._dtypesVector().contains("object"))throw new Error("unsupported operation over data frame columns "+'with "object" dtype')}function Tt(t,e){var r=Bt(e),n=Jt.vector(Object.keys(t),"string"),i=n.s(n.isIn(r).not());if(i.size()>0)throw new Error('invalid properties found in "opts": '+i.strJoin(", "))}function Dt(t,e){var r=t;if(t!==e)if(1===t)r=e;else if(1!==e)throw new Error("incompatible array lengths: "+t+" and "+e);return r}function Ft(t){if(Ht(t)||null===t)return t;var e=1,r="a scalar";if(t.type===Gt.type?(e=t.size(),t=t.values[0],r="a vector"):Array.isArray(t)&&(e=t.length,t=t[0],r="an array"),1!==e)throw new Error("expected a single scalar value but got "+r+" of length "+e);return t}function Bt(t,e){return(ut(t)||t.type!==Gt.type)&&(t=Array.isArray(t)?_t(t.slice(),e):_t([t],e)),t}function Wt(t){return t=Bt(t,"string"),"string"!==t.dtype?t.toDtype("string"):t}function Kt(t){return"number"==typeof t}function Ut(t){return"boolean"==typeof t}function Pt(t){return"string"==typeof t}function Yt(t){return"[object Date]"===Object.prototype.toString.call(t)}function Ht(t){return"undefined"==typeof t}var Jt=t;Jt.version="0.2.0",Number.isNaN=Number.isNaN||function(t){return t!==t},Number.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},Array.prototype.findIndex||(Array.prototype.findIndex=function(t){if(null===this)throw new TypeError("Array.prototype.findIndex called on null or undefined");if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var e,r=Object(this),n=r.length>>>0,i=arguments[1],o=0;n>o;o++)if(e=r[o],t.call(i,e,o,r))return o;return-1}),String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),e+t.length>this.length?!1:this.indexOf(t,e)!==-1}),String.prototype.startsWith||(String.prototype.startsWith=function(t,e){return e=e||0,this.substr(e,t.length)===t}),String.prototype.endsWith||(String.prototype.endsWith=function(t,e){var r=this.toString();("number"!=typeof e||!isFinite(e)||Math.floor(e)!==e||e>r.length)&&(e=r.length),e-=t.length;var n=r.indexOf(t,e);return n!==-1&&n===e});var Gt={};Gt.type="jsdataframe.Vector";var Qt=Object.create(Gt),Xt=Object.create(Gt),Zt=Object.create(Gt),$t=Object.create(Gt),te={};te.type="jsdataframe.DataFrame";var ee={};ee.type="jsdataframe.Range";var re={};re.type="jsdataframe.ByDtype";var ne={};ne.type="jsdataframe.Exclusion";var ie={};ie.type="jsdataframe.AbstractIndex";var oe=Object.create(ie);oe.type="jsdataframe.NestedIndex";var ue=Object.create(null);ue.number=!0,ue["boolean"]=!0,ue.string=!0,ue.date=!0,ue.object=!0;var se={number:NaN,"boolean":null,string:null,date:null,object:null},ae={number:Qt,"boolean":Xt,string:Zt,date:$t,object:Gt},le={number:xt,"boolean":Nt,string:Et,date:Ot,object:function(t){return t}};Jt._private_export={},Jt.vector=function(t,e,r){if(!Array.isArray(t))throw new Error('"array" argument must be an Array');return(Ht(r)||r)&&(t=t.slice()),Ht(e)&&(e=null),null===e?_t(t):wt(t,e)},Jt.seq=function(t,r,n,i){if(1===arguments.length){if(!Kt(t))throw new Error('both "start" and "stop" arguments must be '+"specified for non-numeric sequences");r=t,t=0}else if(bt(t)!==bt(r))throw new Error('"start" and "stop" must have the same dtype');if(n=Ht(n)?1:n,i=Ht(i)?!1:i,Pt(t)){if(1!==t.length||1!==r.length)throw new Error('both "start" and "stop" must be single characters '+"for character sequences");var o=Jt.seq(t.charCodeAt(0),r.charCodeAt(0),n,i);return o.map(e)}if(0===n)throw new Error('"step" must be nonzero');if(r>t&&0>n)throw new Error('"step" must be positive when start < stop');if(t>r&&n>0)throw new Error('"step" must be negative when start > stop');for(var u=[],s=t;n>0?i?r>=s:r>s:i?s>=r:s>r;)u.push(s),s+=n;return at(u,"number")},Jt.seqOut=function(t,r,n){if(arguments.length<3&&(n=1),n=+n,kt(r,"lengthOut"),Pt(t)){if(1!==t.length)throw new Error('"start" must be a single character '+"for character sequences");var i=Jt.seqOut(t.charCodeAt(0),r,n);return i.map(e)}for(var o=st(r),u=t,s=0;r>s;s++)o[s]=u,u+=n;return at(o,"number")},Jt.linspace=function(t,e,r){t=+t,e=+e,kt(r,"length");for(var n=st(r),i=1===r?0:(e-t)/(r-1),o=0;r>o;o++)n[o]=t+o*i;return at(n,"number")},Jt.rep=function(t,e){kt(e,"times"),t=Bt(t);for(var r=t.values,n=r.length,i=st(n*e),o=0;e>o;o++)for(var u=o*n,s=0;n>s;s++)i[u+s]=r[s];return at(i,t.dtype)},Jt.repEach=function(t,e){kt(e,"times"),t=Bt(t);for(var r=t.values,n=r.length,i=st(n*e),o=0;n>o;o++)for(var u=o*e,s=0;e>s;s++)i[u+s]=r[o];return at(i,t.dtype)},Jt.repNa=function(t,e){kt(t,"times"),Mt(e);for(var r=se[e],n=st(t),i=0;t>i;i++)n[i]=r;return at(n,e)},Jt.df=function(t,e){Ht(e)||(e=Wt(e));var r;if(t.type===Gt.type)throw new Error('"columns" should not itself be a vector');if(Array.isArray(t)){if(r=t.length,Ht(e))e=mt(r);else if(e.size()!==r)throw new Error('the length of "colNames" ('+e.size()+') does not match the length of "columns" ('+r+")")}else{if("object"!=typeof t)throw new Error('expected "columns" to be an array or object but got: ',t);var n=Object.keys(t);r=n.length;var i=t;if(Ht(e))e=at(n,"string");else{if(e.isNa().any())throw new Error('"colNames" cannot have null entries when '+'"columns" is an object');if(e.duplicated().any())throw new Error('"colNames" cannot have duplicate entries when '+'"columns" is an object');if(e.size()!==r||e.isIn(n).not().any())throw new Error('"colNames" must match all the keys in '+'"columns" if "columns" is an object')}t=st(r);for(var o=0;r>o;o++)t[o]=i[e.values[o]]}return gt(t,e)},Jt.dfFromObjArray=function(t,e){if(!Array.isArray(t))throw new Error('"objArray" must be an array');var r,n,i=t.length,o=!0;if(Ht(e))e=[],n=[],o=!1;else{if(e=Wt(e),e.isNa().any())throw new Error('"colOrder" cannot have null entries');if(e.duplicated().any())throw new Error('"colOrder" cannot have duplicate entries');for(e=e.values,n=st(e.length),r=0;r<e.length;r++)n[r]=st(i)}for(var u=Object.create(null),s=0;i>s;s++){var a=t[s];if(!o){var l=Object.keys(a);for(r=0;r<l.length;r++){var c=l[r];if(!(c in u)){e.push(c);for(var h=st(i),f=0;s>f;f++)h[f]=null;n.push(h),u[c]=c}}}for(r=0;r<e.length;r++)n[r][s]=a.propertyIsEnumerable(e[r])?a[e[r]]:null}return gt(n,at(e,"string"))},Jt.dfFromMatrix=function(t,e){if(!Array.isArray(t))throw new Error('"matrix" must be an array');var n=t.length>0?t[0].length:0;if(e=Ht(e)?mt(n):Wt(e),n>0&&n!==e.size())throw new Error('"colNames" must have the same length as each '+"row array");return r(t,0,e)},Jt.dfFromMatrixWithHeader=function(t){if(!Array.isArray(t))throw new Error('"matrix" must be an array');if(0===t.length)throw new Error('"matrix" must not have length 0');var e=Wt(t[0]);if(t.length>1&&e.size()!==t[1].length)throw new Error("header row must have the same length as other "+"row arrays");return r(t,1,e)},Jt.unpack=function(t){if(t.type===Gt.type)return n(t);if(t.type===te.type){var e=n(t.names),r=t.cols.map(function(t){return n(t)});return Jt.df(r,e)}throw new Error('"obj" has unrecognized type: '+t.type)},Jt.vCat=function(){for(var t=arguments.length,e=st(t),r=null,n=0,i=0;t>i;i++){var o=arguments[i];if(!Ht(o)&&null!==o&&o.type===te.type)throw new Error("cannot pass data frame arguments to jd.vCat");var u=Bt(o);null===r&&"object"!==u.dtype&&(r=u.dtype),n+=u.size(),e[i]=u}r=null===r?"object":r;var s=st(n),a=0;for(i=0;t>i;i++)for(var l=e[i].values,c=l.length,h=0;c>h;h++)s[a]=l[h],a++;return _t(s,r)},Jt.colCat=function(){for(var t=arguments.length,e=st(t),r=0;t>r;r++)e[r]=arguments[r];return Jt._colCatArray(e)},Jt._colCatArray=function(t){for(var e,r=t.length,n=[],i=[],o=0;r>o;o++){var u=t[o];if(Ht(u)||null===u)n.push(u),i.push(null);else if(u.type===te.type){var s=u._cols.length;for(e=0;s>e;e++)n.push(u._cols[e]),i.push(u._names.values[e])}else if("object"!=typeof u||u.type===Gt.type||Array.isArray(u))n.push(u),i.push(null);else{var a=Object.keys(u);for(e=0;e<a.length;e++){var l=a[e];n.push(u[l]),i.push(l)}}}return gt(n,at(i,"string"))},Jt.rowCat=function(){for(var t=arguments.length,e=st(t),r=0;t>r;r++)e[r]=arguments[r];return Jt._rowCatArray(e)};var ce={SCALAR:0,ARRAY:1,VECTOR:2,DATA_FRAME:3};Jt._rowCatArray=function(t){var e,r,n,i=t.length,o=st(i),u=null,s=0,a=-1;for(r=0;i>r;r++){e=t[r];var l;if(Ht(e)||null===e||"object"!=typeof e)o[r]=ce.SCALAR,s++,l=a;else if(e.type===te.type){if(o[r]=ce.DATA_FRAME,l=e.nCol(),0===l)continue;if(s+=e.nRow(),null===u)u=e._names.values.slice();else{var c=Math.min(u.length,l),h=e._names.values;for(n=0;c>n;n++)h[n]!==u[n]&&(u[n]=null)}}else e.type===Gt.type?(o[r]=ce.VECTOR,s++,l=e.values.length):Array.isArray(e)?(o[r]=ce.ARRAY,s++,l=e.length):(o[r]=ce.SCALAR,s++,l=a);if(a===-1)a=l;else if(a!==l)throw new Error("arguments imply differing number of columns: "+a+", "+l)}if(0===s)return Jt.df([]);a===-1&&(a=1);var f=null===u?Jt.repNa(a,"string"):at(u,"string"),v=st(a);for(n=0;a>n;n++)v[n]=st(s);var p=0;for(r=0;i>r;r++)switch(e=t[r],o[r]){case ce.SCALAR:for(n=0;a>n;n++)v[n][p]=e;p++;break;case ce.VECTOR:e=e.values;case ce.ARRAY:for(n=0;a>n;n++)v[n][p]=e[n];p++;break;case ce.DATA_FRAME:var d=e.nRow();for(n=0;a>n;n++)for(var m=0;d>m;m++)v[n][p+m]=e._cols[n].values[m];p+=d}return gt(v,f)},Jt.strCat=function(){var t=arguments.length;if(0===t)throw new Error('"strCat" must be called with at least one argument');for(var e=st(t),r=0;t>r;r++)e[r]=Bt(arguments[r]).values;var n=Object.create(null),i=vt(e,he,n);return at(i,"string")};var he=U(function(){for(var t=arguments.length,e=st(t),r=0;t>r;r++){var n=arguments[r];if(ut(n))return null;e[r]=jt(n)}return e.join("")}),fe=55,ve=4,pe=45,de=6,me=6,ye=Math.pow(10,1-de),ge=1e7-1e-9,be=" ",we="..",_e=":";Jt.printingOpts={},Jt.printingOpts._maxWidth=79,Jt.printingOpts._maxLines=10,Jt.printingOpts._printCallback=function(t){console.log(t)},Jt.printingOpts.getMaxWidth=function(){return this._maxWidth},Jt.printingOpts.setMaxWidth=function(t){l(t,fe,"maxWidth"),this._maxWidth=t},Jt.printingOpts.getMaxLines=function(){return this._maxLines},Jt.printingOpts.setMaxLines=function(t){l(t,ve,"maxLines"),this._maxLines=t},Jt.printingOpts.setPrintFunction=function(t){It(t,"callback"),this._printCallback=t},Gt.p=function(t){var e=this.printToString(t);Jt.printingOpts._printCallback(e)},Gt.printToString=function(t){if(Ht(t)?t=Jt.printingOpts._maxLines:l(t,ve,"maxLines"),0===this.values.length)return this.toString();var e=u(s(this.values.length,t)),r=u(this._toTruncatedPrintVector(t)),n=Jt.strCat(e,be,r);return this.toString()+"\n"+n.strJoin("\n")},te.p=function(t){var e=this.printToString(t);Jt.printingOpts._printCallback(e)},te.printToString=function(t){Ht(t)?t=Jt.printingOpts._maxLines:l(t,ve,"maxLines");for(var e=u(Jt.vCat("",s(this.nRow(),t))),r=[e],n=0,i=e.at(0).length,o=Jt.printingOpts._maxWidth-we.length-be.length;o>=i&&n<this.nCol();){var c=this._cols[n]._toTruncatedPrintVector(t),h=u(Jt.vCat(a(this._names.at(n)),c));r.push(be),r.push(h),i+=be.length+h.at(0).length,n++}i>o&&(r.pop(),r.push(we));var f=Jt.strCat.apply(Jt,r);return this.toString()+"\n"+f.strJoin("\n")},Gt._toTruncatedPrintVector=function(t){if(this.values.length>t){var e=Math.ceil(t/2-1),r=Jt.rng(0,e),n=Jt.rng(-e),i=this.s([r,n])._toPrintVector();return Jt.vCat(i.s(r),we,i.s(n))}return this._toPrintVector()},Gt._toPrintVector=function(){return this.map(a)},Qt._toPrintVector=function(){if(this.values.some(i)||this.values.some(o))return this.map(function(t){return t.toExponential(me)});var t=Math.min(de,this.map(c).max());return this.map(function(e){return e.toFixed(t)})},Jt._private_export.toPrintString=a,Jt._private_export.fractionDigits=c,Gt.dtype="object",Gt._init=function(t){this.values=t,this._index=null},Gt.size=function(){return this.values.length},Gt.toString=function(){return"Vector[dtype:"+this.dtype+", size:"+this.values.length+"]"},Gt.toArray=function(){return this.values.slice()},Gt.toDtype=function(t){if(this.dtype===t)return this;if("string"===t){var e=Object.create(null),r=vt([this.values],xe,e);return at(r,"string")}return Jt.vector(this.values,t)};var xe=U(Et);Gt.pack=function(){return h(this)},Gt.isNa=function(){return at(this.values.map(ut),"boolean")},Gt.dropNa=function(){return this.filter(f)},Gt.replaceNa=function(t){var e=le[this.dtype];t=e(t);for(var r=this.values.slice(),n=0;n<r.length;n++)ut(r[n])&&(r[n]=t);return at(r,this.dtype)},Gt.s=function(t){var e=H(t,this.values.length);if(null===e)return this;var r=dt(this.values,e.values);return at(r,this.dtype)},Gt.sMod=function(t,e){var r=H(t,this.values.length);null===r&&(r=Jt.seq(this.values.length)),e=Bt(e,this.dtype),Vt(e,this.dtype);var n=1===e.size();if(!n&&e.size()!==r.size())throw new Error("length mismatch: cannot assign "+e.size()+" values to a selection of length "+r.size());for(var i=r.values,o=this.values.slice(),u=0;u<i.length;u++)o[i[u]]=n?e.values[0]:e.values[u];return at(o,this.dtype)},Gt.at=function(t){return t=Ft(t),t=et(t,this.size()),this.values[t]},Gt.head=function(t){return Ht(t)&&(t=6),St(t,"n"),this.s(Jt.rng(0,t))},Gt.tail=function(t){Ht(t)&&(t=6),St(t,"n");var e=0>t?-t:this.size()-t;return this.s(Jt.rng(e,void 0))},Gt.ifElse=function(t,e){if(t=Bt(t,"boolean"),t.size()!==this.size())throw new Error('"cond" must be the same length as this vector');Vt(t,"boolean"),e=Bt(e,this.dtype),Vt(e,this.dtype);var r=vt([this.values,t.values,e.values,[se[this.dtype]]],v);return at(r,this.dtype)},Gt.ex=function(){return Jt.ex(this)},Gt.map=function(){var t=Array.prototype.map.apply(this.values,arguments);return _t(t,this.dtype)},Gt.reduce=function(){return Array.prototype.reduce.apply(this.values,arguments)},Gt.reduceRight=function(){return Array.prototype.reduceRight.apply(this.values,arguments)},Gt.findIndex=function(){return Array.prototype.findIndex.apply(this.values,arguments)},Gt.indexOf=function(t){if("object"===this.dtype)return this.values.indexOf(t);var e=this._getIndex().lookupKey([t]);return null===e?-1:"number"==typeof e?e:e[0]},Gt.sort=function(t){Ht(t)&&(t=Ct);var e=this.values.slice();return Array.prototype.sort.call(e,t),at(e,this.dtype)},Gt.reverse=function(){var t=this.values.slice();return Array.prototype.reverse.call(t),at(t,this.dtype)},Gt.filter=function(){var t=Array.prototype.filter.apply(this.values,arguments);return at(t,this.dtype)},Gt.strJoin=function(t){return this.values.map(jt).join(t)},Gt.combine=function(){var t=arguments.length;if(2>t)throw new Error('must supply at least one "varg"');var e=arguments[t-1];if("function"!=typeof e)throw new Error('the last argument to "combine" must be a function');var r=st(t);r[0]=this.values;for(var n=1;t>n;n++)r[n]=Bt(arguments[n-1]).values;var i=vt(r,e);return Jt.vector(i)},Gt.eq=function(t){t=Bt(t,this.dtype);var e=Dt(this.size(),t.size());if(this.dtype!==t.dtype)return Jt.repNa(e,"boolean");var r="object"===this.dtype?ft(this.values,t.values,null,d):ft(this.values,t.values,null,p);return at(r,"boolean")},Gt.neq=function(t){return this.eq(t).not()},Gt.lt=function(t){t=Bt(t,this.dtype);var e=Dt(this.size(),t.size());if(this.dtype!==t.dtype)return Jt.repNa(e,"boolean");var r=ft(this.values,t.values,null,m);return at(r,"boolean")},Gt.gt=function(t){t=Bt(t,this.dtype);var e=Dt(this.size(),t.size());if(this.dtype!==t.dtype)return Jt.repNa(e,"boolean");var r=ft(this.values,t.values,null,y);return at(r,"boolean")},Gt.lte=function(t){return this.lt(t).or(this.eq(t))},Gt.gte=function(t){return this.gt(t).or(this.eq(t))},Gt.between=function(t,e,r){throw new Error("unimplemented method (TODO)")},Gt.equals=function(t,e){if(ut(t)||t.type!==Gt.type||this.size()!==t.size()||this.dtype!==t.dtype)return!1;if(this===t)return!0;var r=p;"number"===this.dtype?r=Ht(e)?g:function(t,r){return Number.isNaN(t)&&Number.isNaN(r)||Math.abs(t-r)<=e}:"object"===this.dtype&&(r=d);for(var n=this.values,i=t.values,o=0;o<n.length;o++)if(!r(n[o],i[o]))return!1;return!0},Gt.min=function(t){var e=this.idxMin(t);return Number.isNaN(e)?se[this.dtype]:this.values[e]},Gt.max=function(t){var e=this.idxMax(t);return Number.isNaN(e)?se[this.dtype]:this.values[e]},Gt.cuMin=function(t){Ht(t)&&(t=!0);var e=t?pt(this.values,b):pt(this.values,se[this.dtype],b);return at(e,this.dtype)},Gt.cuMax=function(t){Ht(t)&&(t=!0);var e=t?pt(this.values,w):pt(this.values,se[this.dtype],w);return at(e,this.dtype)},Gt.idxMin=function(t){Ht(t)&&(t=!0);for(var e=this.values,r=NaN,n=null,i=0;i<e.length;i++){var o=e[i];if(ut(o)){if(!t)return NaN}else(Ct(o,n)<0||Number.isNaN(r))&&(n=o,r=i)}return r},Gt.idxMax=function(t){Ht(t)&&(t=!0);for(var e=this.values,r=NaN,n=null,i=0;i<e.length;i++){var o=e[i];if(ut(o)){if(!t)return NaN}else(Ct(o,n)>0||Number.isNaN(r))&&(n=o,r=i)}return r},Gt.pMin=function(t){t=Bt(t,this.dtype),Vt(t,this.dtype);var e=ft(this.values,t.values,se[this.dtype],b);return at(e,this.dtype)},Gt.pMax=function(t){t=Bt(t,this.dtype),Vt(t,this.dtype);var e=ft(this.values,t.values,se[this.dtype],w);return at(e,this.dtype)},Gt.clip=function(t,e){t=Bt(t,this.dtype),e=Bt(e,this.dtype),Vt(t,this.dtype),Vt(e,this.dtype);var r=vt([this.values,t.values,e.values],_);return at(r,this.dtype)},Gt.rank=function(){throw new Error("unimplemented method (TODO)")},Gt.contains=function(t){qt(this,"object"),t=Ft(t);var e=bt(t);if(e!==this.dtype&&null!==e)throw new Error('"value" does not match the dtype of this vector');return null!==this._getIndex().lookupKey([t])},Gt.isIn=function(t){return qt(this,"object"),t=Bt(t,this.dtype),Vt(t,this.dtype),t._getIndex().has([this])},Gt.valueCounts=function(){qt(this,"object");var t=this._getIndex().valueCounts(),e=Jt.df([t.vectors[0],t.counts],["value","count"]);return e.sort(["count","value"],[!1,!0])},Gt.unique=function(){return qt(this,"object"),this._getIndex().unique()[0]},Gt.nUnique=function(){return qt(this,"object"),this._getIndex().size},Gt.duplicated=function(t){return qt(this,"object"),this._getIndex().duplicated(t)},Gt.replace=function(){throw new Error("unimplemented method (TODO)")},Gt.describe=function(){throw new Error("unimplemented method (TODO)")},Gt._getIndex=function(){return null===this._index&&(this._index=ot([this])),this._index},Gt.union=function(t){return qt(this,"object"),t=Bt(t,this.dtype),Vt(t,this.dtype),Jt.vCat(this,t).unique()},Gt.intersect=function(t){qt(this,"object"),t=Bt(t,this.dtype),Vt(t,this.dtype);var e=this.unique();return e.s(e.isIn(t))},Gt.setdiff=function(t){qt(this,"object"),t=Bt(t,this.dtype),Vt(t,this.dtype);var e=this.unique();return e.s(e.isIn(t).ex())},Qt.dtype="number",Qt.add=function(t){t=Bt(t,"number"),Vt(t,"number");var e=ft(this.values,t.values,NaN,x);return at(e,"number")},Qt.sub=function(t){t=Bt(t,"number"),Vt(t,"number");var e=ft(this.values,t.values,NaN,N);return at(e,"number")},Qt.mul=function(t){t=Bt(t,"number"),Vt(t,"number");var e=ft(this.values,t.values,NaN,E);return at(e,"number")},Qt.div=function(t){t=Bt(t,"number"),Vt(t,"number");var e=ft(this.values,t.values,NaN,O);return at(e,"number")},Qt.mod=function(t){t=Bt(t,"number"),Vt(t,"number");var e=ft(this.values,t.values,NaN,j);return at(e,"number")},Qt.pow=function(t){t=Bt(t,"number"),Vt(t,"number");var e=ft(this.values,t.values,NaN,Math.pow);return at(e,"number")},Qt.abs=function(){return at(this.values.map(Math.abs),"number")},Qt.sqrt=function(){return at(this.values.map(Math.sqrt),"number")},Qt.sign=function(){return at(this.values.map(Math.sign),"number")},Qt.ceil=function(){return at(this.values.map(Math.ceil),"number")},Qt.floor=function(){return at(this.values.map(Math.floor),"number")},Qt.round=function(){return at(this.values.map(Math.round),"number")},Qt.exp=function(){return at(this.values.map(Math.exp),"number")},Qt.log=function(){return at(this.values.map(Math.log),"number")},Qt.sin=function(){return at(this.values.map(Math.sin),"number")},Qt.cos=function(){return at(this.values.map(Math.cos),"number"); | ||
| },Qt.tan=function(){return at(this.values.map(Math.tan),"number")},Qt.asin=function(){return at(this.values.map(Math.asin),"number")},Qt.acos=function(){return at(this.values.map(Math.acos),"number")},Qt.atan=function(){return at(this.values.map(Math.atan),"number")},Qt.sum=function(t){return Ht(t)&&(t=!0),t?ct(this.values,0,x):ht(this.values,0,ut,x)},Qt.cuSum=function(t){Ht(t)&&(t=!0);var e=t?pt(this.values,x):pt(this.values,se.number,x);return at(e,"number")},Qt.mean=function(t){Ht(t)&&(t=!0);var e={n:0,sum:0},r=t?ct(this.values,e,C):ht(this.values,e,ut,C);return Number.isNaN(r)||0===r.n?NaN:r.sum/r.n},Qt.stdev=function(t){var e=this["var"](t);return Number.isNaN(e)?NaN:Math.sqrt(e)},Qt["var"]=function(t){Ht(t)&&(t=!0);var e={n:0,mean:0,M2:0},r=t?ct(this.values,e,A):ht(this.values,e,ut,A);return Number.isNaN(r)||r.n<2?NaN:r.M2/(r.n-1)},Xt.dtype="boolean",Xt.and=function(t){t=Bt(t,"boolean"),Vt(t,"boolean");var e=ft(this.values,t.values,z);return at(e,"boolean")},Xt.or=function(t){t=Bt(t,"boolean"),Vt(t,"boolean");var e=ft(this.values,t.values,M);return at(e,"boolean")},Xt.not=function(){var t=lt(this.values,null,S);return at(t,"boolean")},Xt.xor=function(t){t=Bt(t,"boolean"),Vt(t,"boolean");var e=ft(this.values,t.values,k);return at(e,"boolean")},Xt.all=function(t){return Ht(t)&&(t=!1),t?ct(this.values,!0,z):this.values.reduce(z,!0)},Xt.any=function(t){return Ht(t)&&(t=!1),t?ct(this.values,!1,M):this.values.reduce(M,!1)},Xt.sum=function(t){if(Ht(t)&&(t=!0),t)return ct(this.values,0,I);var e=ht(this.values,0,ut,I);return null===e?NaN:e},Xt.which=function(){for(var t=[],e=0;e<this.values.length;e++){var r=this.values[e];r===!0&&t.push(e)}return at(t,"number")},Zt.dtype="string",Zt.nChar=function(){var t=lt(this.values,se.number,R);return at(t,"number")},Zt.charAt=function(t){t=Bt(t);var e=Object.create(null),r=vt([this.values,t.values],Ne,e);return at(r,"string")};var Ne=U(function(t,e){return null===t?null:t.charAt(e)});Zt.trim=function(){var t=Object.create(null),e=vt([this.values],Ee,t);return at(e,"string")};var Ee=U(function(t){return null===t?null:t.trim()});Zt.strSlice=function(t,e){t=Bt(t),e=Bt(e);var r=Object.create(null),n=vt([this.values,t.values,e.values],Oe,r);return at(n,"string")};var Oe=U(function(t,e,r){return null===t?null:t.slice(e,r)});Zt.substr=function(t,e){t=Bt(t),e=Bt(e);var r=Object.create(null),n=vt([this.values,t.values,e.values],je,r);return at(n,"string")};var je=U(function(t,e,r){return null===t?null:t.substr(e,r)});Zt.strIncludes=function(t,e){t=Bt(t),e=Bt(e);var r=vt([this.values,t.values,e.values],V);return at(r,"boolean")},Zt.startsWith=function(t,e){t=Bt(t),e=Bt(e);var r=vt([this.values,t.values,e.values],q);return at(r,"boolean")},Zt.endsWith=function(t,e){t=Bt(t),e=Bt(e);var r=vt([this.values,t.values,e.values],L);return at(r,"boolean")},Zt.strIndexOf=function(t,e){t=Bt(t),e=Bt(e);var r=vt([this.values,t.values,e.values],T);return at(r,"number")},Zt.strLastIndexOf=function(t,e){t=Bt(t),e=Bt(e);var r=vt([this.values,t.values,e.values],D);return at(r,"number")},Zt.regexMatch=function(t){t=Bt(t);var e=Object.create(null),r=vt([this.values,t.values],Ce,e);return at(r,"string")};var Ce=U(function(t,e){if(null===t)return null;var r=t.match(e);return null===r?null:r[0]});Zt.regexSearch=function(t){t=Bt(t);var e=vt([this.values,t.values],F);return at(e,"number")},Zt.regexTest=function(t){t=Bt(t);var e=vt([this.values,t.values],B);return at(e,"boolean")},Zt.strReplace=function(t,e){t=Bt(t),e=Bt(e);var r=Object.create(null),n=vt([this.values,t.values,e.values],Ae,r);return at(n,"string")};var Ae=U(function(t,e,r){return null===t?null:t.replace(e,r)});Zt.toLowerCase=function(){var t=Object.create(null),e=vt([this.values],W,t);return at(e,"string")},Zt.toUpperCase=function(){var t=Object.create(null),e=vt([this.values],K,t);return at(e,"string")},$t.dtype="date",te.nRow=function(){return 0===this._cols.length?0:this._cols[0].values.length},te.nCol=function(){return this._cols.length},te.dtypes=function(){return Jt.df([this.names(),this._dtypesVector()],["colName","dtype"])},te._dtypesVector=function(){return at(this._cols.map(function(t){return t.dtype}),"string")},te.colArray=function(){return this._cols.slice()},te.colMap=function(){var t=this._names.dropNa().unique().values,e=t.map(function(t){return nt(t,this._names)},this),r=Object.create(null);return e.forEach(function(e,n){var i=t[n];r[i]=this._cols[e]},this),r},te.equals=function(t,e){if(null===t||Ht(t)||t.type!==te.type||!t.names().equals(this.names()))return!1;for(var r=this.nCol(),n=0;r>n;n++)if(!t._cols[n].equals(this._cols[n],e))return!1;return!0},te.toString=function(){var t="DataFrame[nRow:"+this.nRow()+", nCol:"+this.nCol()+", allDtype:"+this.allDtype+"]";return t},te.toObjArray=function(){for(var t=this._names.dropNa().unique().values,e=t.map(function(t){return nt(t,this._names)},this),r=this.nRow(),n=t.length,i=st(r),o=0;r>o;o++){for(var u={},s=0;n>s;s++)u[t[s]]=this._cols[e[s]].values[o];i[o]=u}return i},te.toMatrix=function(t){t=Ht(t)?!1:t;var e=t?1:0,r=this.nRow(),n=st(r+e);t&&(n[0]=this._names.values);for(var i=this.nCol(),o=0;r>o;o++){for(var u=st(i),s=0;i>s;s++)u[s]=this._cols[s].values[o];n[o+e]=u}return n},te.pack=function(){var t={type:te.type,version:Jt.version};return t.names=h(this.names(),!1),t.cols=this._cols.map(function(t){return h(t,!1)}),t},te.names=function(){return this._names},te.setNames=function(t){if(t=Wt(t),t.size()!==this._cols.length)throw new Error('the length of "names" must match the number of columns');return gt(this._cols,t,!1)},te.rename=function(t){throw new Error("unimplemented method (TODO)")},te.resetNames=function(){return gt(this._cols,mt(this._cols.length),!1)},te.isNa=function(){return this.mapCols(function(t){return t.isNa()})},te.dropNa=function(){var t=this.nCol(),e=this.nRow();if(0===e)return this;for(var r=st(e),n=0;e>n;n++){r[n]=!0;for(var i=0;t>i;i++)if(ut(this._cols[i].values[n])){r[n]=!1;break}}return this.s(r)},te.s=function(t,e){var r=H(t,this.nRow()),n=J(e,this._names,this._dtypesVector()),i=this._names.values,o=this._cols;null!==n&&(i=dt(i,n.values),o=dt(o,n.values));var u=at(i,"string");if(null!==r){null===n&&(o=o.slice());for(var s=0;s<o.length;s++){var a=o[s].dtype,l=dt(o[s].values,r.values);o[s]=at(l,a)}}return gt(o,u,!1)},te.sMod=function(t,e,r){var n=!Ht(r)&&null!==r&&r.type===te.type;n||(r=Ft(r));var i=H(t,this.nRow()),o=J(e,this._names,this._dtypesVector());if(null===o?o=Jt.seq(this.nCol()):yt(o),n){var u=null===i?this.nRow():i.size();if(u!==r.nRow()||o.size()!==r.nCol())throw new Error('"values" has the wrong dimensions for selection')}for(var s=this._cols.slice(),a=0;a<o.values.length;a++){var l=o.values[a],c=n?r._cols[a]:r;s[l]=null!==i?s[l].sMod(i,c):n?c:Jt.rep(c,this.nRow())}return gt(s,this.names(),!1)},te.c=function(t){var e=nt(t,this._names);return this._cols[e]},te.cMod=function(t,e){var r=this._cols.slice(),n=nt(t,this._names);return r[n]=e,gt(r,this._names)},te.insertCol=function(t,e,r){if(t=Et(t),r=Ht(r)?this._cols.length:r,r=Ft(r),!Number.isInteger(r))throw new Error('expected "index" to be an integer but got: '+r);var n=this._cols.slice(),i=this._names.values.slice();return n.splice(r,0,e),i.splice(r,0,t),gt(n,at(i,"string"))},te.at=function(t,e){if(t=Ft(t),t=et(t,this.nRow()),e=Ft(e),Kt(e))e=et(e,this.nCol());else{if(!Pt(e)&&null!==e)throw new Error('expected "j" to be an integer or string but got: '+e);e=nt(e,this._names)}return this._cols[e].values[t]},te.locAt=function(t,e,r){var n=this.c(t),i=nt(r,this._names),o=n.indexOf(e);if(o===-1)throw new Error("no match for lookup key: "+e);return this._cols[i].values[o]},te.head=function(t){return Ht(t)&&(t=6),St(t,"n"),this.s(Jt.rng(0,t))},te.tail=function(t){Ht(t)&&(t=6),St(t,"n");var e=0>t?-t:this.nRow()-t;return this.s(Jt.rng(e,void 0))},te.mapCols=function(t,e){arguments.length<2&&(e=t,t=null),It(e,"func");var r=J(t,this._names,this._dtypesVector());null===r&&(r=Jt.seq(this._cols.length));for(var n=this._names.values,i=r.values.length,o=st(i),u=st(i),s=0;i>s;s++){var a=r.values[s],l=this._cols[a],c=n[a];u[s]=e(l,c,a,s),o[s]=c}var h=at(o,"string");return gt(u,h)},te.updateCols=function(t,e){arguments.length<2&&(e=t,t=null),It(e,"func");var r=J(t,this._names,this._dtypesVector());null===r?r=Jt.seq(this._cols.length):yt(r);for(var n=this._names.values,i=this._cols.slice(),o=r.values.length,u=0;o>u;u++){var s=r.values[u],a=this._cols[s],l=n[s];i[s]=e(a,l,s,u)}return gt(i,this._names)},te.mapRowObjects=function(t,e){return It(t,"func"),this.toObjArray().map(t,e)},te.mapRowArrays=function(t,e){return It(t,"func"),this.toMatrix().map(t,e)},te.mapRowVectors=function(t,e){It(t,"func");var r=this.allDtype;if(null===r)throw new Error('cannot call "mapRowVectors" on a data frame with '+'null "allDtype" property');for(var n=this.toMatrix(),i=0;i<n.length;i++)n[i]=at(n[i],r);return n.map(t,e)},te.mapRowDfs=function(t,e){It(t,"func");for(var r=this.nRow(),n=st(r),i=0;r>i;i++)n[i]=this.s(i);return n.map(t,e)},te.unique=function(){if(0===this.nCol())return this;Lt(this);var t=this._getIndex().unique();return gt(t,this._names,!1)},te.nUnique=function(){return 0===this.nCol()?0:(Lt(this),this._getIndex().size)},te.duplicated=function(t){return 0===this.nCol()?at([],"boolean"):(Lt(this),this._getIndex().duplicated(t))},te._getIndex=function(){return 1===this._cols.length?this._cols[0]._getIndex():(null===this._index&&(this._index=ot(this._cols)),this._index)},te.groupApply=function(t,e,r){if(Ht(t))throw new Error('"colSelect" must not be undefined');var n=J(t,this._names,this._dtypesVector());if(yt(n),null===n||n.size()===this.nCol())throw new Error('"colSelect" must not select every column in the '+"data frame");if(0===n.size())throw new Error('"colSelect" must select at least 1 column');var i=this.s(null,n.ex()),o=this.s(null,n);Lt(o);var u=o._getIndex(),s=o.unique();It(e,"func"),Ht(r)||(r=Bt(r,"string"),"string"!==r.dtype&&(r=r.toDtype("string")));for(var a=s.nRow(),l=st(a),c=-1,h=0,f=0;a>f;f++){var v=s.s(f),p=u.lookup(s._cols,f),d=i.s(p),m=e(d,v);if(!Ht(m)){var y,g;if(null===m?(y=1,g=[v,m]):m.type===te.type?(y=m.nCol(),g=[v,m]):m.type===Gt.type?(y=m.size(),g=[v].concat(m.values)):Array.isArray(m)?(y=m.length,g=[v].concat(m)):(y=1,g=[v,m]),c===-1){if(c=y,!Ht(r)&&y!==r.size())throw new Error('length of "colNames" must match implied number '+'of columns returned by "func"')}else if(y!==c)throw new Error("inconsistent implied column counts returned from "+'"func": '+c+", ",+y);l[h]=Jt._colCatArray(g),h++}}if(0===h)return s.s([]);l.length!==h&&(l.length=h);var b=Jt._rowCatArray(l);if(!Ht(r)){var w=b.names();w=w.sMod(Jt.rng(n.size()),r),b=b.setNames(w)}return b},te.transpose=function(t,e){if(0===this.nRow())return Jt.df([]);if(t=Ht(t)?null:t,null!==t&&!Pt(t))throw new Error('"preservedColName" must be a string when not null or '+"undefined");var r,n,i=this.nRow();if(Ht(e))r=this,n=mt(i);else{var o=nt(e,this._names);r=this.s(null,Jt.ex(o)),n=this.c(o),"string"!==n.dtype&&(n=n.toDtype("string"))}var u,s;null!==t?(n=Jt.vCat(t,n),u=1,s=st(i+1),s[0]=r._names):(u=0,s=st(i));for(var a=r.nCol(),l=0;i>l;l++){for(var c=st(a),h=0;a>h;h++)c[h]=r._cols[h].values[l];s[l+u]=c}return gt(s,n)},te.sort=function(t,e){if(Ht(t))throw new Error('"colSelect" must not be undefined');var r=J(t,this._names,this._dtypesVector());null===r?r=Jt.seq(this.nCol()):yt(r);var n=this.s(null,r);if(Lt(n),e=Ht(e)?!0:e,e=Bt(e,"boolean"),Vt(e,"boolean"),e.isNa().any())throw new Error('"ascending" must not contain missing values');1===e.size()&&(e=Jt.rep(e,n.nCol()));var i=zt(n._cols,e.values);return this.s(i)},te.melt=function(t,e,r){e=Ht(e)||null===e?"variable":Ft(e).toString(),r=Ht(r)||null===r?"value":Ft(r).toString();var n=J(t,this._names,this._dtypesVector()),i=Jt.seq(this.nCol()).s(Jt.ex(n));if(0===i.size())throw new Error('"idVars" must not select all columns in the data frame');yt(n);var o=this.mapCols(n,function(t){return Jt.rep(t,i.size())}),u=Jt.repEach(this.names().s(i),this.nRow()),s=Jt.vCat.apply(Jt,this.s(null,i).colArray());return Jt.colCat(o,Jt.df([u,s],[e,r]))},te.pivot=function(t,e,r){r=Ht(r)?{}:r,Tt(r,["idVars","aggFunc","fillValue"]);var n=r.aggFunc,i=r.fillValue,o=nt(t,this._names),u=nt(e,this._names);if(o===u)throw new Error('"pivotCol" and "valueCol" must be different');var s;if(Ht(r.idVars)?s=Jt.seq(this.nCol()).s(Jt.ex([o,u])):(s=J(r.idVars,this._names,this._dtypesVector()),null===s&&(s=Jt.seq(this.nCol())),yt(s)),s.contains(o)||s.contains(u))throw new Error('"idVars" must not include pivotCol or valueCol');if(0===s.size())throw new Error("one or more columns must be selected as id columns");var a=Jt.df([this.c(o).unique().sort()],["variable"]),l=Jt.vCat(s,o,u),c=this.s(null,l),h=c.groupApply(Jt.rng(0,-2),function(t){t=t.setNames(["variable","value"]),Ht(n)||(t=t.groupApply("variable",function(t){return n(t.c(0))},"value"));var e=a.join(t,"left");if(e.nRow()!==a.nRow())throw new Error('must provide "aggFunc" when aggregation is required');return Ht(i)?e.c("value"):e.c("value").replaceNa(i)},a.c("variable"));return h};var ze=Jt.vector(["by","leftBy","rightBy","leftSuffix","rightSuffix","indicator"]);te.join=function(t,e,r){if(Ht(t)||null===t||t.type!==te.type)throw new Error('"other" must be a data frame');var n=!1,i="_x",o="_y",u=!1,s=!1;switch(e){case"inner":break;case"left":u=!0;break;case"right":s=!0;break;case"outer":u=!0,s=!0;break;default:throw new Error('"how" must be one of the following strings: '+'"inner", "left", "right", "outer"')}Ht(r)||(Tt(r,ze),Ht(r.indicator)||(n=r.indicator),Ht(r.leftSuffix)||(i=r.leftSuffix),Ht(r.rightSuffix)||(o=r.rightSuffix));var a=Y(this,t,r),l=a.left,c=a.right,h=this.s(null,l),f=this.s(null,l.ex()),v=t.s(null,c),p=t.s(null,c.ex());if(h.dtypes().c("dtype").contains("object")||v.dtypes().c("dtype").contains("object"))throw new Error('key columns must not have "object" dtype');if(!h.dtypes().c("dtype").equals(v.dtypes().c("dtype")))throw new Error("key columns must have matching dtypes on left "+"and right");var d,m,y=f.names().s(f.names().isIn(p.names())),g=f.names().map(function(t){return y.contains(t)?t+i:t}),b=p.names().map(function(t){return y.contains(t)?t+o:t}),w=Jt.vCat(h.names(),g,b,n?["_join"]:[]),_=v._getIndex(),x=h.nRow(),N=st(w.size());for(m=0;m<N.length;m++)N[m]=[];if(s)for(d=st(v.nRow()),m=0;m<d.length;m++)d[m]=!0;for(m=0;x>m;m++){var E=_.lookup(h._cols,m);if(null===E)u&&P(N,h,f,p,m,null,"leftOnly");else if("number"==typeof E)P(N,h,f,p,m,E,"both"),s&&(d[E]=!1);else for(var O=0;O<E.length;O++){var j=E[O];P(N,h,f,p,m,j,"both"),s&&(d[j]=!1)}}if(s){var C=v.s(d),A=p.s(d);for(x=C.nRow(),m=0;x>m;m++)P(N,C,f,A,null,m,"rightOnly",!0)}return gt(N,w)},Jt.rng=function(t,e,r){if(r=Ht(r)?null:r,null!==r&&"boolean"!=typeof r)throw new Error('"includeStop" must be either true, false, or null');var n=Kt(t)&&Pt(e)||Pt(t)&&Kt(e);if(n&&null===r)throw new Error('"includeStop" must be set to either true or false '+"when mixing numbers and strings for start/stop");var i=Object.create(ee);return i._start=t,i._stop=e,i._includeStop=r,i},ee.ex=function(){return Jt.ex(this)};var Me=Jt.vector(Object.keys(ue));Jt.byDtype=function(t){t=Bt(t),Vt(t,"string"),t=t.unique();var e=t.isIn(Me);if(!e.all()){var r=t.s(e.not()).at(0);throw new Error('invalid dtype: ""'+r+'"')}var n=Object.create(re);return n._dtypes=t,n},re.ex=function(){return Jt.ex(this)},Jt.ex=function(t){if(Ht(t))throw new Error('"selector" must not be undefined');var e=Object.create(ne);return e._selector=t,e};var Se={INT:"INT",COL:"COL",KEY:"KEY"};Gt._resolveSelectorHelper=function(t,e){var r,n,i="number"===this.dtype,o="string"===this.dtype;switch(t.resolveMode){case Se.INT:if(!i)throw new Error("expected number vector for integer indexing "+'but got vector with dtype: "'+this.dtype+'"');for(r=0;r<this.values.length;r++)e.push(et(this.values[r],t.maxLen));break;case Se.COL:if(i)for(r=0;r<this.values.length;r++)e.push(et(this.values[r],t.maxLen));else{if(!o)throw new Error("expected number or string vector for column "+'indexing but got vector with dtype: "'+this.dtype+'"');for(r=0;r<this.values.length;r++){var u=this.values[r];n=t.index.lookupKey([u]),rt(n,u,t,e)}}break;case Se.KEY:if(1!==t.index.arity)throw new Error("unimplemented case (TODO)");var s=t.index.initVectors[0].dtype;if(this.dtype!==s)throw new Error('expected "'+s+'" vector for key '+'lookup but got vector with dtype: "'+this.dtype+'"');var a=[this];for(r=0;r<this.values.length;r++)n=t.index.lookup(a,r),rt(n,this.values[r],t,e);break;default:throw new Error("Unrecognized RESOLVE_MODE: "+t.resolveMode)}},ee._resolveSelectorHelper=function(t,e){var r=tt(this._start,t,!1);if(!(r>=t.maxLen)){var n=tt(this._stop,t,!0,this._includeStop);if(!(0>=n)){r=0>r?0:r,n=n>t.maxLen?t.maxLen:n;for(var i=r;n>i;i++)e.push(i)}}},re._resolveSelectorHelper=function(t,e){if(null===t.dtypes)throw new Error("ByDtype selector can only be used for column indexing");for(var r=t.dtypes.isIn(this._dtypes).which(),n=0;n<r.values.length;n++)e.push(r.values[n])},ne._resolveSelectorHelper=function(t,e){var r=[];$(this._selector,t,r);for(var n=Q(at(r,"number"),t.maxLen),i=0;i<n.values.length;i++)e.push(n.values[i])},ie.lookup=function(t,e){throw new Error('abstract "lookup" method called without concrete '+"implementation")},ie.has=function(t){for(var e=t[0].size(),r=st(e),n=0;e>n;n++)r[n]=null!==this.lookup(t,n);return at(r,"boolean")},ie.valueCounts=function(){for(var t=this.initVectors,e=this.arity,r=this.size,n=st(e),i=0;e>i;i++)n[i]=st(r);for(var o=st(r),u=t[0].size(),s=0,a=0;u>a;a++){var l=this.lookup(t,a);if(l===a||l[0]===a){for(i=0;e>i;i++)n[i][s]=t[i].values[a];o[s]=l===a?1:l.length,s++}}var c=n.map(function(e,r){return at(e,t[r].dtype)});return{vectors:c,counts:at(o,"number")}},ie.unique=function(){return this.valueCounts().vectors},ie.duplicated=function(t){Ht(t)&&(t="first");var e=!1,r=!1;if("first"===t)e=!0;else if("last"===t)r=!0;else if(t!==!1)throw new Error('"keep" must be either "first", "last", or false');for(var n=this.initVectors,i=n[0].size(),o=st(i),u=0;i>u;u++)o[u]=!1;var s=e?1:0;for(u=0;i>u;u++){var a=this.lookup(n,u);if("number"!=typeof a&&a[0]===u)for(var l=a.length,c=r?l-1:l,h=s;c>h;h++)o[a[h]]=!0}return at(o,"boolean")};var ke={"null":"_INTERNAL_JSDATAFRAME_NULL_KEY_",undefined:"_INTERNAL_JSDATAFRAME_UNDEFINED_KEY_"};Jt._private_export.newNestedIndex=ot,oe.lookup=function(t,e){for(var r=this.arity,n=this._dtypes,i=this._map,o=0;r>o;o++){var u=t[o],s=it(u.values[e],n[o]);if(i=i[s],Ht(i))return null}return i},oe.lookupKey=function(t){for(var e=this.arity,r=this._dtypes,n=this._map,i=0;e>i;i++){var o=it(t[i],r[i]);if(n=n[o],Ht(n))return null}return n},Jt._private_export.mapNonNa=lt,Jt._private_export.reduceNonNa=ct,Jt._private_export.reduceUnless=ht,Jt._private_export.combineArrays=ft,Jt._private_export.inferDtype=bt,Jt._private_export.inferVectorDtype=_t,Jt._private_export.coerceToNum=xt,Jt._private_export.coerceToBool=Nt,Jt._private_export.coerceToStr=Et,Jt._private_export.coerceToDate=Ot;var Ie={undefined:0,"null":1,NaN:2};Jt._private_export.compare=Ct;var Re=At(Ct);Jt._private_export.reverseComp=At,Jt._private_export.ensureVector=Bt}); | ||
| //# sourceMappingURL=jsdataframe-min.map |
+1
-1
| { | ||
| "name": "jsdataframe", | ||
| "version": "0.1.1", | ||
| "version": "0.2.0", | ||
| "description": "a data frame library inspired by R and Python Pandas", | ||
@@ -5,0 +5,0 @@ "main": "jsdataframe.js", |
+2
-1
@@ -7,3 +7,4 @@ # **jsdataframe** | ||
| methods, subset selection/modification, sorting, grouped | ||
| split-apply-combine operations, database-style joins, and more. | ||
| split-apply-combine operations, database-style joins, reshaping/pivoting, | ||
| JSON serialization, and more. | ||
| It is hoped that users of R and Python Pandas will find the concepts | ||
@@ -10,0 +11,0 @@ in jsdataframe quite familiar. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
263460
5.45%4141
4.47%15
7.14%