Search in sources :

Example 41 with Val

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

the class AstNaOmitTest method TestNaOmit.

/** Test written by Nidhi to test that NaOmit actaully remove the rows with NAs in them. */
@Test
public void TestNaOmit() {
    Frame f = null;
    Frame fNew = null;
    try {
        f = ArrayUtils.frame(ar("A", "B"), ard(1.0, Double.NaN), ard(2.0, 23.3), ard(3.0, 3.3), ard(Double.NaN, 3.3));
        String x = String.format("(na.omit %s)", f._key);
        // make the call the remove NAs in frame
        Val res = Rapids.exec(x);
        // get frame without any NAs
        fNew = res.getFrame();
        // 2 rows of NAs removed.
        assertEquals(f.numRows() - fNew.numRows(), 2);
    } finally {
        if (f != null)
            f.delete();
        if (fNew != null)
            fNew.delete();
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 42 with Val

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

the class AstCumuTest method testCumuSimple.

@Test
public void testCumuSimple() {
    Scope.enter();
    try {
        Session sess = new Session();
        new TestFrameBuilder().withName("$fr", sess).withColNames("c1", "c2", "c3", "c4").withDataForCol(0, ard(1, 1)).withDataForCol(1, ard(2, 2)).withDataForCol(2, ard(3, 3)).withDataForCol(3, ard(4, 4)).build();
        Val val = Rapids.exec("(cumsum $fr 1)", sess);
        Assert.assertTrue(val instanceof ValFrame);
        Frame res = Scope.track(val.getFrame());
        Assert.assertEquals(res.vec(0).at8(0L), 1);
        Assert.assertEquals(res.vec(1).at8(0L), 3);
        Assert.assertEquals(res.vec(2).at8(0L), 6);
        Assert.assertEquals(res.vec(3).at8(0L), 10);
        val = Rapids.exec("(cumsum $fr 0)", sess);
        Assert.assertTrue(val instanceof ValFrame);
        res = Scope.track(val.getFrame());
        Assert.assertEquals(res.vec(0).at8(1L), 2);
        Assert.assertEquals(res.vec(1).at8(1L), 4);
        Assert.assertEquals(res.vec(2).at8(1L), 6);
        Assert.assertEquals(res.vec(3).at8(1L), 8);
        val = Rapids.exec("(cummax $fr 1)", sess);
        Assert.assertTrue(val instanceof ValFrame);
        res = Scope.track(val.getFrame());
        Assert.assertEquals(res.vec(0).at8(0L), 1);
        Assert.assertEquals(res.vec(1).at8(0L), 2);
        Assert.assertEquals(res.vec(2).at8(0L), 3);
        Assert.assertEquals(res.vec(3).at8(0L), 4);
    } finally {
        Scope.exit();
    }
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) TestFrameBuilder(water.fvec.TestFrameBuilder) Session(water.rapids.Session) Test(org.junit.Test)

Example 43 with Val

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

the class AstMeanTest method testRowwiseMeanOnFrameWithTimeAndNumericColumn.

@Test
public void testRowwiseMeanOnFrameWithTimeAndNumericColumn() {
    Frame fr = register(new Frame(Key.<Frame>make(), ar("t1", "i1"), aro(vt1, vi1)));
    Val val = Rapids.exec("(mean " + fr._key + " 1 1)");
    assertTrue(val instanceof ValFrame);
    Frame res = register(val.getFrame());
    assertColFrameEquals(ard(-1, -2, 0, 2, 1), 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 44 with Val

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

the class AstMeanTest method testColumnwiseMeanOnEmptyFrame.

@Test
public void testColumnwiseMeanOnEmptyFrame() {
    Frame fr = register(new Frame(Key.<Frame>make()));
    Val val = Rapids.exec("(mean " + fr._key + " 0 0)");
    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 45 with Val

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

the class AstMeanTest method testRowwiseMeanWithoutNaRmAndNonnumericColumn.

@Test
public void testRowwiseMeanWithoutNaRmAndNonnumericColumn() {
    Frame fr = register(new Frame(Key.<Frame>make(), ar("i1", "d1", "d2", "d3", "s1"), aro(vi1, vd1, vd2, vd3, vs1)));
    Val val = Rapids.exec("(mean " + fr._key + " 0 1)");
    assertTrue(val instanceof ValFrame);
    Frame res = register(val.getFrame());
    assertColFrameEquals(ard(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN), res);
    assertEquals("mean", res.name(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)

Aggregations

Val (water.rapids.Val)76 Frame (water.fvec.Frame)65 Test (org.junit.Test)56 ValFrame (water.rapids.vals.ValFrame)52 Vec (water.fvec.Vec)14 ValRow (water.rapids.vals.ValRow)8 MRTask (water.MRTask)5 Session (water.rapids.Session)5 Chunk (water.fvec.Chunk)4 TestFrameBuilder (water.fvec.TestFrameBuilder)4 ValNum (water.rapids.vals.ValNum)4 NewChunk (water.fvec.NewChunk)2 AstParameter (water.rapids.ast.AstParameter)2 AstNumList (water.rapids.ast.params.AstNumList)2 CreateFrame (hex.CreateFrame)1 GLRMParameters (hex.glrm.GLRMModel.GLRMParameters)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1