use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstCountMatches method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
final String[] pattern = asts[2] instanceof AstStrList ? ((AstStrList) asts[2])._strs : new String[] { asts[2].exec(env).getStr() };
// Type check
for (Vec v : fr.vecs()) if (!(v.isCategorical() || v.isString()))
throw new IllegalArgumentException("countmatches() 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] = countMatchesCategoricalCol(v, pattern);
else
nvs[i] = countMatchesStringCol(v, pattern);
i++;
}
return new ValFrame(new Frame(nvs));
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstEntropy method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
//Type check
for (Vec v : fr.vecs()) if (!(v.isCategorical() || v.isString()))
throw new IllegalArgumentException("entropy() 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] = entropyCategoricalCol(v);
else
nvs[i] = entropyStringCol(v);
i++;
}
return new ValFrame(new Frame(nvs));
}
use of water.rapids.vals.ValFrame 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.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstSubstring method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
int startIndex = (int) asts[2].exec(env).getNum();
if (startIndex < 0)
startIndex = 0;
int endIndex = asts[3] instanceof AstNumList ? Integer.MAX_VALUE : (int) asts[3].exec(env).getNum();
// Type check
for (Vec v : fr.vecs()) if (!(v.isCategorical() || v.isString()))
throw new IllegalArgumentException("substring() 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] = substringCategoricalCol(v, startIndex, endIndex);
else
nvs[i] = substringStringCol(v, startIndex, endIndex);
i++;
}
return new ValFrame(new Frame(nvs));
}
use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.
the class AstToUpper method apply.
@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Frame fr = stk.track(asts[1].exec(env)).getFrame();
// Type check
for (Vec v : fr.vecs()) if (!(v.isCategorical() || v.isString()))
throw new IllegalArgumentException("toupper() 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] = toUpperCategoricalCol(v);
else
nvs[i] = toUpperStringCol(v);
i++;
}
return new ValFrame(new Frame(nvs));
}
Aggregations