use of water.fvec.Vec in project h2o-3 by h2oai.
the class AstGrep method exec.
@Override
protected Val exec(Val[] args) {
Frame fr = args[1].getFrame();
String regex = args[2].getStr();
boolean ignoreCase = args[3].getNum() == 1;
boolean invert = args[4].getNum() == 1;
boolean outputLogical = args[5].getNum() == 1;
GrepHelper grepHelper = new GrepHelper(regex, ignoreCase, invert, outputLogical);
if ((fr.numCols() != 1) || !(fr.anyVec().isCategorical() || fr.anyVec().isString()))
throw new IllegalArgumentException("can only grep on a single categorical/string column.");
Vec v = fr.anyVec();
assert v != null;
Frame result;
if (v.isCategorical()) {
int[] filtered = grepDomain(grepHelper, v);
Arrays.sort(filtered);
result = new GrepCatTask(grepHelper, filtered).doAll(Vec.T_NUM, v).outputFrame();
} else {
result = new GrepStrTask(grepHelper).doAll(Vec.T_NUM, v).outputFrame();
}
return new ValFrame(result);
}
use of water.fvec.Vec 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.fvec.Vec 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.fvec.Vec 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.fvec.Vec in project h2o-3 by h2oai.
the class AstProd method apply.
@Override
public ValNum apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
for (Vec v : fr.vecs()) if (v.isCategorical() || v.isUUID() || v.isString())
throw new IllegalArgumentException("`" + str() + "`" + " only defined on a data frame with all numeric variables");
double prod = new AstProd.RedProd().doAll(fr)._d;
return new ValNum(prod);
}
Aggregations