Search in sources :

Example 46 with ValFrame

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

the class AstSumAxisTest method testValRowArgument.

@Test
public void testValRowArgument() {
    Frame fr = register(new Frame(Key.<Frame>make(), ar("i1", "d1", "d2", "d3"), aro(vi1, vd1, vd2, vd3)));
    // skip NAs
    Val val = Rapids.exec("(apply " + fr._key + " 1 {x . (sumaxis x 1)})");
    assertTrue(val instanceof ValFrame);
    Frame res = register(val.getFrame());
    assertColFrameEquals(ard(1.7, 2.9, 4.1, 10.3, 10.0), res);
    // do not skip NAs
    Val val2 = Rapids.exec("(apply " + fr._key + " 1 {x . (sumaxis x 0)})");
    assertTrue(val2 instanceof ValFrame);
    Frame res2 = register(val2.getFrame());
    assertColFrameEquals(ard(1.7, 2.9, Double.NaN, 10.3, Double.NaN), res2);
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 47 with ValFrame

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

the class AstSumAxisTest method testRowwisesumOnFrameWithTimeColumnsOnly.

@Test
public void testRowwisesumOnFrameWithTimeColumnsOnly() {
    Frame fr = register(new Frame(Key.<Frame>make(), ar("t1", "s", "t2"), aro(vt1, vs1, vt2)));
    Val val = Rapids.exec("(sumaxis " + fr._key + " 1 1)");
    assertTrue(val instanceof ValFrame);
    Frame res = register(val.getFrame());
    assertEquals("Unexpected column name", "sum", res.name(0));
    assertEquals("Unexpected column type", Vec.T_TIME, res.types()[0]);
    assertColFrameEquals(ard(30000000, 30000040, 30000060, 30000080, 30000120), res);
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 48 with ValFrame

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

the class AstSumAxisTest method testRowwisesumWithNaRm.

@Test
public void testRowwisesumWithNaRm() {
    Frame fr = register(new Frame(Key.<Frame>make(), ar("i1", "d1", "d2", "d3", "s1"), aro(vi1, vd1, vd2, vd3, vs1)));
    Val val = Rapids.exec("(sumaxis " + fr._key + " 1 1)");
    assertTrue(val instanceof ValFrame);
    Frame res = register(val.getFrame());
    assertEquals("Unexpected column name", "sum", res.name(0));
    assertEquals("Unexpected column type", Vec.T_NUM, res.types()[0]);
    assertColFrameEquals(ard(1.7, 2.9, 4.1, 10.3, 10.0), res);
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 49 with ValFrame

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

the class AstSumAxisTest method testRowwisesumOnEmptyFrame.

@Test
public void testRowwisesumOnEmptyFrame() {
    Frame fr = register(new Frame(Key.<Frame>make()));
    Val val = Rapids.exec("(sumaxis " + fr._key + " 0 1)");
    assertTrue(val instanceof ValFrame);
    Frame res = register(val.getFrame());
    assertEquals(res.numCols(), 0);
    assertEquals(res.numRows(), 0);
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 50 with ValFrame

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

the class AstAppend method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Frame dst = stk.track(asts[1].exec(env)).getFrame();
    Val vsrc = stk.track(asts[2].exec(env));
    String newColName = asts[3].exec(env).getStr();
    Vec vec = dst.anyVec();
    switch(vsrc.type()) {
        case Val.NUM:
            vec = vec.makeCon(vsrc.getNum());
            break;
        case Val.STR:
            throw H2O.unimpl();
        case Val.FRM:
            if (vsrc.getFrame().numCols() != 1)
                throw new IllegalArgumentException("Can only append one column");
            vec = vsrc.getFrame().anyVec();
            break;
        default:
            throw new IllegalArgumentException("Source must be a Frame or Number, but found a " + vsrc.getClass());
    }
    dst = new Frame(dst._names.clone(), dst.vecs().clone());
    dst.add(newColName, vec);
    return new ValFrame(dst);
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec)

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