Search in sources :

Example 36 with ValFrame

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

the class AstRectangleConditionalAssignTest method testConditionalAssignCategorical.

@Test
public void testConditionalAssignCategorical() {
    Frame fr = makeTestFrame();
    Vec expected = cvec(new String[] { "a", "b" }, "b", "b", "b", "b", "b");
    try {
        Val val = Rapids.exec("(tmp= py_1 (:= data \"b\" 4 (== (cols_py data 4) \"a\")))");
        if (val instanceof ValFrame) {
            Frame fr2 = val.getFrame();
            assertCatVecEquals(expected, fr2.vec(4));
            fr2.remove();
        }
    } finally {
        fr.remove();
        expected.remove();
    }
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec) Test(org.junit.Test)

Example 37 with ValFrame

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

the class AstRectangleConditionalAssignTest method testConditionalAssignString.

@Test
public void testConditionalAssignString() {
    Frame fr = makeTestFrame();
    Vec expected = svec("row1", "tst", "row3", "tst", "row5");
    try {
        Val val = Rapids.exec("(tmp= py_1 (:= data \"tst\" 3 (== (cols_py data 4) \"a\")))");
        if (val instanceof ValFrame) {
            Frame fr2 = val.getFrame();
            assertStringVecEquals(expected, fr2.vec(3));
            fr2.remove();
        }
    } finally {
        fr.remove();
        expected.remove();
    }
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec) Test(org.junit.Test)

Example 38 with ValFrame

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

the class AstRectangleFrameSliceAssignTest method testAssignFrameSlice.

@Test
public void testAssignFrameSlice() throws Exception {
    final Frame data = parse_test_file(Key.make("data"), "smalldata/airlines/allyears2k_headers.zip");
    Frame output = null;
    try {
        String rapids = "(tmp= tst (:= data (rows (cols data [8.0, 11.0] ) [10000.0:" + _nRows + ".0] ) [8.0, 11.0] [0.0:" + _nRows + ".0] ) )";
        Val val = Rapids.exec(rapids);
        if (val instanceof ValFrame) {
            output = val.getFrame();
            // categorical column
            String[] expectedCats = catVec2array(data.vec(8));
            System.arraycopy(expectedCats, 10000, expectedCats, 0, _nRows);
            String[] actualCats = catVec2array(output.vec(8));
            assertArrayEquals(expectedCats, actualCats);
            // numerical column
            double[] expected = vec2array(data.vec(11));
            System.arraycopy(expected, 10000, expected, 0, _nRows);
            double[] actual = vec2array(output.vec(11));
            assertArrayEquals(expected, actual, 0.0001d);
        }
    } finally {
        data.delete();
        if (output != null) {
            output.delete();
        }
    }
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Test(org.junit.Test)

Example 39 with ValFrame

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

the class AstMeanTest method testRowwiseMeanOnFrameWithTimeColumnsOnly.

@Test
public void testRowwiseMeanOnFrameWithTimeColumnsOnly() {
    Frame fr = register(new Frame(Key.<Frame>make(), ar("t1", "s", "t2"), aro(vt1, vs1, vt2)));
    Val val = Rapids.exec("(mean " + fr._key + " 1 1)");
    assertTrue(val instanceof ValFrame);
    Frame res = register(val.getFrame());
    assertEquals("Unexpected column name", "mean", res.name(0));
    assertEquals("Unexpected column type", Vec.T_TIME, res.types()[0]);
    assertColFrameEquals(ard(15000000, 15000020, 15000030, 15000040, 15000060), 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 40 with ValFrame

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

the class AstMeanTest method testRowwiseMeanOnFrameWithNonnumericColumnsOnly.

@Test
public void testRowwiseMeanOnFrameWithNonnumericColumnsOnly() {
    Frame fr = register(new Frame(Key.<Frame>make(), ar("c1", "s1"), aro(vc2, vs1)));
    Val val = Rapids.exec("(mean " + fr._key + " 1 1)");
    assertTrue(val instanceof ValFrame);
    Frame res = register(val.getFrame());
    assertEquals("Unexpected column name", "mean", res.name(0));
    assertEquals("Unexpected column type", Vec.T_NUM, res.types()[0]);
    assertColFrameEquals(ard(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN), 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)

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