use of water.rapids.ast.params.AstNum in project h2o-3 by h2oai.
the class AstColNames method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
if (asts[2] instanceof AstNumList) {
if (!(asts[3] instanceof AstStrList))
throw new IllegalArgumentException("Column naming requires a string-list, but found a " + asts[3].getClass());
AstNumList cols = ((AstNumList) asts[2]);
AstStrList nams = ((AstStrList) asts[3]);
int[] d = cols.expand4();
if (d.length != nams._strs.length)
throw new IllegalArgumentException("Must have the same number of column choices as names");
for (int i = 0; i < d.length; i++) fr._names[d[i]] = nams._strs[i];
} else if ((asts[2] instanceof AstNum)) {
int col = (int) (asts[2].exec(env).getNum());
String name = asts[3].exec(env).getStr();
fr._names[col] = name;
} else
throw new IllegalArgumentException("Column naming requires a number-list, but found a " + asts[2].getClass());
// Update names in DKV
if (fr._key != null)
DKV.put(fr);
return new ValFrame(fr);
}
use of water.rapids.ast.params.AstNum in project h2o-3 by h2oai.
the class AstColPySlice method apply.
@Override
public Val apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Val v = stk.track(asts[1].exec(env));
AstParameter colList = (AstParameter) asts[2];
if (v instanceof ValRow) {
ValRow vv = (ValRow) v;
return vv.slice(colList.columns(vv.getNames()));
}
Frame fr = v.getFrame();
int[] cols = colList.columns(fr.names());
Frame fr2 = new Frame();
if (// Empty inclusion list?
cols.length == 0)
return new ValFrame(fr2);
if (// Negative cols have number of cols added
cols[0] < 0)
for (int i = 0; i < cols.length; i++) cols[i] += fr.numCols();
if (// Singletons must be in-range
asts[2] instanceof AstNum && (cols[0] < 0 || cols[0] >= fr.numCols()))
throw new IllegalArgumentException("Column must be an integer from 0 to " + (fr.numCols() - 1));
for (// For all included columns
int col : // For all included columns
cols) if (// Ignoring out-of-range ones
col >= 0 && col < fr.numCols())
fr2.add(fr.names()[col], fr.vecs()[col]);
return new ValFrame(fr2);
}
Aggregations