df-script 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +124 -8
  2. package/dist/api.d.ts +1 -1
  3. package/dist/columnExpressions/ColumnExpr.d.ts +2 -2
  4. package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
  5. package/dist/columnExpressions/functions/element.d.ts +1 -1
  6. package/dist/columnExpressions/functions/when.d.ts +2 -2
  7. package/dist/columnExpressions/index.d.ts +1 -1
  8. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +2 -2
  9. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +11 -10
  10. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +39 -0
  11. package/dist/columnExpressions/mixins/ListExpr.d.ts +2 -2
  12. package/dist/columnExpressions/mixins/StringExpr.d.ts +2 -2
  13. package/dist/columnExpressions/types.d.ts +1 -0
  14. package/dist/constants.d.ts +11 -0
  15. package/dist/dataframe/dataframe.d.ts +1 -1
  16. package/dist/datatypes/index.d.ts +3 -2
  17. package/dist/datatypes/types.d.ts +7 -7
  18. package/dist/index.js +6 -6
  19. package/dist/types.d.ts +4 -2
  20. package/dist/utils/array.d.ts +217 -0
  21. package/dist/utils/binary.d.ts +3 -0
  22. package/dist/utils/date.d.ts +21 -35
  23. package/dist/utils/guards.d.ts +11 -10
  24. package/dist/utils/index.d.ts +3 -2
  25. package/dist/utils/list.d.ts +23 -1
  26. package/dist/utils/number.d.ts +14 -29
  27. package/dist/utils/object.d.ts +26 -0
  28. package/dist/utils/string.d.ts +3 -5
  29. package/package.json +2 -2
  30. package/dist/api.js +0 -26
  31. package/dist/bundle.min.js +0 -1
  32. package/dist/columnExpressions/ColumnExpr.js +0 -219
  33. package/dist/columnExpressions/ExprBase.js +0 -92
  34. package/dist/columnExpressions/constants.js +0 -7
  35. package/dist/columnExpressions/functions/all.js +0 -11
  36. package/dist/columnExpressions/functions/coalesce.js +0 -44
  37. package/dist/columnExpressions/functions/element.js +0 -11
  38. package/dist/columnExpressions/functions/exclude.js +0 -13
  39. package/dist/columnExpressions/functions/implode.js +0 -7
  40. package/dist/columnExpressions/functions/lit.js +0 -17
  41. package/dist/columnExpressions/functions/repeat.d.ts +0 -47
  42. package/dist/columnExpressions/functions/repeat.js +0 -131
  43. package/dist/columnExpressions/functions/seq_range.js +0 -91
  44. package/dist/columnExpressions/functions/when.js +0 -85
  45. package/dist/columnExpressions/index.js +0 -38
  46. package/dist/columnExpressions/mixins/AggregationExpr.js +0 -76
  47. package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -131
  48. package/dist/columnExpressions/mixins/BooleanExpr.d.ts +0 -40
  49. package/dist/columnExpressions/mixins/BooleanExpr.js +0 -67
  50. package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -250
  51. package/dist/columnExpressions/mixins/ListExpr.js +0 -224
  52. package/dist/columnExpressions/mixins/LogicalExpr.js +0 -53
  53. package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -71
  54. package/dist/columnExpressions/mixins/NumericExpr.d.ts +0 -92
  55. package/dist/columnExpressions/mixins/NumericExpr.js +0 -259
  56. package/dist/columnExpressions/mixins/StringExpr.js +0 -237
  57. package/dist/columnExpressions/mixins/StructExpr.js +0 -139
  58. package/dist/columnExpressions/mixins/TemporalExpr.js +0 -126
  59. package/dist/columnExpressions/mixins/WindowExpr.js +0 -151
  60. package/dist/columnExpressions/types.js +0 -2
  61. package/dist/columnExpressions/utils.js +0 -45
  62. package/dist/dataframe/constants.js +0 -7
  63. package/dist/dataframe/dataframe.js +0 -990
  64. package/dist/dataframe/grouped/grouped.js +0 -114
  65. package/dist/dataframe/index.js +0 -20
  66. package/dist/dataframe/types.js +0 -2
  67. package/dist/dataframe/utils.js +0 -307
  68. package/dist/datatypes/DataType.js +0 -76
  69. package/dist/datatypes/index.js +0 -46
  70. package/dist/datatypes/types/Binary.d.ts +0 -9
  71. package/dist/datatypes/types/Binary.js +0 -18
  72. package/dist/datatypes/types/Boolean.d.ts +0 -9
  73. package/dist/datatypes/types/Boolean.js +0 -19
  74. package/dist/datatypes/types/Date.d.ts +0 -8
  75. package/dist/datatypes/types/Date.js +0 -21
  76. package/dist/datatypes/types/Datetime.d.ts +0 -8
  77. package/dist/datatypes/types/Datetime.js +0 -17
  78. package/dist/datatypes/types/Decimal.d.ts +0 -10
  79. package/dist/datatypes/types/Decimal.js +0 -28
  80. package/dist/datatypes/types/Duration.d.ts +0 -8
  81. package/dist/datatypes/types/Duration.js +0 -17
  82. package/dist/datatypes/types/Float32.d.ts +0 -8
  83. package/dist/datatypes/types/Float32.js +0 -17
  84. package/dist/datatypes/types/Float64.d.ts +0 -8
  85. package/dist/datatypes/types/Float64.js +0 -17
  86. package/dist/datatypes/types/Int16.d.ts +0 -8
  87. package/dist/datatypes/types/Int16.js +0 -17
  88. package/dist/datatypes/types/Int32.d.ts +0 -8
  89. package/dist/datatypes/types/Int32.js +0 -17
  90. package/dist/datatypes/types/Int64.d.ts +0 -8
  91. package/dist/datatypes/types/Int64.js +0 -17
  92. package/dist/datatypes/types/Int8.d.ts +0 -8
  93. package/dist/datatypes/types/Int8.js +0 -17
  94. package/dist/datatypes/types/List.d.ts +0 -10
  95. package/dist/datatypes/types/List.js +0 -31
  96. package/dist/datatypes/types/Null.d.ts +0 -9
  97. package/dist/datatypes/types/Null.js +0 -17
  98. package/dist/datatypes/types/Object.d.ts +0 -9
  99. package/dist/datatypes/types/Object.js +0 -17
  100. package/dist/datatypes/types/Struct.d.ts +0 -14
  101. package/dist/datatypes/types/Struct.js +0 -39
  102. package/dist/datatypes/types/Time.d.ts +0 -8
  103. package/dist/datatypes/types/Time.js +0 -29
  104. package/dist/datatypes/types/UInt16.d.ts +0 -8
  105. package/dist/datatypes/types/UInt16.js +0 -17
  106. package/dist/datatypes/types/UInt32.d.ts +0 -8
  107. package/dist/datatypes/types/UInt32.js +0 -17
  108. package/dist/datatypes/types/UInt64.d.ts +0 -8
  109. package/dist/datatypes/types/UInt64.js +0 -17
  110. package/dist/datatypes/types/UInt8.d.ts +0 -8
  111. package/dist/datatypes/types/UInt8.js +0 -17
  112. package/dist/datatypes/types/Utf8.d.ts +0 -10
  113. package/dist/datatypes/types/Utf8.js +0 -20
  114. package/dist/datatypes/types.js +0 -290
  115. package/dist/exceptions/index.js +0 -46
  116. package/dist/exceptions/utils.js +0 -28
  117. package/dist/functions/concat.js +0 -260
  118. package/dist/functions/index.js +0 -9
  119. package/dist/functions/read_csv.js +0 -53
  120. package/dist/functions/read_json.js +0 -21
  121. package/dist/functions/transpose.d.ts +0 -7
  122. package/dist/functions/transpose.js +0 -84
  123. package/dist/types.js +0 -2
  124. package/dist/utils/boolean.d.ts +0 -1
  125. package/dist/utils/boolean.js +0 -18
  126. package/dist/utils/csv.js +0 -313
  127. package/dist/utils/date.js +0 -348
  128. package/dist/utils/guards.js +0 -112
  129. package/dist/utils/index.js +0 -23
  130. package/dist/utils/json.js +0 -217
  131. package/dist/utils/list.js +0 -361
  132. package/dist/utils/number.js +0 -401
  133. package/dist/utils/string.js +0 -209
@@ -1 +0,0 @@
1
- "use strict";var Vt=Object.defineProperty;var xn=Object.getOwnPropertyDescriptor;var bn=Object.getOwnPropertyNames;var wn=Object.prototype.hasOwnProperty;var _n=(s,t)=>{for(var e in t)Vt(s,e,{get:t[e],enumerable:!0})},Tn=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of bn(t))!wn.call(s,r)&&r!==e&&Vt(s,r,{get:()=>t[r],enumerable:!(n=xn(t,r))||n.enumerable});return s};var Dn=s=>Tn(Vt({},"__esModule",{value:!0}),s);var Mn={};_n(Mn,{$tbl:()=>On,ALL_COLUMNS_MARKER:()=>j,AggregationExpr:()=>Ht,ArithmeticExpr:()=>Wt,ColumnExpr:()=>k,ColumnNotFoundError:()=>B,ComparisonExpr:()=>qt,ComputeError:()=>nt,DataFrame:()=>F,DataFrameError:()=>V,DataType:()=>K,DataTypeRegistry:()=>L,DateTimeExprNamespace:()=>Ut,ExprBase:()=>wt,FrameScriptError:()=>ut,GroupedData:()=>Tt,LITERAL_MARKER:()=>Pt,ListExpr:()=>Xt,ListExprNamespace:()=>vt,LogicalExpr:()=>Yt,SchemaError:()=>ct,StringExpr:()=>zt,StringExprNamespace:()=>Mt,TemporalExpr:()=>Zt,When:()=>Ft,WhenThen:()=>_t,WhenThenChain:()=>Rt,WindowExpr:()=>Gt,all:()=>Jt,coalesce:()=>te,columnsToRows:()=>Ae,concat:()=>Dt,derive:()=>g,exclude:()=>Qt,getRowFromColumns:()=>En,inferColumnType:()=>rt,kleeneBinary:()=>v,kleeneUnary:()=>_,lit:()=>it,normalizeToDataFrames:()=>dn,resolveColumnSelectors:()=>ft,resolveWindowExpr:()=>jt,rowsToColumns:()=>De,when:()=>ee});module.exports=Dn(Mn);var ke=/[,\s_]/g,An=/^[+-]?\d+(?:\.\d+)?$/;function ot(s){return typeof s=="number"&&!Number.isNaN(s)&&Number.isFinite(s)}function et(s){if(s==null||typeof s=="symbol")return null;if(ot(s))return s;if(typeof s=="boolean")return s?1:0;if(typeof s=="bigint"){let t=Number(s);return ot(t)?t:null}if(s instanceof Date){let t=s.getTime();return ot(t)?t:null}if(typeof s=="string"){let t=s.trim().replace(ke,"");if(t==="")return null;let e=Number(t);return ot(e)?e:null}return null}function yt(s){let{val:t,min:e,max:n}=s;return t<e?e:t>n?n:t}var Se=34028234663852886e22,vn={Float32:{min:-Se,max:Se},Float64:{min:-Number.MAX_VALUE,max:Number.MAX_VALUE}};function At(s,t="Float64"){let e=et(s);return e===null?null:t==="Float32"?Math.fround(e):e}var Ee={Int8:{min:-128,max:127},Int16:{min:-32768,max:32767},Int32:{min:-2147483648,max:2147483647},UInt8:{min:0,max:255},UInt16:{min:0,max:65535},UInt32:{min:0,max:4294967295}},In={Int64:{min:-9223372036854775808n,max:9223372036854775807n},UInt64:{min:0n,max:18446744073709551615n}};function Oe(s,t){if(!ot(s)||!Number.isInteger(s))return!1;if(!t)return!0;let e=typeof t=="string"?Ee[t]:t;return s>=e.min&&s<=e.max}function H(s,t="Int32",e={}){let n=et(s);if(n===null)return null;let r=n;switch(e.coerce||"truncate"){case"round":r=Math.round(r);break;case"floor":r=Math.floor(r);break;case"ceil":r=Math.ceil(r);break;case"truncate":r=Math.trunc(r);break}let i=typeof t=="string"?Ee[t]:t;return yt({val:r,min:i.min,max:i.max})}function It(s,t="Int64"){if(s==null||typeof s=="symbol")return null;let e=null;if(typeof s=="bigint")e=s;else if(typeof s=="boolean")e=s?1n:0n;else if(typeof s=="string"){let r=s.trim().replace(ke,"");if(r==="")return null;if(An.test(r))e=BigInt(r.split(".")[0]);else{let o=et(s);if(o===null)return null;e=BigInt(Math.trunc(o))}}else{let r=et(s);if(r===null)return null;e=BigInt(Math.trunc(r))}let n=typeof t=="string"?In[t]:t;return yt({val:e,min:n.min,max:n.max})}function Ct(s,t={}){let e=et(s);if(e===null)return null;let{precision:n,scale:r}=t,o=e;if(r!==void 0){let i=Math.pow(10,r);o=Math.round(o*i)/i}if(n!==void 0){let i=r||0,l=n-i;if(l>0){let a=Math.pow(10,l)-Math.pow(10,-i);o=yt({val:o,min:-a,max:a})}}return o}function Me(s){let t=s|0;return function(){let e=t=t+1831565813|0;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var St=/^\d{2}:\d{2}/,kt=/(?:Z|[+-]\d{2}(?::?\d{2})?)$/i;var Bt=1e3,ve=6e4,Re=36e5,dt=864e5,Et=1e3,Ot=1e6;function Fe(s,t="ms"){let e=s.getTime();switch(t){case"s":return Math.floor(e/Bt);case"ms":return e;case"us":return e*Et;case"ns":return e*Ot}}function Ne(s){let t=s.getUTCFullYear();return Math.floor((t-1)/100)+1}function Le(s){let t=new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth(),s.getUTCDate())),e=t.getUTCDay()||7;t.setUTCDate(t.getUTCDate()+4-e);let n=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t.getTime()-n.getTime())/dt+1)/7)}function je(s){let t=s.getUTCFullYear();return Math.floor((t-1)/1e3)+1}function Kt(s,t,e=1){return new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth()+t,e,0,0,0,0))}function Ve(s){let t=new Date(Date.UTC(s.getUTCFullYear(),0,1)),e=s.getTime()-t.getTime();return Math.floor(e/dt)+1}function Be(s){return Math.floor(s.getUTCMonth()/3)+1}function Ke(s){let t=s instanceof Date?s.getUTCFullYear():s;return t%4===0&&t%100!==0||t%400===0}function z(s){return s instanceof Date&&!Number.isNaN(s.getTime())}function Ue(s){let t=Math.abs(s);return t>=1e12?s:t<=1e10?s*1e3:s}var Cn=["%ms","%f","%Y","%y","%m","%d","%e","%H","%I","%p","%M","%S","%A","%a","%B","%b","%h","%j","%u","%w","%Z","%z"];function $e(s,t,e){let n=t;n=n.replace(/%%/g,"\0"),n=n.replace(/%F/g,"%Y-%m-%d"),n=n.replace(/%T/g,"%H:%M:%S"),n=n.replace(/%R/g,"%H:%M"),n=n.replace(/%D/g,"%m/%d/%y");let r={get"%Y"(){return String(s.getUTCFullYear())},get"%y"(){return String(s.getUTCFullYear()%100).padStart(2,"0")},get"%m"(){return String(s.getUTCMonth()+1).padStart(2,"0")},get"%d"(){return String(s.getUTCDate()).padStart(2,"0")},get"%e"(){return String(s.getUTCDate()).padStart(2," ")},get"%H"(){return String(s.getUTCHours()).padStart(2,"0")},get"%I"(){return String(s.getUTCHours()%12||12).padStart(2,"0")},get"%p"(){return s.getUTCHours()>=12?"PM":"AM"},get"%M"(){return String(s.getUTCMinutes()).padStart(2,"0")},get"%S"(){return String(s.getUTCSeconds()).padStart(2,"0")},get"%A"(){return s.toLocaleDateString(e,{weekday:"long",timeZone:"UTC"})},get"%a"(){return s.toLocaleDateString(e,{weekday:"short",timeZone:"UTC"})},get"%B"(){return s.toLocaleDateString(e,{month:"long",timeZone:"UTC"})},get"%b"(){return s.toLocaleDateString(e,{month:"short",timeZone:"UTC"})},get"%h"(){return s.toLocaleDateString(e,{month:"short",timeZone:"UTC"})},get"%j"(){let o=new Date(Date.UTC(s.getUTCFullYear(),0,1)),i=s.getTime()-o.getTime(),l=Math.floor(i/dt)+1;return String(l).padStart(3,"0")},get"%u"(){return String(s.getUTCDay()||7)},get"%w"(){return String(s.getUTCDay())},get"%Z"(){return"UTC"},get"%z"(){return"+0000"},get"%ms"(){return String(s.getUTCMilliseconds()).padStart(3,"0")},get"%f"(){return String(s.getUTCMilliseconds()*1e3).padStart(6,"0")}};for(let o of Cn)n.includes(o)&&(n=n.replaceAll(o,r[o]));return n.replace(/\0/g,"%")}function Pe(s,t,e=!0){if(typeof s!="string"||typeof t!="string")return null;let n=[],r=1,o="",i=0;for(;i<t.length;){let b=t[i];if(b==="%")if(i+1<t.length){let w=t[i+1];if(w==="%")o+="%",i+=2;else if(t.slice(i,i+3)==="%ms")n.push({name:"ms",index:r++}),o+="(\\d{1,3})",i+=3;else{switch(w){case"Y":n.push({name:"year",index:r++}),o+="(\\d{4})";break;case"y":n.push({name:"year_short",index:r++}),o+="(\\d{2})";break;case"m":n.push({name:"month",index:r++}),o+="(\\d{1,2})";break;case"d":case"e":n.push({name:"day",index:r++}),o+="(\\d{1,2})";break;case"H":case"I":n.push({name:"hour",index:r++}),o+="(\\d{1,2})";break;case"M":n.push({name:"minute",index:r++}),o+="(\\d{1,2})";break;case"S":n.push({name:"second",index:r++}),o+="(\\d{1,2})";break;case"f":n.push({name:"fractional",index:r++}),o+="(\\d{1,6})";break;default:o+=b+w}i+=2}}else o+=b,i++;else"\\^$*+?.()|[]{}".indexOf(b)!==-1?o+="\\"+b:o+=b,i++}let l=new RegExp("^"+o+"$"),a=s.match(l);if(!a){if(e)return null;let b=new Date(s);return z(b)?b:null}let u=1970,c=1,f=1,h=0,p=0,m=0,y=0;for(let b of n){let w=a[b.index],A=parseInt(w,10);switch(b.name){case"year":u=A;break;case"year_short":u=A+(A>=69?1900:2e3);break;case"month":c=A;break;case"day":f=A;break;case"hour":h=A;break;case"minute":p=A;break;case"second":m=A;break;case"ms":y=parseInt(w.padEnd(3,"0").slice(0,3),10);break;case"fractional":y=parseInt(w.padEnd(6,"0").slice(0,3),10);break}}let d=new Date(Date.UTC(u,c-1,f,h,p,m,y));return z(d)?d:null}function Y(s){if(s instanceof Date)return z(s)?s:null;if(typeof s=="number"){let t=new Date(Ue(s));return z(t)?t:null}if(typeof s=="bigint"){let t=new Date(Ue(Number(s)));return z(t)?t:null}if(typeof s=="string"){let t=s.trim();if(t==="")return null;let e=new Date(t);return z(e)?e:null}return null}function P(s){return ArrayBuffer.isView(s)&&!(s instanceof DataView)}function C(s){return Array.isArray(s)||P(s)}function Z(s){return s!==null&&typeof s=="object"&&!Array.isArray(s)}function xt(s){if(!Z(s))return!1;let t=Object.getPrototypeOf(s);return t===null||t===Object.prototype}function We(s){return typeof s!="function"?!1:/^class\s/.test(Function.prototype.toString.call(s))||s.prototype!==void 0&&s.prototype.constructor===s&&Object.getOwnPropertyDescriptor(s,"prototype")?.writable===!1}function Sn(s){if(s==null)return!1;if(s instanceof Uint8Array||typeof s=="string")return!0;if(Array.isArray(s)){let t=s.length;for(let e=0;e<t;e++)if(!Oe(s[e],{min:-128,max:255}))return!1;return!0}return!!P(s)}function qe(s){return Sn(s)?s instanceof Uint8Array?s:typeof s=="string"?new TextEncoder().encode(s):ArrayBuffer.isView(s)?new Uint8Array(s.buffer,s.byteOffset,s.byteLength):new Uint8Array(s):null}function st(s){return s==null?[]:Array.isArray(s)?s:P(s)?Array.from(s):[s]}function lt(s,t,{mode:e="every",allowNulls:n=!1,allowEmpty:r=!0}={}){if(!C(s))return!1;let o=s.length;if(o===0)return r?e==="every":!1;let i=l=>l==null?n:typeof t=="function"?We(t)?l instanceof t:t(l):t==="date"?z(l):t==="object"?Z(l):t==="plainObject"?xt(l):t==="number"?ot(l):typeof l===t;if(e==="every"){for(let l=0;l<o;l++)if(!i(s[l]))return!1;return!0}else{for(let l=0;l<o;l++)if(i(s[l]))return!0;return!1}}function $t(s,t=!1){if(!C(s))return[];let e=Array.from(s);return e.sort((n,r)=>n==null&&r==null?0:n==null?1:r==null?-1:n<r?t?1:-1:n>r?t?-1:1:0),e}function bt(s){if(!C(s))return{sum:null,count:0,min:null,max:null};let t=s.length;if(t===0)return{sum:null,count:0,min:null,max:null};let e=0,n=0,r=null,o=null;for(let i=0;i<t;i++){let l=s[i];if(l==null)continue;(r==null||l<r)&&(r=l),(o==null||l>o)&&(o=l);let a=et(l);a!==null&&(e+=a,n++)}return{sum:n>0?e:null,count:n,min:r,max:o}}function He(s){if(!lt(s,"number",{allowNulls:!0}))return null;let t=s.length,e=[];for(let r=0;r<t;r++){let o=s[r];o!=null&&e.push(o)}if(e.length===0)return null;e.sort((r,o)=>r-o);let n=Math.floor(e.length/2);return e.length%2!==0?e[n]:(e[n-1]+e[n])/2}function Ge(s){if(!C(s))return null;let t=s.length,e=new Map,n=0;for(let o=0;o<t;o++){let i=s[o];if(i==null)continue;let l=(e.get(i)??0)+1;e.set(i,l),l>n&&(n=l)}if(n===0)return[];let r=[];for(let[o,i]of e.entries())i===n&&r.push(o);return $t(r)}function at(s,t=null,{mode:e="both",returnStringOnNull:n=!1,maxScanStart:r=1,maxScanEnd:o=1,maxMatchesStart:i=1,maxMatchesEnd:l=1,trimFirst:a=!1,stringOptions:{literal:u=!1,caseInsensitive:c=!1}={}}={}){if(s==null)return n?"":null;let f=(x,I="both")=>I==="start"?x.trimStart():I==="end"?x.trimEnd():x.trim(),h=s;if(a&&t!=null&&(h=f(s,e)),t==null){let x=f(h,e);return n||x!==""?x:null}let p=t instanceof RegExp?x=>t.test(x):(()=>{let x=new Set(c?t.toLowerCase():t);return I=>x.has(c?I.toLowerCase():I)})(),m=h.length,y=new Uint8Array(m),A=u&&typeof t=="string"?({isStart:x,limit:I,maxMatches:U})=>{if(m===0||U===0)return;let E=t.length;if(E===0)return;let N=c?h.toLowerCase():h,$=c?t.toLowerCase():t,T=x?0:m-1,D=0,O=0;for(;T>=0&&T<m&&!(U!==null&&U>=0&&D>=U);){let R=x?T:T-E+1;if(!x&&R<0)break;let M=x?N.indexOf($,R):N.lastIndexOf($,R);if(M===-1)break;let q=x?M-T:T-(M+E-1);if(O+=q,I!==null&&I>=0&&O>=I)break;for(let G=0;G<E;G++)y[M+G]=1;D++,T=x?M+E:M-1}}:({isStart:x,limit:I,maxMatches:U})=>{if(m===0||U===0)return;let E=x?0:m-1,N=x?m:-1,$=x?1:-1,T=!1,D=0,O=0;for(let R=E;R!==N;R+=$)if(p(h[R])){if(!T){if(I!==null&&I>=0&&O>=I||U!==null&&U>=0&&D>=U)break;T=!0,D++}y[R]=1}else T=!1,O++};(e==="both"||e==="start")&&A({isStart:!0,limit:r,maxMatches:i}),(e==="both"||e==="end")&&A({isStart:!1,limit:o,maxMatches:l});let S="";for(let x=0;x<m;x++)y[x]===0&&(S+=h[x]);return n||S!==""?S:null}var j="*",Pt="*literal*";var _=s=>t=>{let e=t.length,n=new Array(e);for(let r=0;r<e;r++){let o=t[r];n[r]=o==null?null:s(o)}return n},v=(s,t,e)=>(n,r)=>{let o=n.length,i=s._resolve(t,r,o),l=new Array(o);if(C(i))for(let a=0;a<o;a++){let u=n[a],c=i[a];l[a]=u==null||c==null?null:e(u,c)}else for(let a=0;a<o;a++){let u=n[a];l[a]=u==null||i==null?null:e(u,i)}return l},g=(s,t)=>{let e=s.constructor,n=new e(s.colName||"");return Object.assign(n,s),n.ops=t?[...s.ops,t]:[...s.ops],n},wt=class{ops=[];outputName="";aggFn=null;groupingOpsIndex;partitionOpsIndex;partitionBy=null;_resolve(t,e,n){return t&&typeof t=="object"&&"evaluate"in t?t.isLiteral&&t.ops.length===1?t.literalValue:t.evaluate(e,n):t}alias(t){let e=this.constructor,n=new e(this.colName||"");return Object.assign(n,this),n.outputName=t,n}cast(t){return g(this,e=>{let n=e.length,r=new Array(n);for(let o=0;o<n;o++)r[o]=t.coerce(e[o]);return r})}debug(t){return g(this,e=>(console.log(`[DEBUG] ${t?t+": ":""}`,e),e))}evaluate(t,e){let n=this.colName,r=n&&n!=="*"?t[n]||new Array(e).fill(null):new Array(e).fill(null),o=this.ops,i=o.length;for(let l=0;l<i;l++)r=o[l](r,t);return r}_evaluatePre(t,e,n){let r=this.colName,o=r&&r!=="*"?e[r]||new Array(n).fill(null):new Array(n).fill(null),i=this.ops,l=t!==void 0?t:i.length;for(let a=0;a<l;a++)o=i[a](o,e);return o}_evaluatePost(t,e,n){let r=this.ops,o=t!==void 0?t:r.length,i=e;for(let l=o;l<r.length;l++)i=r[l](i,n);return i}evaluatePrePartition(t,e){return this._evaluatePre(this.partitionOpsIndex,t,e)}evaluatePostPartition(t,e){return this._evaluatePost(this.partitionOpsIndex,t,e)}evaluatePreGrouping(t,e){return this._evaluatePre(this.groupingOpsIndex,t,e)}evaluatePostGrouping(t,e){return this._evaluatePost(this.groupingOpsIndex,t,e)}};var Wt=s=>class extends s{abs(){return g(this,_(t=>Math.abs(t)))}acos(){return g(this,_(t=>t<-1||t>1?null:Math.acos(t)))}acosh(){return g(this,_(t=>t<1?null:Math.acosh(t)))}add(t){return g(this,v(this,t,(e,n)=>e+n))}asin(){return g(this,_(t=>t<-1||t>1?null:Math.asin(t)))}asinh(){return g(this,_(Math.asinh))}atan(){return g(this,_(Math.atan))}atanh(){return g(this,_(t=>t<=-1||t>=1?null:Math.atanh(t)))}cbrt(){return g(this,_(Math.cbrt))}ceil(){return g(this,_(Math.ceil))}clip(t=null,e=null){return g(this,_(n=>t!==null&&e!==null?yt({val:n,min:t,max:e}):t!==null?Math.max(n,t):e!==null?Math.min(n,e):n))}cos(){return g(this,_(Math.cos))}cosh(){return g(this,_(Math.cosh))}degrees(){return g(this,_(t=>t*(180/Math.PI)))}div(t){return g(this,v(this,t,(e,n)=>n===0?null:e/n))}exp(){return g(this,_(Math.exp))}expm1(){return g(this,_(Math.expm1))}floor(){return g(this,_(Math.floor))}floordiv(t){return g(this,v(this,t,(e,n)=>n===0?null:Math.floor(e/n)))}hypot(t){return g(this,v(this,t,(e,n)=>Math.hypot(e,n)))}log(t=Math.E){return g(this,_(e=>e<=0?null:t===Math.E?Math.log(e):Math.log(e)/Math.log(t)))}log1p(){return g(this,_(t=>t<=-1?null:Math.log1p(t)))}mod(t){return g(this,v(this,t,(e,n)=>n===0?null:e%n))}mul(t){return g(this,v(this,t,(e,n)=>e*n))}negate(){return g(this,_(t=>-t))}pow(t){return g(this,v(this,t,(e,n)=>Math.pow(e,n)))}radians(){return g(this,_(t=>t*(Math.PI/180)))}rand(t,{min:e=0,max:n=1,integer:r=!1}={}){return g(this,o=>{let i=o.length,l=new Float64Array(i),a=t!==void 0?Me(t):Math.random,u=n-e;for(let c=0;c<i;c++){let f=a();l[c]=r?Math.floor(f*(u+1))+e:f*u+e}return l})}round(t=0){let e=Math.pow(10,t);return g(this,_(n=>Math.round(n*e)/e))}sign(){return g(this,_(Math.sign))}sin(){return g(this,_(Math.sin))}sinh(){return g(this,_(Math.sinh))}sqrt(){return g(this,_(t=>t<0?null:Math.sqrt(t)))}sub(t){return g(this,v(this,t,(e,n)=>e-n))}tan(){return g(this,_(Math.tan))}tanh(){return g(this,_(Math.tanh))}trunc(){return g(this,_(Math.trunc))}};function W(s){return s==null?s:s instanceof Date?`d:${s.getTime()}`:s instanceof Uint8Array?`u:${s.toString()}`:typeof s=="object"||typeof s=="function"?String(s):s}var qt=s=>class extends s{between(t,e,n="both"){return g(this,(r,o)=>{let i=r.length,l=this._resolve(t,o,i),a=this._resolve(e,o,i),u=new Array(i),c=C(l),f=C(a);for(let h=0;h<i;h++){let p=r[h],m=c?l[h]:l,y=f?a[h]:a;if(p==null||m==null||y==null)u[h]=null;else{let d=n==="both"||n==="left"?p>=m:p>m,b=n==="both"||n==="right"?p<=y:p<y;u[h]=d&&b}}return u})}eq(t){return g(this,v(this,t,(e,n)=>e===n))}eq_missing(t){return g(this,(e,n)=>{let r=e.length,o=this._resolve(t,n,r),i=new Array(r);if(C(o))for(let l=0;l<r;l++){let a=e[l],u=o[l];a==null&&u==null?i[l]=!0:a==null||u==null?i[l]=!1:i[l]=a===u}else for(let l=0;l<r;l++){let a=e[l];a==null&&o==null?i[l]=!0:a==null||o==null?i[l]=!1:i[l]=a===o}return i})}ge(t){return g(this,v(this,t,(e,n)=>e>=n))}gt(t){return g(this,v(this,t,(e,n)=>e>n))}has_nulls(){return this._deriveAgg(t=>{for(let e=0;e<t.length;e++)if(t[e]==null)return!0;return!1})}is_close(t,e={}){let{abs_tol:n=1e-8,rel_tol:r=1e-8,nans_equal:o=!1}=e;return g(this,(i,l)=>{let a=i.length,u=this._resolve(t,l,a),c=C(u),f=new Array(a);for(let h=0;h<a;h++){let p=i[h],m=c?u[h]:u;if(p==null||m==null)f[h]=null;else if(Number.isNaN(p)||Number.isNaN(m))o&&Number.isNaN(p)&&Number.isNaN(m)?f[h]=!0:f[h]=!1;else if(!Number.isFinite(p)||!Number.isFinite(m))f[h]=p===m;else{let y=Math.abs(p-m),d=Math.max(r*Math.max(Math.abs(p),Math.abs(m)),n);f[h]=y<=d}}return f})}is_duplicated(){return g(this,t=>{let e=t.length,n=new Map,r=new Array(e);for(let i=0;i<e;i++){let l=W(t[i]);r[i]=l,n.set(l,(n.get(l)||0)+1)}let o=new Array(e);for(let i=0;i<e;i++)o[i]=(n.get(r[i])||0)>1;return o})}is_empty(t={}){let{ignoreNulls:e=!1}=t;return g(this,_(n=>{if(typeof n=="string")return n.length===0;if(C(n)){if(e){let r=n.length,o=0;for(let i=0;i<r;i++)n[i]!=null&&o++;return o===0}return n.length===0}return null}))}is_finite(){return g(this,_(Number.isFinite))}is_first_distinct(){return g(this,t=>{let e=t.length,n=new Set,r=new Array(e);for(let o=0;o<e;o++){let i=W(t[o]);n.has(i)?r[o]=!1:(n.add(i),r[o]=!0)}return r})}is_in(t){return g(this,(e,n)=>{let r=e.length,o=new Array(r);if(t&&typeof t=="object"&&"evaluate"in t){let i=t.evaluate(n,r);for(let l=0;l<r;l++){let a=e[l];if(a==null)o[l]=null;else{let u=i[l],c=new Set;if(C(u)){let f=u.length;for(let h=0;h<f;h++)c.add(W(u[h]))}else c.add(W(u));o[l]=c.has(W(a))}}}else{let i=C(t)?t:[],l=new Set,a=i.length;for(let u=0;u<a;u++)l.add(W(i[u]));for(let u=0;u<r;u++){let c=e[u];o[u]=c==null?null:l.has(W(c))}}return o})}is_infinite(){return g(this,_(t=>t===1/0||t===-1/0))}is_last_distinct(){return g(this,t=>{let e=t.length,n=new Set,r=new Array(e);for(let o=e-1;o>=0;o--){let i=W(t[o]);n.has(i)?r[o]=!1:(n.add(i),r[o]=!0)}return r})}is_n_distinct(t){return this._deriveAgg(e=>{let n=new Set,r=e.length;for(let o=0;o<r;o++)n.add(W(e[o]));return n.size===t})}is_nan(){return g(this,_(Number.isNaN))}is_not_nan(){return g(this,_(t=>!Number.isNaN(t)))}is_not_null(){return g(this,t=>{let e=t.length,n=new Array(e);for(let r=0;r<e;r++)n[r]=t[r]!=null;return n})}is_null(){return g(this,t=>{let e=t.length,n=new Array(e);for(let r=0;r<e;r++)n[r]=t[r]==null;return n})}is_unique(){return g(this,t=>{let e=t.length,n=new Map,r=new Array(e);for(let i=0;i<e;i++){let l=W(t[i]);r[i]=l,n.set(l,(n.get(l)||0)+1)}let o=new Array(e);for(let i=0;i<e;i++)o[i]=n.get(r[i])===1;return o})}le(t){return g(this,v(this,t,(e,n)=>e<=n))}lt(t){return g(this,v(this,t,(e,n)=>e<n))}ne(t){return g(this,v(this,t,(e,n)=>e!==n))}ne_missing(t){return g(this,(e,n)=>{let r=e.length,o=this._resolve(t,n,r),i=new Array(r);if(C(o))for(let l=0;l<r;l++){let a=e[l],u=o[l];a==null&&u==null?i[l]=!1:a==null||u==null?i[l]=!0:i[l]=a!==u}else for(let l=0;l<r;l++){let a=e[l];a==null&&o==null?i[l]=!1:a==null||o==null?i[l]=!0:i[l]=a!==o}return i})}not_in(t){return g(this,(e,n)=>{let r=e.length,o=new Array(r);if(t&&typeof t=="object"&&"evaluate"in t){let i=t.evaluate(n,r);for(let l=0;l<r;l++){let a=e[l];if(a==null)o[l]=null;else{let u=i[l],c=new Set;if(C(u)){let f=u.length;for(let h=0;h<f;h++)c.add(W(u[h]))}else c.add(W(u));o[l]=!c.has(W(a))}}}else{let i=C(t)?t:[],l=new Set,a=i.length;for(let u=0;u<a;u++)l.add(W(i[u]));for(let u=0;u<r;u++){let c=e[u];o[u]=c==null?null:!l.has(W(c))}}return o})}};var ut=class extends Error{constructor(t){super(t),this.name=this.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}},V=class extends ut{},B=class extends V{constructor(t,e){super(e||`Column "${t}" does not exist in the DataFrame.`)}},ct=class extends ut{},nt=class extends ut{};var Ht=s=>class extends s{aggFn=this.aggFn||null;_deriveAgg(t){let e=g(this);return e.aggFn=t,e.groupingOpsIndex=this.ops.length,e.partitionOpsIndex=this.ops.length,e}all(){return this._deriveAgg(t=>{for(let e=0;e<t.length;e++)if(!t[e])return!1;return!0})}all_null(){return this._deriveAgg(t=>{for(let e=0;e<t.length;e++)if(t[e]!=null)return!1;return!0})}any(){return this._deriveAgg(t=>{for(let e=0;e<t.length;e++)if(t[e])return!0;return!1})}any_null(){return this._deriveAgg(t=>{for(let e=0;e<t.length;e++)if(t[e]==null)return!0;return!1})}avg(){return this._deriveAgg(t=>{let e=0,n=0;for(let r=0;r<t.length;r++)t[r]!=null&&(e+=t[r],n++);return n?e/n:null})}count(t={}){return t.includeNulls?this._deriveAgg(e=>e.length):this._deriveAgg(e=>{let n=0;for(let r=0;r<e.length;r++)e[r]!=null&&n++;return n})}first(){return this._deriveAgg(t=>t[0]??null)}last(){return this._deriveAgg(t=>t[t.length-1]??null)}max(){return this._deriveAgg(t=>{let e=null;for(let n=0;n<t.length;n++)t[n]!=null&&(e===null||t[n]>e)&&(e=t[n]);return e})}mean(){return this.avg()}median(){return this._deriveAgg(t=>{let e=[];for(let o=0;o<t.length;o++)t[o]!=null&&e.push(t[o]);let n=e.length;if(!n)return null;e.sort((o,i)=>o-i);let r=Math.floor(n/2);return n%2!==0?e[r]:(e[r-1]+e[r])/2})}min(){return this._deriveAgg(t=>{let e=null;for(let n=0;n<t.length;n++)t[n]!=null&&(e===null||t[n]<e)&&(e=t[n]);return e})}mode(){return this._deriveAgg(t=>{let e=new Map,n=0,r=null;for(let o=0;o<t.length;o++){let i=t[o];if(i==null)continue;let l=(e.get(i)||0)+1;e.set(i,l),l>n&&(n=l,r=i)}return r})}n_unique(){return this._deriveAgg(t=>new Set(t).size)}quantile(t){if(t<0||t>1)throw new nt("Quantile q must be between 0 and 1");return this._deriveAgg(e=>{let n=[];for(let a=0;a<e.length;a++)e[a]!=null&&n.push(e[a]);let r=n.length;if(!r)return null;n.sort((a,u)=>a-u);let o=(r-1)*t,i=Math.floor(o),l=Math.ceil(o);return i===l?n[i]:n[i]+(o-i)*(n[l]-n[i])})}std(){return this._deriveAgg(t=>{let e=0,n=0;for(let i=0;i<t.length;i++)t[i]!=null&&(e+=t[i],n++);if(n<2)return 0;let r=e/n,o=0;for(let i=0;i<t.length;i++)t[i]!=null&&(o+=(t[i]-r)**2);return Math.sqrt(o/(n-1))})}sum(){return this._deriveAgg(t=>{let e=null;for(let n=0;n<t.length;n++)t[n]!=null&&(e=(e??0)+t[n]);return e})}};var Gt=s=>class extends s{partitionBy=this.partitionBy||null;_rolling(t,e){let n=g(this);return n.partitionOpsIndex=this.ops.length,n.groupingOpsIndex=this.ops.length,n.evaluateWindow=function(r,o,i){let l=Math.max(0,i-t+1),a=i+1,u=r.slice(l,a);return e(u)},n}get isWindow(){return this.partitionBy!==null||this.evaluateWindow!==void 0||this.aggFn!==null}cum_count(t=!1){let e=g(this);return e.partitionOpsIndex=this.ops.length,e.groupingOpsIndex=this.ops.length,e.evaluateWindow=function(n,r,o){let i=0,l=t?o:0,a=t?n.length-1:o;for(let u=l;u<=a;u++)n[u]!=null&&i++;return i},e}cum_max(t=!1){let e=g(this);return e.partitionOpsIndex=this.ops.length,e.groupingOpsIndex=this.ops.length,e.evaluateWindow=function(n,r,o){let i=null,l=t?o:0,a=t?n.length-1:o;for(let u=l;u<=a;u++){let c=n[u];c!=null&&(i===null||c>i)&&(i=c)}return i},e}cum_min(t=!1){let e=g(this);return e.partitionOpsIndex=this.ops.length,e.groupingOpsIndex=this.ops.length,e.evaluateWindow=function(n,r,o){let i=null,l=t?o:0,a=t?n.length-1:o;for(let u=l;u<=a;u++){let c=n[u];c!=null&&(i===null||c<i)&&(i=c)}return i},e}cum_prod(t=!1){let e=g(this);return e.partitionOpsIndex=this.ops.length,e.groupingOpsIndex=this.ops.length,e.evaluateWindow=function(n,r,o){let i=1,l=!1,a=t?o:0,u=t?n.length-1:o;for(let c=a;c<=u;c++){let f=n[c];f!=null&&(i*=f,l=!0)}return l?i:null},e}cum_sum(t=!1){let e=g(this);return e.partitionOpsIndex=this.ops.length,e.groupingOpsIndex=this.ops.length,e.evaluateWindow=function(n,r,o){let i=0,l=t?o:0,a=t?n.length-1:o;for(let u=l;u<=a;u++){let c=n[u];c!=null&&(i+=c)}return i},e}dense_rank(){let t=g(this);return t.partitionOpsIndex=this.ops.length,t.groupingOpsIndex=this.ops.length,t.evaluateWindow=function(e,n,r){let o=Array.from(new Set(e)).sort((a,u)=>a-u),i=new Map;for(let a=0;a<o.length;a++)i.set(o[a],a+1);let l=e[r];return i.get(l)??null},t}lag(t=1,e=null){let n=g(this);return n.partitionOpsIndex=this.ops.length,n.groupingOpsIndex=this.ops.length,n.evaluateWindow=function(r,o,i){let l=e;return i-t>=0&&(l=r[i-t]),l},n}lead(t=1,e=null){let n=g(this);return n.partitionOpsIndex=this.ops.length,n.groupingOpsIndex=this.ops.length,n.evaluateWindow=function(r,o,i){let l=e;return i+t<r.length&&(l=r[i+t]),l},n}over(t){let e=g(this),n=Array.isArray(t)?t:[t];return e.partitionBy=n,e}rank(){let t=g(this);return t.partitionOpsIndex=this.ops.length,t.groupingOpsIndex=this.ops.length,t.evaluateWindow=function(e,n,r){let o=[...e].sort((a,u)=>a-u),i=new Map;for(let a=0;a<o.length;a++){let u=o[a];i.has(u)||i.set(u,a+1)}let l=e[r];return i.get(l)??null},t}rolling_max(t){return this._rolling(t,e=>{let n=null;for(let r=0;r<e.length;r++)e[r]!=null&&(n===null||e[r]>n)&&(n=e[r]);return n})}rolling_mean(t){return this._rolling(t,e=>{let n=0,r=0;for(let o=0;o<e.length;o++)e[o]!=null&&(n+=e[o],r++);return r?n/r:null})}rolling_median(t){return this._rolling(t,e=>{let n=[];for(let o=0;o<e.length;o++)e[o]!=null&&n.push(e[o]);if(!n.length)return null;n.sort((o,i)=>o-i);let r=Math.floor(n.length/2);return n.length%2!==0?n[r]:(n[r-1]+n[r])/2})}rolling_min(t){return this._rolling(t,e=>{let n=null;for(let r=0;r<e.length;r++)e[r]!=null&&(n===null||e[r]<n)&&(n=e[r]);return n})}rolling_quantile(t,e){return this._rolling(e,n=>{let r=[];for(let u=0;u<n.length;u++)n[u]!=null&&r.push(n[u]);let o=r.length;if(o===0)return null;r.sort((u,c)=>u-c);let i=t*(o-1),l=Math.floor(i),a=Math.ceil(i);return l===a?r[l]:r[l]+(i-l)*(r[a]-r[l])})}rolling_rank(t){let e=g(this);return e.partitionOpsIndex=this.ops.length,e.groupingOpsIndex=this.ops.length,e.evaluateWindow=function(n,r,o){let i=Math.max(0,o-t+1),l=o+1,a=n.slice(i,l),u=n[o];if(u==null)return null;let c=[];for(let p=0;p<a.length;p++)a[p]!=null&&c.push(a[p]);if(c.length===0)return null;let f=[...c].sort((p,m)=>p-m),h=new Map;for(let p=0;p<f.length;p++){let m=f[p];h.has(m)||h.set(m,p+1)}return h.get(u)??null},e}rolling_std(t){return this._rolling(t,e=>{let n=0,r=0;for(let l=0;l<e.length;l++)e[l]!=null&&(n+=e[l],r++);if(r<2)return 0;let o=n/r,i=0;for(let l=0;l<e.length;l++)e[l]!=null&&(i+=(e[l]-o)**2);return Math.sqrt(i/(r-1))})}rolling_sum(t){return this._rolling(t,e=>{let n=null;for(let r=0;r<e.length;r++)e[r]!=null&&(n=(n??0)+e[r]);return n})}row_number(){let t=g(this);return t.partitionOpsIndex=this.ops.length,t.groupingOpsIndex=this.ops.length,t.evaluateWindow=function(e,n,r){return r+1},t.outputName="row_number",t}};var Mt=class{constructor(t){this.expr=t}expr;_deriveString(t){return g(this.expr,_(e=>t(String(e))))}concat(t){return g(this.expr,v(this.expr,t,(e,n)=>String(e)+String(n)))}contains(t){return t==null?g(this.expr,e=>new Array(e.length).fill(null)):this._deriveString(e=>t instanceof RegExp?t.test(e):e.includes(t))}count_matches(t){return t==null?g(this.expr,e=>new Array(e.length).fill(null)):this._deriveString(e=>{if(t instanceof RegExp){let n=t.global?t:new RegExp(t.source,t.flags+"g"),r=e.match(n);return r?r.length:0}else{let n=0,r=e.indexOf(t);for(;r!==-1;)n++,r=e.indexOf(t,r+t.length);return n}})}decode_uri_component(){return this._deriveString(t=>{try{return decodeURIComponent(t)}catch{return t}})}encode_uri_component(){return this._deriveString(t=>{try{return encodeURIComponent(t)}catch{return t}})}ends_with(t){return this._deriveString(e=>e.endsWith(t))}explode(){return this._deriveString(t=>t.split(""))}extract(t,e=0){return t==null?g(this.expr,n=>new Array(n.length).fill(null)):this._deriveString(n=>{let r=n.match(t);return r&&r[e]!==void 0?r[e]:null})}len(){return this.len_chars()}len_bytes(){return this._deriveString(t=>new TextEncoder().encode(t).length)}len_chars(){return this._deriveString(t=>t.length)}lower(){return this._deriveString(t=>t.toLowerCase())}lpad(t,e=" "){return this._deriveString(n=>n.padStart(t,e))}pad_end(t,e=" "){return this.rpad(t,e)}pad_start(t,e=" "){return this.lpad(t,e)}replace(t,e){return t==null?g(this.expr,n=>new Array(n.length).fill(null)):this._deriveString(n=>n.replace(t,e))}replace_all(t,e){return t==null?g(this.expr,n=>new Array(n.length).fill(null)):this._deriveString(n=>{if(t instanceof RegExp){let r=t.global?t:new RegExp(t.source,t.flags+"g");return n.replace(r,e)}return n.replaceAll(t,e)})}reverse(){return this._deriveString(t=>t.split("").reverse().join(""))}rpad(t,e=" "){return this._deriveString(n=>n.padEnd(t,e))}slice(t,e){return this._deriveString(n=>{let r=t<0?n.length+t:t,o=e!==void 0?r+e:void 0;return n.slice(r,o)})}slice_str(t,e){return this.slice(t,e)}split(t){return this._deriveString(e=>e.split(t))}starts_with(t){return this._deriveString(e=>e.startsWith(t))}strip_chars(t,e){return this._deriveString(n=>at(n,t,{mode:"both",...e}))}strip_chars_end(t,e){return this._deriveString(n=>at(n,t,{mode:"end",...e}))}strip_chars_start(t,e){return this._deriveString(n=>at(n,t,{mode:"start",...e}))}strip_prefix(t){return this._deriveString(e=>at(e,t,{mode:"start",maxScanStart:1,maxMatchesStart:1,returnStringOnNull:!0,stringOptions:{literal:!0}}))}strip_suffix(t){return this._deriveString(e=>at(e,t,{mode:"end",maxScanEnd:1,maxMatchesEnd:1,returnStringOnNull:!0,stringOptions:{literal:!0}}))}strptime(t,e=!0){return this._deriveString(n=>Pe(n,t,e))}to_date(){return this._deriveString(t=>{let e=Y(t);if(!e)return null;let n=new Date(e);return n.setUTCHours(0,0,0,0),n})}to_datetime(){return this._deriveString(Y)}to_decimal(t,e){return this._deriveString(n=>Ct(n,{precision:t,scale:e}))}to_integer(){return this._deriveString(t=>H(t))}to_lowercase(){return this.lower()}to_time(){return this._deriveString(t=>{let e=Y(t);if(e)return e.toISOString().split("T")[1].slice(0,12);let n=t.trim();if(St.test(n)){let r=new Date(`1970-01-01T${n}${kt.test(n)?"":"Z"}`);if(z(r))return r.toISOString().split("T")[1].slice(0,12)}return null})}to_titlecase(){return this._deriveString(t=>t.replace(/\b\w/g,e=>e.toUpperCase()))}to_uppercase(){return this.upper()}trim(){return this.strip_chars()}trim_end(){return this.strip_chars_end()}trim_start(){return this.strip_chars_start()}upper(){return this._deriveString(t=>t.toUpperCase())}zfill(t){return this._deriveString(e=>e.padStart(t,"0"))}},zt=s=>class extends s{get str(){return new Mt(this)}};var Yt=s=>class extends s{and(t){return g(this,(e,n)=>{let r=e.length,o=this._resolve(t,n,r),i=C(o),l=new Array(r);for(let a=0;a<r;a++){let u=e[a],c=i?o[a]:o;u===!1||c===!1?l[a]=!1:u==null||c==null?l[a]=null:l[a]=!0}return l})}not(){return g(this,_(t=>!t))}or(t){return g(this,(e,n)=>{let r=e.length,o=this._resolve(t,n,r),i=C(o),l=new Array(r);for(let a=0;a<r;a++){let u=e[a],c=i?o[a]:o;u===!0||c===!0?l[a]=!0:u==null||c==null?l[a]=null:l[a]=!1}return l})}xor(t){return g(this,v(this,t,(e,n)=>!!e!=!!n))}};var Ut=class{constructor(t){this.expr=t}expr;_deriveDate(t){return g(this.expr,_(e=>{let n=Y(e);return n?t(n):null}))}_deriveDuration(t){return g(this.expr,_(e=>typeof e=="number"?t(e):null))}century(){return this._deriveDate(Ne)}date(){return this._deriveDate(t=>new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())))}datetime(){return this._deriveDate(t=>t)}day(){return this._deriveDate(t=>t.getUTCDate())}epoch(t="ms"){return this._deriveDate(e=>Fe(e,t))}hour(){return this._deriveDate(t=>t.getUTCHours())}is_leap_year(){return this._deriveDate(Ke)}microsecond(){return this._deriveDate(t=>t.getUTCMilliseconds()*Et)}millennium(){return this._deriveDate(je)}millisecond(){return this._deriveDate(t=>t.getUTCMilliseconds())}minute(){return this._deriveDate(t=>t.getUTCMinutes())}month(){return this._deriveDate(t=>t.getUTCMonth()+1)}month_end(){return this._deriveDate(t=>Kt(t,1,0))}month_start(){return this._deriveDate(t=>Kt(t,0,1))}nanosecond(){return this._deriveDate(t=>t.getUTCMilliseconds()*Ot)}ordinal_day(){return this._deriveDate(Ve)}quarter(){return this._deriveDate(Be)}second(){return this._deriveDate(t=>t.getUTCSeconds())}strftime(t,e){return this._deriveDate(n=>$e(n,t,e))}time(){return this._deriveDate(t=>t.toISOString().split("T")[1].slice(0,12))}timestamp(t="ms"){return this.epoch(t)}to_string(t,e){return this.strftime(t,e)}total_days(){return this._deriveDuration(t=>t/dt)}total_hours(){return this._deriveDuration(t=>t/Re)}total_microseconds(){return this._deriveDuration(t=>t*Et)}total_milliseconds(){return this._deriveDuration(t=>t)}total_minutes(){return this._deriveDuration(t=>t/ve)}total_nanoseconds(){return this._deriveDuration(t=>t*Ot)}total_seconds(){return this._deriveDuration(t=>t/Bt)}week(){return this._deriveDate(Le)}weekday(){return this._deriveDate(t=>t.getUTCDay()||7)}year(){return this._deriveDate(t=>t.getUTCFullYear())}},Zt=s=>class extends s{get dt(){return new Ut(this)}};var vt=class{constructor(t){this.expr=t}expr;_deriveList(t){return g(this.expr,_(e=>C(e)?t(e):null))}all(){return this._deriveList(t=>{let e=Array.from(t);for(let n=0;n<e.length;n++)if(!e[n])return!1;return!0})}any(){return this._deriveList(t=>{let e=Array.from(t);for(let n=0;n<e.length;n++)if(e[n])return!0;return!1})}contains(t){return this._deriveList(e=>Array.from(e).includes(t))}contains_all(t){return this._deriveList(e=>{let n=Array.from(e);for(let r=0;r<t.length;r++)if(!n.includes(t[r]))return!1;return!0})}contains_any(t){return this._deriveList(e=>{let n=Array.from(e);for(let r=0;r<t.length;r++)if(n.includes(t[r]))return!0;return!1})}count_matches(t){return this._deriveList(e=>{let n=Array.from(e),r=0;for(let o of n)o===t&&r++;return r})}drop_nulls(){return this._deriveList(t=>{let e=Array.from(t),n=[];for(let r=0;r<e.length;r++)e[r]!=null&&n.push(e[r]);return n})}first(t=!0){return this.get(0,t)}gather(t,e=!0){let n=Array.isArray(t)?t:[t];return this._deriveList(r=>{let o=r.length,i=new Array(n.length);for(let l=0;l<n.length;l++){let a=n[l],u=r.at(a);if(u===void 0&&!e)throw new nt(`Index ${a} is out of bounds for list of length ${o}`);i[l]=u??null}return i})}gather_every(t,e=0){if(t<=0)throw new nt("Step size n must be positive");return this._deriveList(n=>{let r=n.length,o=[];for(let i=e;i<r;i+=t)o.push(n[i]);return o})}get(t,e=!0){return this._deriveList(n=>{let r=n.at(t);if(r===void 0&&!e)throw new nt(`Index ${t} is out of bounds for list of length ${n.length}`);return r??null})}join(t,{ignoreNulls:e=!1}={}){return this._deriveList(n=>{let r=Array.from(n),o=[];for(let i=0;i<r.length;i++){let l=r[i];l!=null?o.push(String(l)):e||o.push("")}return o.join(t)})}last(t=!0){return this.get(-1,t)}len(){return this.lengths()}lengths(){return this._deriveList(t=>t.length)}max(){return this._deriveList(t=>bt(t).max)}mean(){return this._deriveList(t=>{let{sum:e,count:n}=bt(t);return e!==null&&n>0?e/n:null})}median(){return this._deriveList(He)}min(){return this._deriveList(t=>bt(t).min)}mode(){return this._deriveList(Ge)}n_unique(){return this._deriveList(t=>new Set(Array.from(t)).size)}reverse(){return this._deriveList(t=>Array.from(t).reverse())}slice(t,e){return this._deriveList(n=>{let r=Array.from(n),o=t<0?Math.max(0,r.length+t):t,i=e!==void 0?o+e:r.length;return r.slice(o,i)})}sort(t=!1){return this._deriveList(e=>$t(e,t))}sum(){return this._deriveList(t=>bt(t).sum)}unique(){return this._deriveList(t=>Array.from(new Set(Array.from(t))))}},Xt=s=>class extends s{get list(){return new vt(this)}};var ze=s=>class extends s{fill_null(t){return g(this,(e,n)=>{let r=e.length,o=this._resolve(t,n,r),i=new Array(r);if(C(o))for(let l=0;l<r;l++){let a=e[l];i[l]=a??o[l]}else for(let l=0;l<r;l++){let a=e[l];i[l]=a??o}return i})}reverse(){return g(this,t=>t.slice().reverse())}};var k=class extends Xt(Zt(Yt(zt(Gt(Ht(qt(Wt(ze(wt))))))))){colName;excludedCols=[];constructor(t){super(),this.colName=String(t),this.outputName=this.colName}};function it(s){let t=new k(Pt);return t.isLiteral=!0,t.literalValue=s,t.ops.push(e=>{let n=e.length,r=new Array(n);for(let o=0;o<n;o++)r[o]=s;return r}),t}function Jt(){return new k("*")}function Qt(s){let t=new k("*");return t.excludedCols=Array.isArray(s)?s:[s],t}function te(...s){let t=s.length===1&&Array.isArray(s[0])?s[0]:s,e=new k("*coalesce*");return e.ops.push((n,r)=>{let o=n.length,l=t.map(c=>typeof c=="string"?new k(c):c&&typeof c=="object"&&"evaluate"in c?c:it(c)).map(c=>c.evaluate(r,o)),a=new Array(o),u=l.length;for(let c=0;c<o;c++){let f=null;for(let h=0;h<u;h++){let p=l[h][c];if(p!=null){f=p;break}}a[c]=f}return a}),e}var Rt=class{predicates;values;constructor(t,e){this.predicates=t,this.values=e}then(t){return new _t(this.predicates,this.values.concat(t))}},Ft=class{predicates;constructor(t){this.predicates=[t]}then(t){return new _t(this.predicates,[t])}},_t=class s extends k{predicates;values;otherwiseValue;constructor(t,e,n=null){super(typeof t=="string"?t:"*when*"),this.predicates=Array.isArray(t)?t:[],this.values=e||[],this.otherwiseValue=n,this.ops.push((r,o)=>{let i=r.length,l=d=>typeof d=="string"?d in o?new k(d):it(d):d&&typeof d=="object"&&"evaluate"in d?d:it(d),a=this.predicates.map(l),u=this.values.map(l),c=l(this.otherwiseValue),f=a.map(d=>d.evaluate(o,i)),h=u.map(d=>d.evaluate(o,i)),p=c.evaluate(o,i),m=new Array(i),y=f.length;for(let d=0;d<i;d++){let b=!1;for(let w=0;w<y;w++)if(f[w][d]===!0){m[d]=h[w][d],b=!0;break}b||(m[d]=p[d])}return m})}when(t){return new Rt(this.predicates.concat(t),this.values)}otherwise(t){return new s(this.predicates,this.values,t)}};function ee(s){return new Ft(s)}function ft(s,t,e){let n=[],r=e?new Set(e):new Set;for(let o of s)if(typeof o=="string")n.push(new k(o));else if(o instanceof k&&o.colName==="*"){let i=new Set(o.excludedCols);for(let l of t)if(!r.has(l)&&!i.has(l)){let a=new k(l);a.ops=[...o.ops],a.aggFn=o.aggFn,a.partitionOpsIndex=o.partitionOpsIndex,a.groupingOpsIndex=o.groupingOpsIndex,a.partitionBy=o.partitionBy,o.evaluateWindow&&(a.evaluateWindow=o.evaluateWindow),o.outputName&&o.outputName!=="*"&&(a.outputName=o.outputName),n.push(a)}}else if(o&&typeof o=="object"&&"evaluate"in o&&!o.colName){for(let i of t)if(!r.has(i)){let l=new k(i);l.ops=[...o.ops],l.aggFn=o.aggFn,l.groupingOpsIndex=o.groupingOpsIndex,l.partitionOpsIndex=o.partitionOpsIndex,n.push(l)}}else n.push(o);return n}var K=class{get isNumeric(){return!1}get isInteger(){return!1}get isFloat(){return!1}get isSigned(){return!1}get isUnsigned(){return!1}get isTemporal(){return!1}get isNested(){return!1}get isBoolean(){return!1}get isString(){return!1}get isUtf8(){return!1}get isObject(){return!1}get isNull(){return!1}get isBinary(){return!1}},ht=class extends K{get isNumeric(){return!0}},Nt=class extends ht{get isInteger(){return!0}},X=class extends Nt{get isSigned(){return!0}},J=class extends Nt{get isUnsigned(){return!0}},mt=class extends ht{get isFloat(){return!0}},Q=class extends K{get isTemporal(){return!0}},pt=class extends K{get isNested(){return!0}};var ne=class extends X{name="Int8";coerce(t){return H(t,"Int8")}equals(t){return t.name==="Int8"}allocate(t){return new Int8Array(t)}},Ye=new ne;var re=class extends X{name="Int16";coerce(t){return H(t,"Int16")}equals(t){return t.name==="Int16"}allocate(t){return new Int16Array(t)}},Ze=new re;var oe=class extends X{name="Int32";coerce(t){return H(t)}equals(t){return t.name==="Int32"}allocate(t){return new Int32Array(t)}},Xe=new oe;var se=class extends X{name="Int64";coerce(t){return It(t)}equals(t){return t.name==="Int64"}allocate(t){return new BigInt64Array(t)}},Je=new se;var ie=class extends J{name="UInt8";coerce(t){return H(t,"UInt8")}equals(t){return t.name==="UInt8"}allocate(t){return new Uint8Array(t)}},Qe=new ie;var le=class extends J{name="UInt16";coerce(t){return H(t,"UInt16")}equals(t){return t.name==="UInt16"}allocate(t){return new Uint16Array(t)}},tn=new le;var ae=class extends J{name="UInt32";coerce(t){return H(t,"UInt32")}equals(t){return t.name==="UInt32"}allocate(t){return new Uint32Array(t)}},en=new ae;var ue=class extends J{name="UInt64";coerce(t){return It(t)}equals(t){return t.name==="UInt64"}allocate(t){return new BigUint64Array(t)}},nn=new ue;var ce=class extends mt{name="Float32";coerce(t){return At(t,"Float32")}equals(t){return t.name==="Float32"}allocate(t){return new Float32Array(t)}},rn=new ce;var fe=class extends mt{name="Float64";coerce(t){return At(t)}equals(t){return t.name==="Float64"}allocate(t){return new Float64Array(t)}},on=new fe;var Lt=class s extends ht{constructor(e,n){super();this.precision=e;this.scale=n;this.name=e!==void 0&&n!==void 0?`Decimal(${e}, ${n})`:"Decimal"}precision;scale;name;coerce(e){return Ct(e,{precision:this.precision,scale:this.scale})}equals(e){return e instanceof s&&this.precision===e.precision&&this.scale===e.scale}allocate(e){return new Array(e).fill(null)}};var he=class extends K{name="Boolean";get isBoolean(){return!0}coerce(t){return t==null?null:!!t}equals(t){return t.name==="Boolean"}allocate(t){return new Array(t).fill(null)}},sn=new he;var me=class extends K{name="Utf8";get isString(){return!0}get isUtf8(){return!0}coerce(t){return t==null?null:String(t)}equals(t){return t.name==="Utf8"}allocate(t){return new Array(t).fill(null)}},ln=new me;var pe=class extends K{name="Binary";get isBinary(){return!0}coerce(t){return qe(t)}equals(t){return t.name==="Binary"}allocate(t){return new Array(t).fill(null)}},an=new pe;var ge=class extends Q{name="Date";coerce(t){let e=Y(t);return e?(e.setUTCHours(0,0,0,0),e):null}equals(t){return t.name==="Date"}allocate(t){return new Array(t).fill(null)}},un=new ge;var ye=class extends Q{name="Datetime";coerce(t){return Y(t)}equals(t){return t.name==="Datetime"}allocate(t){return new Array(t).fill(null)}},cn=new ye;var de=class extends Q{name="Time";coerce(t){if(t==null)return null;if(typeof t=="string"){let n=t.trim();if(St.test(n)){let r=new Date(`1970-01-01T${n}${kt.test(n)?"":"Z"}`);if(z(r))return r.toISOString().split("T")[1].slice(0,12)}}let e=Y(t);return e?e.toISOString().split("T")[1].slice(0,12):null}equals(t){return t.name==="Time"}allocate(t){return new Array(t).fill(null)}},fn=new de;var xe=class extends Q{name="Duration";coerce(t){return et(t)}equals(t){return t.name==="Duration"}allocate(t){return new Array(t).fill(null)}},hn=new xe;var be=class extends K{name="Object";get isObject(){return!0}coerce(t){return t===void 0?null:t}equals(t){return t.name==="Object"}allocate(t){return new Array(t).fill(null)}},mn=new be;var we=class extends K{name="Null";get isNull(){return!0}coerce(t){return null}equals(t){return t.name==="Null"}allocate(t){return new Array(t).fill(null)}},pn=new we;var _e=class s extends pt{constructor(e){super();this.innerType=e}innerType;name="List";coerce(e){if(e==null)return null;let n=C(e)?Array.from(e):[e],r=n.length,o=new Array(r);for(let i=0;i<r;i++)o[i]=this.innerType.coerce(n[i]);return o}equals(e){return e instanceof s&&this.innerType.equals(e.innerType)}allocate(e){return new Array(e).fill(null)}},gn=s=>new _e(s);var Te=class s extends pt{constructor(e){super();this.fields=e}fields;name="Struct";coerce(e){if(!Z(e))return null;let n={};for(let[r,o]of Object.entries(this.fields))n[r]=o.coerce(e[r]);return n}equals(e){if(!(e instanceof s))return!1;let n=Object.keys(this.fields),r=Object.keys(e.fields);if(n.length!==r.length)return!1;for(let o of n)if(!e.fields[o]||!this.fields[o].equals(e.fields[o]))return!1;return!0}allocate(e){return new Array(e).fill(null)}},yn=s=>new Te(s);var L={Int8:Ye,Int16:Ze,Int32:Xe,Int64:Je,UInt8:Qe,UInt16:tn,UInt32:en,UInt64:nn,Float32:rn,Float64:on,Decimal:(s,t)=>new Lt(s,t),Boolean:sn,Utf8:ln,Binary:an,Date:un,Datetime:cn,Time:fn,Duration:hn,Object:mn,Null:pn,List:gn,Struct:yn};function kn(s,t,e){let n=new Map,r=e.length,o=new Array(r);for(let i=0;i<r;i++){let l=e[i];if(typeof l=="string"){if(!(l in s))throw new B(l,`Partition key "${l}" does not exist in the DataFrame.`);o[i]=s[l]}else o[i]=l.evaluate(s,t)}for(let i=0;i<t;i++){let l=new Array(o.length);for(let c=0;c<o.length;c++){let f=o[c][i];l[c]=f==null?"":String(f)}let a=l.join("\0"),u=n.get(a);u===void 0&&(u=[],n.set(a,u)),u.push(i)}return n}function jt(s,t,e){let n=new Array(e);if(e===0)return n;let r=s.partitionBy||[],o=kn(t,e,r),i=s.evaluatePrePartition(t,e);for(let l of o.values()){let a=l.length,u=new Array(a);for(let c=0;c<a;c++)u[c]=i[l[c]];if(s.evaluateWindow){for(let c=0;c<a;c++)n[l[c]]=s.evaluateWindow(u,l,c);continue}if(s.aggFn){let c=s.aggFn(u);for(let f=0;f<a;f++)n[l[f]]=c;continue}for(let c=0;c<a;c++)n[l[c]]=i[l[c]]}return s.evaluatePostPartition(n,t)}function De(s){if(!Array.isArray(s)||s.length===0)return{columns:{},height:0};let t=s.length,e=new Set;for(let o=0;o<t;o++){let i=s[o];if(Z(i)){let l=Object.keys(i);for(let a=0;a<l.length;a++)e.add(l[a])}}let n=Array.from(e),r={};for(let o=0;o<n.length;o++)r[n[o]]=new Array(t);for(let o=0;o<t;o++){let i=s[o]||{};for(let l=0;l<n.length;l++){let a=n[l],u=i[a];r[a][o]=u===void 0?null:u}}return{columns:r,height:t}}function Ae(s,t){let e=Object.keys(s),n=new Array(t);for(let r=0;r<t;r++){let o={};for(let i=0;i<e.length;i++){let l=e[i],a=s[l][r];o[l]=a===void 0?null:a}n[r]=o}return n}function En(s,t,e){let n={};for(let r=0;r<e.length;r++){let o=e[r],i=s[o][t];n[o]=i===void 0?null:i}return n}function rt(s){if(s.length===0)return L.Utf8;let t=!0,e=!0,n=!0,r=!0,o=!0,i=!0,l=!1,a=!1,u=[];for(let c=0;c<s.length;c++){let f=s[c];if(f!=null){if(a=!0,!Array.isArray(f))i=!1;else for(let h=0;h<f.length;h++)u.push(f[h]);f instanceof Date&&(l=!0),typeof f!="boolean"&&(t=!1),typeof f!="bigint"&&(r=!1),typeof f!="number"?(n=!1,e=!1):Number.isInteger(f)||(e=!1),!(f instanceof Date)&&(typeof f!="string"||isNaN(Date.parse(f)))&&(o=!1)}}if(!a)return L.Utf8;if(i){let c=rt(u);return L.List(c)}if(t)return L.Boolean;if(r)return L.Int64;if(n&&!e)return L.Float64;if(n&&e){let c=!0;for(let f=0;f<s.length;f++){let h=s[f];if(h!=null&&(h<-2147483648||h>2147483647)){c=!1;break}}return c?L.Int32:L.Float64}return o&&l?L.Datetime:L.Utf8}var Tt=class{groups;keys;allKeys;parentColumns;parentHeight;parentSchema;constructor(t,e,n,r,o,i){this.groups=t,this.keys=e,this.allKeys=n,this.parentColumns=r,this.parentHeight=o,this.parentSchema=i}to_dataframe(){let t=this.keys.length,e=new Array(t);for(let l=0;l<t;l++)e[l]=String(this.keys[l]);let n=this.groups.size,r={};for(let l=0;l<e.length;l++)r[e[l]]=new Array(n);let o=0;for(let l of this.groups.values()){if(l.length===0)continue;let a=l[0];for(let u=0;u<e.length;u++){let c=e[u],f=this.parentColumns[c][a];r[c][o]=f===void 0?null:f}o++}let i={};for(let l of e)i[l]=this.parentSchema[l];return new F(r,i,o)}agg(...t){let e=this.allKeys.length,n=new Array(e);for(let f=0;f<e;f++)n[f]=String(this.allKeys[f]);let r=this.keys.length,o=new Array(r);for(let f=0;f<r;f++)o[f]=String(this.keys[f]);let i=ft(t.flat(),n,o),l=this.groups.size,a={};for(let f=0;f<o.length;f++)a[o[f]]=new Array(l);let u=0;for(let f of this.groups.values()){if(f.length===0)continue;let h=f[0];for(let p=0;p<o.length;p++){let m=o[p],y=this.parentColumns[m][h];a[m][u]=y===void 0?null:y}u++}for(let f=0;f<i.length;f++){let h=i[f],p=h.outputName||h.colName||"*";if(!h.aggFn){a[p]=h.evaluate(a,l);continue}let m=h.evaluatePreGrouping(this.parentColumns,this.parentHeight),y=new Array(l),d=0;for(let b of this.groups.values()){if(b.length===0)continue;let w=new Array(b.length);for(let A=0;A<b.length;A++)w[A]=m[b[A]];y[d]=h.aggFn(w),d++}a[p]=h.evaluatePostGrouping(y,a)}let c={};for(let f of o)c[f]=this.parentSchema[f];for(let f of i){let h=f.outputName||f.colName||"*";c[h]=rt(a[h])}return new F(a,c,u)}};function dn(s,t,e){if(s==null)throw new V(`Invalid input to ${t} at index ${e}: item cannot be null or undefined.`);if(s instanceof F)return[s];if(xt(s))return[new F(s)];if(C(s)){if(lt(s,F,{mode:"every"}))return s;if(lt(s,"plainObject",{mode:"every"}))return[new F(s)];let n=lt(s,F,{mode:"some"});for(let r=0;r<s.length;r++)if(n?!(s[r]instanceof F):!xt(s[r]))throw new V(n?`Invalid input to ${t} at index ${e}, sub-index ${r}: nested array must contain only DataFrame instances.`:`Invalid input to ${t} at index ${e}, row ${r}: rows must be plain objects.`)}throw new V(`Invalid input to ${t} at index ${e}: expected DataFrame, row array, or column dictionary.`)}function Dt(s,t={}){if(s==null)throw new V("Invalid input to concat: rawItems cannot be null or undefined.");let e=Array.isArray(s)?s:[s],n=[];for(let i=0;i<e.length;i++)n.push(...dn(e[i],"concat",i));let{how:r="vertical"}=t,o=t.horizontal?.strict??!0;if(n.length===0)return new F({},{},0);if(n.length===1&&r!=="horizontal")return n[0];switch(r){case"vertical":{let i=[];for(let p=0;p<n.length;p++)n[p].height>0&&i.push(n[p]);if(i.length===0)return new F({},{},0);let l=i[0],a=Object.keys(l._columns);for(let p=0;p<n.length;p++){let m=n[p];if(m.height===0)continue;let y=Object.keys(m._columns);if(a.length!==y.length)throw new V(`[Strict Vertical] Column count mismatch at index ${p}.`);for(let d=0;d<a.length;d++){if(a[d]!==y[d])throw new V(`[Strict Vertical] Schema mismatch at position ${d} in DF ${p}. Expected column "${a[d]}", but found "${y[d]}".`);let b=l.schema[a[d]],w=m.schema[a[d]];if(b&&w&&!b.equals(w))throw new ct(`[Strict Type Check] Schema type mismatch for column "${a[d]}": expected ${b.name}, found ${w.name}.`)}}let u=0;for(let p of n)u+=p.height;let c=n.find(p=>p.height>0)?.schema||n[0]?.schema||{},f={};for(let p of a){let m=c[p],y=!1;for(let b of n){let w=b._columns[p];if(!w){y=!0;break}if(!P(w)){for(let A=0;A<w.length;A++)if(w[A]==null){y=!0;break}}if(y)break}let d=m&&m.allocate?m.allocate(u):new Array(u).fill(null);y&&P(d)&&(d=new Array(u).fill(null)),f[p]=d}let h=0;for(let p of n){let m=p.height;if(m!==0){for(let y of a){let d=p._columns[y]||new Array(m).fill(null),b=f[y];if(P(b)&&P(d))b.set(d,h);else{let w=b;for(let A=0;A<m;A++)w[h+A]=d[A]}}h+=m}}return new F(f,c,u)}case"horizontal":{let i=n[0].height;for(let c=1;c<n.length;c++)n[c].height>i&&(i=n[c].height);let l=new Set;for(let c=0;c<n.length;c++){let f=n[c];if(o&&f.height!==i)throw new V(`[Horizontal] Row count mismatch at index ${c}. Expected ${i}, got ${f.height}. Set strict=false to allow padding.`);for(let h of Object.keys(f._columns)){if(l.has(h))throw new V(`[Horizontal] Duplicate column name "${h}" detected. Horizontal concat requires unique names.`);l.add(h)}}let a={},u={};for(let c of n){let f=c.height;Object.assign(u,c.schema);for(let[h,p]of Object.entries(c._columns))if(f===i)a[h]=P(p)?Array.from(p):p;else{let m=new Array(i);for(let y=0;y<f;y++)m[y]=p[y];for(let y=f;y<i;y++)m[y]=null;a[h]=m}}return new F(a,u,i)}case"diagonal":{let i=new Set;for(let h of n)for(let p of Object.keys(h._columns))i.add(p);let l=Array.from(i),a=0;for(let h=0;h<n.length;h++)a+=n[h].height;let u={};for(let h of l){let p=null;for(let m of n){let y=m.schema[h];if(y){if(p===null)p=y;else if(!p.equals(y))throw new ct(`[Strict Type Check] Schema type mismatch for column "${h}": expected ${p.name}, found ${y.name}.`)}}u[h]=p||L.Utf8}let c={};for(let h=0;h<l.length;h++)c[l[h]]=new Array(a).fill(null);let f=0;for(let h=0;h<n.length;h++){let p=n[h],m=p.height;if(m!==0){for(let y=0;y<l.length;y++){let d=l[y],b=c[d],w=p._columns[d];if(w!==void 0)if(P(w)&&P(b))b.set(w,f);else{let A=b;for(let S=0;S<m;S++)A[f+S]=w[S]}else{let A=b;for(let S=0;S<m;S++)A[f+S]=null}}f+=m}}return new F(c,u,a)}}}var F=class s{_columns;_height;_schema={};constructor(t,e,n){if(Array.isArray(t)){let{columns:r,height:o}=De(t);this._columns=r,this._height=o,e?this.applySchema(e):this.inferSchema();return}if(Z(t)){let r=-1;for(let[o,i]of Object.entries(t)){let l=C(i)?i.length:0;if(r===-1)r=l;else if(l!==r)throw new V(`Column height mismatch: Column "${o}" has length ${l}, but previous columns have length ${r}`)}this._columns=t,this._height=n!==void 0?n:r===-1?0:r,e?this.applySchema(e):this.inferSchema();return}this._columns={},this._height=0,e?this.applySchema(e):this._schema={}}inferSchema(){let t={},e=Object.keys(this._columns);for(let n of e)t[n]=rt(this._columns[n]);this._schema=t}applySchema(t){this._schema=t;let e=Object.keys(t),n={};for(let r of e){let o=t[r],i=this._columns[r],l=o.allocate?o.allocate(this._height):new Array(this._height).fill(null);if(!i){this._height>0&&P(l)&&(l=new Array(this._height).fill(null)),n[r]=l;continue}let a=!1,u=new Array(this._height);for(let c=0;c<this._height;c++){let f=o.coerce(i[c]);u[c]=f,f==null&&(a=!0)}a&&P(l)&&(l=new Array(this._height));for(let c=0;c<this._height;c++)l[c]=u[c];n[r]=l}this._columns=n}getSchema(){return this._schema}to_dicts(){return Ae(this._columns,this._height)}to_dict(){return{...this._columns}}get columns(){return Object.keys(this._columns)}concat(t,e={}){let n=lt(t,s,{mode:"every",allowEmpty:!1})?t:[t];return Dt([this,...n],e)}drop(...t){let e=new Set(t.flat()),n={},r={};for(let o of Object.keys(this._columns))e.has(o)||(n[o]=this._columns[o],r[o]=this._schema[o]);return new s(n,r,this._height)}get dtypes(){let t=Object.keys(this._columns),e=t.length,n=new Array(e);for(let r=0;r<e;r++)n[r]=this._schema[t[r]];return n}filter(...t){if(this._height===0)return new s({},this._schema,0);let e=this._height,n=Object.keys(this._columns),r=n.length,o=[],i=[];for(let h of t)typeof h=="function"?i.push(h):o.push(h.evaluate(this._columns,e));let l=[],a=0,u=null;if(i.length>0){let h=this._columns;u={};for(let p=0;p<r;p++){let m=n[p],y=h[m];Object.defineProperty(u,m,{get(){let d=y[a];return d===void 0?null:d},enumerable:!0,configurable:!0})}}for(let h=0;h<e;h++){let p=!0;for(let m=0;m<o.length;m++)if(!o[m][h]){p=!1;break}if(p){if(u){a=h;for(let m=0;m<i.length;m++)if(!i[m](u)){p=!1;break}}p&&l.push(h)}}let c=l.length,f={};for(let h=0;h<r;h++){let p=n[h],m=this._columns[p],y=new Array(c);for(let d=0;d<c;d++)y[d]=m[l[d]];f[p]=y}return new s(f,this._schema,c)}groupby(t){let e=st(t),n=new Map,r=this._height,o=e.length,i=new Array(o);for(let c=0;c<o;c++)i[c]=String(e[c]);for(let c=0;c<i.length;c++)if(!(i[c]in this._columns))throw new B(i[c],`Grouping key "${i[c]}" does not exist`);let l=o===1?i[0]:null,a=l?this._columns[l]:null;for(let c=0;c<r;c++){let f;if(l){let p=a[c];f=p==null?"":String(p)}else{let p=new Array(o);for(let m=0;m<o;m++){let y=this._columns[i[m]][c];p[m]=y==null?"":String(y)}f=p.join("\0")}let h=n.get(f);h===void 0&&n.set(f,h=[]),h.push(c)}let u=Object.keys(this._columns);return new Tt(n,e,u,this._columns,this._height,this._schema)}head(t=10){return this.limit(t,{offset:0,from:"start"})}get height(){return this._height}hstack(t,e={}){return this.concat(t,{how:"horizontal",horizontal:e})}join(t){let{other:e,on:n,how:r="inner",suffixes:o=["","_right"]}=t,i=st(n);for(let T of i){let D=String(T);if(!(D in this._columns))throw new B(D,`Join key "${D}" does not exist in the left DataFrame.`);if(!(D in e._columns))throw new B(D,`Join key "${D}" does not exist in the right DataFrame.`)}let[l,a]=o,u=Object.keys(this._columns),c=Object.keys(e._columns),f=new Set(i),h=u.length,p=c.length,m=(T,D)=>{let O=i.length;if(O===1){let M=T[i[0]][D];return M==null?null:String(M)}let R=new Array(O);for(let M=0;M<O;M++){let q=T[i[M]][D];if(q==null)return null;R[M]=String(q)}return R.join("\0")},y=new Map,d=e._height,b=e._columns;for(let T=0;T<d;T++){let D=m(b,T);if(D===null)continue;let O=y.get(D);O===void 0&&(O=[],y.set(D,O)),O.push(T)}let w=this._height,A=this._columns,S=[],x=[],I=r==="outer"||r==="right",U=I?new Set:null;for(let T=0;T<w;T++){let D=m(A,T),O=D===null?void 0:y.get(D);if(O===void 0)(r==="left"||r==="outer")&&(S.push(T),x.push(null));else for(let R=0;R<O.length;R++){let M=O[R];I&&U.add(M),S.push(T),x.push(M)}}if(I)for(let T=0;T<d;T++)U.has(T)||(S.push(-1),x.push(T));let E=S.length,N={},$={};for(let T=0;T<h;T++){let D=u[T],O=D in e._columns&&!f.has(D)?`${D}${l}`:D,R=this._columns[D],M=f.has(D),q=new Array(E);if(M){let G=e._columns[D];for(let tt=0;tt<E;tt++){let Ie=S[tt];if(Ie!==-1)q[tt]=R[Ie];else{let Ce=x[tt];q[tt]=Ce!==null?G[Ce]:null}}}else for(let G=0;G<E;G++){let tt=S[G];q[G]=tt!==-1?R[tt]:null}N[O]=q,this._schema[D]&&($[O]=this._schema[D])}for(let T=0;T<p;T++){let D=c[T];if(!f.has(D)){let O=D in this._columns?`${D}${a}`:D,R=e._columns[D],M=new Array(E);for(let q=0;q<E;q++){let G=x[q];M[q]=G!==null?R[G]:null}N[O]=M,e._schema[D]&&($[O]=e._schema[D])}}return new s(N,$,E)}limit(t,e={}){let{offset:n=0,from:r="start"}=e,o=this._height,i=isNaN(t)?0:Math.max(Math.floor(t),0),l=isNaN(n)?0:Math.max(Math.floor(n),0);if(i===0||o===0||l>=o){let h={},p={};for(let m of Object.keys(this._columns))h[m]=[],p[m]=this._schema[m];return new s(h,p,0)}let a=0,u=0;r==="end"?(u=Math.max(o-l,0),a=Math.max(u-i,0)):(u=Math.min(l+i,o),a=l);let c=Math.max(u-a,0),f={};for(let h of Object.keys(this._columns))f[h]=this._columns[h].slice(a,u);return new s(f,this._schema,c)}pivot(t){if(this._height===0)return new s({},{},0);let{index:e,columns:n,values:r}=t,o=st(e),i=o.length,l=new Array(i);for(let x=0;x<i;x++)l[x]=String(o[x]);let a=String(n),u=String(r);for(let x of l)if(!(x in this._columns))throw new B(x,`Pivot index key "${x}" does not exist in the DataFrame.`);if(!(a in this._columns))throw new B(a,`Pivot column key "${a}" does not exist`);if(!(u in this._columns))throw new B(u,`Pivot values key "${u}" does not exist in the DataFrame.`);let c=new Map,f=new Set,h=this._height,p=this._columns[a],m=this._columns[u];for(let x=0;x<h;x++){let I=new Array(i);for(let $=0;$<i;$++){let T=this._columns[l[$]][x];I[$]=T==null?"":String(T)}let U=I.join("\0"),E=String(p[x]);f.add(E);let N=c.get(U);N===void 0&&(N={firstIdx:x,indices:[]},c.set(U,N)),N.indices.push(x)}let y=c.size,d={},b={};for(let x=0;x<i;x++){let I=l[x];d[I]=new Array(y),this._schema[I]&&(b[I]=this._schema[I])}let w=Array.from(f),A=this._schema[u]||L.Utf8;for(let x=0;x<w.length;x++){let I=w[x];d[I]=new Array(y).fill(null),b[I]=A}let S=0;for(let x of c.values()){let I=x.firstIdx;for(let E=0;E<i;E++){let N=l[E];d[N][S]=this._columns[N][I]}let U=x.indices;for(let E=0;E<U.length;E++){let N=U[E],$=String(p[N]);d[$][S]=m[N]}S++}return new s(d,b,y)}rename(t){let e=t||{},n={},r={},o=Object.keys(this._columns);for(let l of o){let a=e[l]||l;n[a]=this._columns[l],r[a]=this._schema[l]}if(Object.keys(n).length<o.length)throw new V("Rename collision: Multiple columns mapped to the same output name.");return new s(n,r,this._height)}reverse(){if(this._height===0)return this;let t={},e=Object.keys(this._columns),n=e.length;for(let r=0;r<n;r++){let o=e[r];t[o]=this._columns[o].slice().reverse()}return new s(t,this._schema,this._height)}get schema(){return this._schema}select(...t){let e=this._normalizeArgs(t),n=Object.keys(this._columns),r=ft(e,n),o={},i={};for(let l of r){let a=l.outputName||l.colName||"*";if(a in o)throw new V(`Duplicate column selection: "${a}" is selected multiple times.`);o[a]=l.isWindow?jt(l,this._columns,this._height):l.evaluate(this._columns,this._height);let u=l.colName||a,c=l instanceof k&&l.ops.length===0&&!l.isWindow&&!l.aggFn;i[a]=c&&this._schema[u]?this._schema[u]:rt(o[a])}return new s(o,i,this._height)}get shape(){return[this.height,this.width]}slice(t,e){let n=this._height,r=t<0?Math.max(n+t,0):Math.min(t,n),o=e===void 0?n:e<0?Math.max(n+e,0):Math.min(e,n),i=Math.max(o-r,0);return this.limit(i,{offset:r})}sort(t){if(!t||!t.by||this._height===0)return this;let{by:e,descending:n=!1,nullsLast:r=!0,custom:o}=t,i=st(e);for(let m=0;m<i.length;m++){let y=i[m];if(typeof y=="string"&&!(y in this._columns))throw new B(y,`Sort key "${y}" does not exist`)}let l=Array.isArray(n)?n:new Array(i.length).fill(n),a=i.length,u=new Array(a);for(let m=0;m<a;m++){let y=i[m],d=l[m]?-1:1,b=o&&typeof y=="string"?o[y]:null,w=y?.evaluate?y.evaluate(this._columns,this._height):this._columns[y]||new Array(this._height).fill(null);u[m]={values:w,isDesc:d,customComp:b}}let c=u.length,f=r?1:-1,h=new Array(this._height);for(let m=0;m<this._height;m++)h[m]=m;h.sort((m,y)=>{for(let d=0;d<c;d++){let{values:b,isDesc:w,customComp:A}=u[d],S=b[m],x=b[y];if(A){let U=A(S,x);if(U!==0)return U*w;continue}if(S==null||x==null){if(S===x)continue;return(S==null?1:-1)*f}if(S===x)continue;return(S<x?-1:1)*w}return 0});let p={};for(let m of Object.keys(this._columns)){let y=this._columns[m],d=new Array(this._height);for(let b=0;b<this._height;b++)d[b]=y[h[b]];p[m]=d}return new s(p,this._schema,this._height)}tail(t=10){return this.limit(t,{offset:0,from:"end"})}to_list(t){if(this._height===0)return[];let e=t&&typeof t!="string"&&"evaluate"in t,n;if(e)n=t.evaluate(this._columns,this._height);else{let r=t;if(r==null)return new Array(this._height).fill(null);let o=this._columns[r];if(!o)throw new B(r,`Column "${r}" does not exist`);n=o}return Array.isArray(n)?n:Array.from(n)}unique(t){if(this._height===0)return new s({},this._schema,0);let e=st(t),n=e.length===0?Object.keys(this._columns):e.map(String);for(let f of n)if(!(f in this._columns))throw new B(f,`Unique column key "${f}" does not exist`);let r=new Set,o=[],i=n.length,l=this._height,a=i===1?this._columns[n[0]]:null;for(let f=0;f<l;f++){let h;if(a){let p=a[f];h=p==null?"":String(p)}else{let p=new Array(i);for(let m=0;m<i;m++){let y=this._columns[n[m]][f];p[m]=y==null?"":String(y)}h=p.join("\0")}r.has(h)||(r.add(h),o.push(f))}let u=o.length,c={};for(let f of Object.keys(this._columns)){let h=this._columns[f],p=new Array(u);for(let m=0;m<u;m++)p[m]=h[o[m]];c[f]=p}return new s(c,this._schema,u)}unpivot(t){let{idVars:e,valueVars:n,varName:r="variable",valueName:o="value"}=t,i=st(e).map(String),l=st(n).map(String),a=i.length,u=l.length;for(let m of i)if(!(m in this._columns))throw new B(m,`Unpivot id variable key "${m}" does not exist`);for(let m of l)if(!(m in this._columns))throw new B(m,`Unpivot value variable key "${m}" does not exist`);let c=this._height*u,f={};for(let m=0;m<a;m++)f[i[m]]=new Array(c);f[r]=new Array(c),f[o]=new Array(c);let h=0;for(let m=0;m<this._height;m++)for(let y=0;y<u;y++){let d=l[y];for(let b=0;b<a;b++){let w=i[b];f[w][h]=this._columns[w][m]}f[r][h]=d,f[o][h]=this._columns[d][m],h++}let p={};for(let m of i)p[m]=this._schema[m];return p[r]=L.Utf8,p[o]=rt(f[o]),new s(f,p,c)}vstack(t){return this.concat(t,{how:"vertical"})}get width(){return Object.keys(this._columns).length}_normalizeArgs(t){let e=t.flat(),n=[];for(let r of e)if(typeof r=="string")n.push(new k(r));else if(Z(r)&&"evaluate"in r)n.push(r);else if(Z(r))for(let[o,i]of Object.entries(r))if(Z(i)&&"evaluate"in i)n.push(i.alias(o));else{let l=new k(o);l.evaluate=(a,u)=>new Array(u).fill(i),n.push(l)}return n}with_columns(...t){let e=this._normalizeArgs(t),n=Object.keys(this._columns),r=ft(e,n),o=r.length,i={...this._columns},l={...this._schema};for(let a=0;a<o;a++){let u=r[a],c=u.outputName||u.colName||"*";u.isWindow?i[c]=jt(u,this._columns,this._height):i[c]=u.evaluate(this._columns,this._height);let f=u.colName||c;u instanceof k&&u.ops.length===0&&!u.isWindow&&!u.aggFn&&this._schema[f]?l[c]=this._schema[f]:l[c]=rt(i[c])}return new s(i,l,this._height)}};var On={data:(s,t)=>new F(s,t),col:s=>new k(s),all:Jt,exclude:Qt,coalesce:te,concat:Dt,lit:it,when:ee,DataType:L};0&&(module.exports={$tbl,ALL_COLUMNS_MARKER,AggregationExpr,ArithmeticExpr,ColumnExpr,ColumnNotFoundError,ComparisonExpr,ComputeError,DataFrame,DataFrameError,DataType,DataTypeRegistry,DateTimeExprNamespace,ExprBase,FrameScriptError,GroupedData,LITERAL_MARKER,ListExpr,ListExprNamespace,LogicalExpr,SchemaError,StringExpr,StringExprNamespace,TemporalExpr,When,WhenThen,WhenThenChain,WindowExpr,all,coalesce,columnsToRows,concat,derive,exclude,getRowFromColumns,inferColumnType,kleeneBinary,kleeneUnary,lit,normalizeToDataFrames,resolveColumnSelectors,resolveWindowExpr,rowsToColumns,when});
@@ -1,219 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ColumnExpr = void 0;
4
- exports.resolveColumnSelectors = resolveColumnSelectors;
5
- const ExprBase_1 = require("./ExprBase");
6
- const ArithmeticExpr_1 = require("./mixins/ArithmeticExpr");
7
- const ComparisonExpr_1 = require("./mixins/ComparisonExpr");
8
- const AggregationExpr_1 = require("./mixins/AggregationExpr");
9
- const WindowExpr_1 = require("./mixins/WindowExpr");
10
- const StringExpr_1 = require("./mixins/StringExpr");
11
- const LogicalExpr_1 = require("./mixins/LogicalExpr");
12
- const TemporalExpr_1 = require("./mixins/TemporalExpr");
13
- const ListExpr_1 = require("./mixins/ListExpr");
14
- const StructExpr_1 = require("./mixins/StructExpr");
15
- const ManipulationExpr_1 = require("./mixins/ManipulationExpr");
16
- const utils_1 = require("../utils");
17
- const datatypes_1 = require("../datatypes");
18
- const constants_1 = require("./constants");
19
- class ColumnExpr extends ExprBase_1.ExprBase {
20
- colName;
21
- colNames;
22
- excludedCols = [];
23
- targetType;
24
- targetTypes;
25
- static isColExpr(v) {
26
- if (!(0, utils_1.isObj)(v))
27
- return false;
28
- try {
29
- return "evaluate" in v && typeof v.evaluate === "function";
30
- }
31
- catch {
32
- return false;
33
- }
34
- }
35
- static toColExpr(col) {
36
- if (col == null) {
37
- throw new Error("Column reference cannot be null or undefined.");
38
- }
39
- return ColumnExpr.isColExpr(col) ? col : new ColumnExpr(col);
40
- }
41
- constructor(colName) {
42
- super();
43
- if (Array.isArray(colName)) {
44
- const hasTypes = colName.some(x => x instanceof datatypes_1.DataType || typeof x === "function");
45
- if (hasTypes) {
46
- this.targetTypes = colName;
47
- this.colName = "";
48
- this.outputName = "";
49
- }
50
- else {
51
- this.colNames = colName.map(String);
52
- this.colName = "";
53
- this.outputName = "";
54
- }
55
- }
56
- else if (colName instanceof datatypes_1.DataType || typeof colName === "function") {
57
- this.targetType = colName;
58
- this.colName = "";
59
- this.outputName = "";
60
- }
61
- else {
62
- this.colName = String(colName);
63
- this.outputName = this.colName;
64
- }
65
- }
66
- }
67
- exports.ColumnExpr = ColumnExpr;
68
- function applyMixins(derivedCtor, constructors) {
69
- for (const baseCtor of constructors) {
70
- for (const name of Object.getOwnPropertyNames(baseCtor.prototype)) {
71
- if (name !== 'constructor') {
72
- Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
73
- }
74
- }
75
- }
76
- }
77
- applyMixins(ColumnExpr, [
78
- ArithmeticExpr_1.ArithmeticExpr,
79
- ComparisonExpr_1.ComparisonExpr,
80
- AggregationExpr_1.AggregationExpr,
81
- WindowExpr_1.WindowExpr,
82
- StringExpr_1.StringExpr,
83
- LogicalExpr_1.LogicalExpr,
84
- TemporalExpr_1.TemporalExpr,
85
- ListExpr_1.ListExpr,
86
- StructExpr_1.StructExpr,
87
- ManipulationExpr_1.ManipulationExpr
88
- ]);
89
- /**
90
- * Determines which concrete keys a column selector matches.
91
- * Returns null if the expression is not a multi-column selector.
92
- */
93
- function getTargetKeys(expr, allKeys, excludeSet, schema) {
94
- if (!(expr instanceof ColumnExpr)) {
95
- if (expr && typeof expr === "object" && "evaluate" in expr && !expr.colName) {
96
- const targets = [];
97
- for (let i = 0; i < allKeys.length; i++) {
98
- if (!excludeSet.has(allKeys[i])) {
99
- targets.push(allKeys[i]);
100
- }
101
- }
102
- return targets;
103
- }
104
- return null;
105
- }
106
- if (expr.colNames && expr.colNames.length > 0) {
107
- return expr.colNames;
108
- }
109
- if (expr.colName === constants_1.ALL_COLUMNS_MARKER) {
110
- const excluded = new Set(expr.excludedCols);
111
- const targets = [];
112
- for (let i = 0; i < allKeys.length; i++) {
113
- const key = allKeys[i];
114
- if (!excluded.has(key) && !excludeSet.has(key)) {
115
- targets.push(key);
116
- }
117
- }
118
- return targets;
119
- }
120
- if (expr.targetType || (expr.targetTypes && expr.targetTypes.length > 0)) {
121
- if (!schema) {
122
- throw new Error("Cannot resolve DataType column selector without DataFrame schema.");
123
- }
124
- const targets = [];
125
- for (let i = 0; i < allKeys.length; i++) {
126
- const key = allKeys[i];
127
- if (excludeSet.has(key)) {
128
- continue;
129
- }
130
- const colType = schema[key];
131
- if (!colType) {
132
- continue;
133
- }
134
- if (expr.targetType) {
135
- if (colType.matches(expr.targetType)) {
136
- targets.push(key);
137
- }
138
- }
139
- else if (expr.targetTypes) {
140
- for (let k = 0; k < expr.targetTypes.length; k++) {
141
- if (colType.matches(expr.targetTypes[k])) {
142
- targets.push(key);
143
- break;
144
- }
145
- }
146
- }
147
- }
148
- return targets;
149
- }
150
- return null;
151
- }
152
- /**
153
- * Resolves column selectors, expanding wildcards, datatypes, and arrays of columns/types
154
- * into concrete ColumnExpr instances.
155
- */
156
- function resolveColumnSelectors(exprs, allKeys, keysToExcludeFromAll, schema, columns) {
157
- const expanded = [];
158
- const excludeSet = keysToExcludeFromAll ? new Set(keysToExcludeFromAll) : new Set();
159
- for (let i = 0; i < exprs.length; i++) {
160
- const expr = exprs[i];
161
- if (typeof expr === "string") {
162
- expanded.push(new ColumnExpr(expr));
163
- continue;
164
- }
165
- // Handle struct unnesting expansion
166
- if (expr && typeof expr === "object" && expr.isUnnest) {
167
- let fields = [];
168
- const colName = expr.colName;
169
- if (schema && colName && schema[colName] && schema[colName].name === "Struct") {
170
- fields = Object.keys(schema[colName].fields);
171
- }
172
- if (fields.length === 0 && columns) {
173
- const columnsKeys = Object.keys(columns);
174
- const firstKey = columnsKeys[0];
175
- const height = firstKey ? columns[firstKey].length : 0;
176
- const evaluated = expr.baseExpr.evaluate(columns, height);
177
- const evalLen = evaluated.length;
178
- for (let idx = 0; idx < evalLen; idx++) {
179
- const item = evaluated[idx];
180
- if (item != null && typeof item === "object") {
181
- fields = Object.keys(item);
182
- break;
183
- }
184
- }
185
- }
186
- const fieldsLen = fields.length;
187
- if (fieldsLen > 0) {
188
- for (let fIdx = 0; fIdx < fieldsLen; fIdx++) {
189
- const fieldName = fields[fIdx];
190
- const fieldExpr = expr.baseExpr.struct.field(fieldName);
191
- expanded.push(fieldExpr);
192
- }
193
- continue;
194
- }
195
- }
196
- const targets = getTargetKeys(expr, allKeys, excludeSet, schema);
197
- if (targets !== null) {
198
- for (let j = 0; j < targets.length; j++) {
199
- const concrete = new ColumnExpr(targets[j]);
200
- concrete.ops = [...(expr.ops || [])];
201
- concrete.aggFn = expr.aggFn;
202
- concrete.partitionOpsIndex = expr.partitionOpsIndex;
203
- concrete.groupingOpsIndex = expr.groupingOpsIndex;
204
- concrete.partitionBy = expr.partitionBy;
205
- if (expr.evaluateWindow) {
206
- concrete.evaluateWindow = expr.evaluateWindow;
207
- }
208
- if (expr.outputName && expr.outputName !== constants_1.ALL_COLUMNS_MARKER) {
209
- concrete.outputName = expr.outputName;
210
- }
211
- expanded.push(concrete);
212
- }
213
- }
214
- else {
215
- expanded.push(expr);
216
- }
217
- }
218
- return expanded;
219
- }
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExprBase = exports.derive = void 0;
4
- const constants_1 = require("./constants");
5
- const exceptions_1 = require("../exceptions");
6
- const derive = (instance, nextOp) => {
7
- const Constructor = instance.constructor;
8
- const colNameVal = instance.colNames || instance.colName || "";
9
- const newInst = new Constructor(colNameVal);
10
- Object.assign(newInst, instance);
11
- newInst.ops = nextOp ? [...instance.ops, nextOp] : [...instance.ops];
12
- return newInst;
13
- };
14
- exports.derive = derive;
15
- class ExprBase {
16
- ops = [];
17
- outputName = "";
18
- isLiteral;
19
- literalValue;
20
- aggFn = null;
21
- groupingOpsIndex;
22
- partitionOpsIndex;
23
- partitionBy = null;
24
- evaluateWindow;
25
- _resolve(val, columns, height) {
26
- if (val instanceof ExprBase) {
27
- if (val.isLiteral && val.ops.length === 1) {
28
- return val.literalValue;
29
- }
30
- return val.evaluate(columns, height);
31
- }
32
- return val;
33
- }
34
- alias(name) {
35
- const newInst = (0, exports.derive)(this);
36
- newInst.outputName = name;
37
- return newInst;
38
- }
39
- cast(dataType) {
40
- return (0, exports.derive)(this, (vArray) => {
41
- const height = vArray.length;
42
- const result = new Array(height);
43
- for (let i = 0; i < height; i++) {
44
- result[i] = dataType.coerce(vArray[i]);
45
- }
46
- return result;
47
- });
48
- }
49
- debug(label) {
50
- return (0, exports.derive)(this, (vArray) => {
51
- console.log(`[DEBUG] ${label ? label + ': ' : ''}`, vArray);
52
- return vArray;
53
- });
54
- }
55
- _getInitialValue(columns, height) {
56
- const name = this.colName;
57
- if (name && name !== constants_1.ALL_COLUMNS_MARKER && !name.startsWith("*") && !(name in columns)) {
58
- throw new exceptions_1.ColumnNotFoundError(name);
59
- }
60
- return name && name !== constants_1.ALL_COLUMNS_MARKER
61
- ? (columns[name] || new Array(height).fill(null))
62
- : new Array(height).fill(null);
63
- }
64
- evaluate(columns, height) {
65
- let value = this._getInitialValue(columns, height);
66
- const ops = this.ops;
67
- const len = ops.length;
68
- for (let i = 0; i < len; i++) {
69
- value = ops[i](value, columns);
70
- }
71
- return value;
72
- }
73
- evaluatePre(opsIndex, columns, height) {
74
- let value = this._getInitialValue(columns, height);
75
- const ops = this.ops;
76
- const idx = opsIndex !== undefined ? opsIndex : ops.length;
77
- for (let i = 0; i < idx; i++) {
78
- value = ops[i](value, columns);
79
- }
80
- return value;
81
- }
82
- evaluatePost(opsIndex, aggregatedArray, columns) {
83
- const ops = this.ops;
84
- const idx = opsIndex !== undefined ? opsIndex : ops.length;
85
- let value = aggregatedArray;
86
- for (let i = idx; i < ops.length; i++) {
87
- value = ops[i](value, columns);
88
- }
89
- return value;
90
- }
91
- }
92
- exports.ExprBase = ExprBase;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ELEMENT_MARKER = exports.COALESCE_MARKER = exports.LITERAL_MARKER = exports.ALL_COLUMNS_MARKER = void 0;
4
- exports.ALL_COLUMNS_MARKER = "*";
5
- exports.LITERAL_MARKER = "*literal*";
6
- exports.COALESCE_MARKER = "*coalesce*";
7
- exports.ELEMENT_MARKER = "*element*";
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.all = all;
4
- const ColumnExpr_1 = require("../ColumnExpr");
5
- const constants_1 = require("../constants");
6
- /**
7
- * Creates an expression targeting all columns in the DataFrame.
8
- */
9
- function all() {
10
- return new ColumnExpr_1.ColumnExpr(constants_1.ALL_COLUMNS_MARKER);
11
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.coalesce = coalesce;
4
- const ColumnExpr_1 = require("../ColumnExpr");
5
- const utils_1 = require("../../utils");
6
- const constants_1 = require("../constants");
7
- function coalesce(...exprs) {
8
- const rawArgs = (exprs.length === 1 && Array.isArray(exprs[0]))
9
- ? exprs[0]
10
- : exprs;
11
- const expr = new ColumnExpr_1.ColumnExpr(constants_1.COALESCE_MARKER);
12
- expr.ops.push((_, columns) => {
13
- const height = _.length;
14
- const evaluateArg = (arg) => {
15
- if (ColumnExpr_1.ColumnExpr.isColExpr(arg)) {
16
- return arg.evaluate(columns, height);
17
- }
18
- if (typeof arg === "string") {
19
- return columns[arg] || new Array(height).fill(null);
20
- }
21
- return arg;
22
- };
23
- const exprCount = rawArgs.length;
24
- const evaluatedArrays = new Array(exprCount);
25
- for (let j = 0; j < exprCount; j++) {
26
- evaluatedArrays[j] = evaluateArg(rawArgs[j]);
27
- }
28
- const result = new Array(height);
29
- for (let i = 0; i < height; i++) {
30
- let foundVal = null;
31
- for (let j = 0; j < exprCount; j++) {
32
- const arr = evaluatedArrays[j];
33
- const val = (0, utils_1.isArrayOrTypedArray)(arr) ? arr[i] : arr;
34
- if (val != null) {
35
- foundVal = val;
36
- break;
37
- }
38
- }
39
- result[i] = foundVal;
40
- }
41
- return result;
42
- });
43
- return expr;
44
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.element = element;
4
- const ColumnExpr_1 = require("../ColumnExpr");
5
- const constants_1 = require("../constants");
6
- /**
7
- * Creates an expression referencing the current element(s) of a list during evaluation.
8
- */
9
- function element() {
10
- return new ColumnExpr_1.ColumnExpr(constants_1.ELEMENT_MARKER);
11
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exclude = exclude;
4
- const ColumnExpr_1 = require("../ColumnExpr");
5
- const constants_1 = require("../constants");
6
- /**
7
- * Creates an expression targeting all columns except the specified ones.
8
- */
9
- function exclude(columns) {
10
- const expr = new ColumnExpr_1.ColumnExpr(constants_1.ALL_COLUMNS_MARKER);
11
- expr.excludedCols = Array.isArray(columns) ? columns : [columns];
12
- return expr;
13
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.implode = implode;
4
- const ColumnExpr_1 = require("../ColumnExpr");
5
- function implode(column) {
6
- return ColumnExpr_1.ColumnExpr.toColExpr(column).implode();
7
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lit = lit;
4
- const seq_range_1 = require("./seq_range");
5
- /**
6
- * Creates a literal column expression that repeats the given value for all rows.
7
- */
8
- function lit(value, options) {
9
- const expr = (0, seq_range_1.seq_range)(value, {
10
- strict: true,
11
- mode: "constant",
12
- dtype: options?.dtype,
13
- name: options?.name,
14
- });
15
- expr.isLiteral = true;
16
- return expr;
17
- }
@@ -1,47 +0,0 @@
1
- import { ColumnExpr } from "../ColumnExpr";
2
- import type { RegisteredDataType } from "../../types";
3
- export type RepeatOptions = {
4
- n?: number;
5
- dtype?: RegisteredDataType;
6
- name?: string;
7
- } & ({
8
- mode?: "constant";
9
- } | {
10
- mode: "cumulative" | "independent";
11
- step?: number | ((prevOrIndex: any, index: number) => any);
12
- }) & ({
13
- strict?: true;
14
- } | {
15
- strict: false;
16
- pad?: boolean;
17
- truncate?: boolean;
18
- padValue?: any;
19
- startIndex?: number;
20
- endIndex?: number;
21
- });
22
- export type SeqRangeOptions = {
23
- n?: number;
24
- dtype?: RegisteredDataType;
25
- name?: string;
26
- step?: number | ((prevOrIndex: any, index: number) => any);
27
- mode?: "cumulative" | "independent";
28
- } & ({
29
- strict?: true;
30
- } | {
31
- strict: false;
32
- pad?: boolean;
33
- truncate?: boolean;
34
- padValue?: any;
35
- startIndex?: number;
36
- endIndex?: number;
37
- });
38
- /**
39
- * Creates a literal column expression that repeats the given value.
40
- * If n is specified, it repeats the value n times.
41
- * If strict is true (default), a height mismatch with the DataFrame will throw a ShapeError.
42
- */
43
- export declare function repeat(value: any, options?: RepeatOptions): ColumnExpr<any>;
44
- /**
45
- * Creates a column expression that generates a sequence of values starting from the given start value.
46
- */
47
- export declare function seq_range(start: any, options?: SeqRangeOptions): ColumnExpr<any>;