Search in sources :

Example 21 with ValFrame

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);
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) BufferedString(water.parser.BufferedString)

Example 22 with ValFrame

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);
}
Also used : ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) BufferedString(water.parser.BufferedString) Chunk(water.fvec.Chunk) NewChunk(water.fvec.NewChunk) NewChunk(water.fvec.NewChunk) ValFrame(water.rapids.vals.ValFrame) Vec(water.fvec.Vec) MRTask(water.MRTask) BufferedString(water.parser.BufferedString) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 23 with ValFrame

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 }));
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec)

Example 24 with ValFrame

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);
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec)

Example 25 with ValFrame

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));
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) BufferedString(water.parser.BufferedString)

Aggregations

ValFrame (water.rapids.vals.ValFrame)132 Frame (water.fvec.Frame)98 Val (water.rapids.Val)48 Vec (water.fvec.Vec)43 Test (org.junit.Test)38 MRTask (water.MRTask)32 Chunk (water.fvec.Chunk)24 NewChunk (water.fvec.NewChunk)23 BufferedString (water.parser.BufferedString)16 AstNumList (water.rapids.ast.params.AstNumList)11 AstNum (water.rapids.ast.params.AstNum)7 ValNum (water.rapids.vals.ValNum)7 AstRoot (water.rapids.ast.AstRoot)6 ValRow (water.rapids.vals.ValRow)6 ArrayList (java.util.ArrayList)5 Key (water.Key)5 AstStrList (water.rapids.ast.params.AstStrList)5 Futures (water.Futures)4 AstParameter (water.rapids.ast.AstParameter)4 Random (java.util.Random)3