Search in sources :

Example 1 with ValStr

use of water.rapids.vals.ValStr in project h2o-3 by h2oai.

the class AstFlatten method apply.

@Override
public Val apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Frame fr = stk.track(asts[1].exec(env)).getFrame();
    // did not flatten
    if (fr.numCols() != 1 || fr.numRows() != 1)
        return new ValFrame(fr);
    Vec vec = fr.anyVec();
    switch(vec.get_type()) {
        case Vec.T_BAD:
        case Vec.T_NUM:
            return new ValNum(vec.at(0));
        case Vec.T_TIME:
            // check for missing values
            return vec.isNA(0) ? new ValNum(Double.NaN) : new ValNum(vec.at8(0));
        case Vec.T_STR:
            return new ValStr(vec.atStr(new BufferedString(), 0).toString());
        case // check for missing values
        Vec.T_CAT:
            return vec.isNA(0) ? new ValStr("NA") : new ValStr(vec.factor(vec.at8(0)));
        default:
            throw H2O.unimpl("The type of vector: " + vec.get_type_str() + " is not supported by " + str());
    }
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec) ValStr(water.rapids.vals.ValStr) BufferedString(water.parser.BufferedString) ValNum(water.rapids.vals.ValNum)

Aggregations

Frame (water.fvec.Frame)1 Vec (water.fvec.Vec)1 BufferedString (water.parser.BufferedString)1 ValFrame (water.rapids.vals.ValFrame)1 ValNum (water.rapids.vals.ValNum)1 ValStr (water.rapids.vals.ValStr)1