Search in sources :

Example 31 with Vec

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

Example 32 with Vec

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);
}
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 33 with Vec

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

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

Example 35 with Vec

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

Aggregations

Vec (water.fvec.Vec)280 Frame (water.fvec.Frame)213 Test (org.junit.Test)82 NFSFileVec (water.fvec.NFSFileVec)48 ValFrame (water.rapids.vals.ValFrame)47 Chunk (water.fvec.Chunk)30 Random (java.util.Random)25 NewChunk (water.fvec.NewChunk)23 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)22 Key (water.Key)21 MRTask (water.MRTask)17 Val (water.rapids.Val)14 File (java.io.File)11 ArrayList (java.util.ArrayList)11 Futures (water.Futures)11 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)11 ValNum (water.rapids.vals.ValNum)11 ShuffleSplitFrame (hex.splitframe.ShuffleSplitFrame)10 BufferedString (water.parser.BufferedString)10 AppendableVec (water.fvec.AppendableVec)9