use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstTokenize method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
String regex = asts[2].exec(env).getStr();
// Type check
for (Vec v : fr.vecs()) if (!v.isString())
throw new IllegalArgumentException("tokenize() requires all input columns to be of a String type. " + "Received " + fr.anyVec().get_type_str() + ". Please convert column to a string column first.");
Frame tokenized = new Tokenizer(regex).doAll(Vec.T_STR, fr).outputFrame();
return new ValFrame(tokenized);
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstAsDate method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
Vec vec = fr.vecs()[0];
if (fr.vecs().length != 1 || !(vec.isCategorical() || vec.isString()))
throw new IllegalArgumentException("as.Date requires a single column of factors or strings");
final String format = asts[2].exec(env).getStr();
if (format.isEmpty())
throw new IllegalArgumentException("as.Date requires a non-empty format string");
// check the format string more?
final String[] dom = vec.domain();
final boolean isStr = dom == null && vec.isString();
assert isStr || dom != null : "as.Date error: domain is null, but vec is not String";
Frame fr2 = new MRTask() {
private transient DateTimeFormatter _fmt;
@Override
public void setupLocal() {
_fmt = ParseTime.forStrptimePattern(format).withZone(ParseTime.getTimezone());
}
@Override
public void map(Chunk c, NewChunk nc) {
//done on each node in lieu of rewriting DateTimeFormatter as Iced
String date;
BufferedString tmpStr = new BufferedString();
for (int i = 0; i < c._len; ++i) {
if (!c.isNA(i)) {
if (isStr)
date = c.atStr(tmpStr, i).toString();
else
date = dom[(int) c.at8(i)];
nc.addNum(DateTime.parse(date, _fmt).getMillis(), 0);
} else
nc.addNA();
}
}
}.doAll(1, Vec.T_NUM, fr).outputFrame(fr._names, null);
return new ValFrame(fr2);
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstListTimeZones method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
String[] domain = ParseTime.listTimezones().split("\n");
double[] ds = new double[domain.length];
for (int i = 0; i < domain.length; i++) ds[i] = i;
Vec vec = Vec.makeVec(ds, Vec.VectorGroup.VG_LEN1.addVec());
vec.setDomain(domain);
return new ValFrame(new Frame(new String[] { "Timezones" }, new Vec[] { vec }));
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstMoment method make1x1Frame.
private ValFrame make1x1Frame(double val) {
Vec v = Vec.makeTimeVec(new double[] { val }, null);
Frame f = new Frame(new String[] { "time" }, new Vec[] { v });
return new ValFrame(f);
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstLStrip method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
String set = asts[2].exec(env).getStr();
// Type check
for (Vec v : fr.vecs()) if (!(v.isCategorical() || v.isString()))
throw new IllegalArgumentException("trim() requires a string or categorical column. " + "Received " + fr.anyVec().get_type_str() + ". Please convert column to a string or categorical first.");
// Transform each vec
Vec[] nvs = new Vec[fr.numCols()];
int i = 0;
for (Vec v : fr.vecs()) {
if (v.isCategorical())
nvs[i] = lstripCategoricalCol(v, set);
else
nvs[i] = lstripStringCol(v, set);
i++;
}
return new ValFrame(new Frame(nvs));
}
Aggregations