rapidsai / node

GPU-accelerated data science and visualization in node

Home Page:https://rapidsai.github.io/node/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refactor the cast() implementation so different subtypes can override

bryevdv opened this issue · comments

Suggestion from @trxcllnt

because there's sometimes custom conversion logic between different types (like string and int)

Proposed change

class CastVisitor extends Arrow.Visitor {
  constructor(private series) { super(); }
  visitInt8(dtype) { return this.series._castAsInt8(); }
  visitInt16(dtype) { return this.series._castAsInt16(); }
  visitInt32(dtype) { return this.series._castAsInt32(); }
  // etc
}

class Series {
  cast(dtype) {
    return new CastVisitor(this).visit(dtype);
  }
  protected _castAsInt8(): Series<Int8> { throw new Error("Unimplemented"); }
  protected _castAsInt16(): Series<Int16> { throw new Error("Unimplemented"); }
  protected _castAsInt32(): Series<Int32> { throw new Error("Unimplemented"); }
  // etc
}

class StringSeries {
  protected _castAsInt8() { return Series.new(this._col.stoi(new Int8)); }
  protected _castAsInt16() { return Series.new(this._col.stoi(new Int16)); }
  protected _castAsInt32() { return Series.new(this._col.stoi(new Int16)); }
  // etc
}