Search in sources :

Example 36 with Val

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

the class AstMatchTest method testMatchStrList.

@Test
public void testMatchStrList() throws Exception {
    final Frame data = makeTestFrame();
    Frame output = null;
    try {
        String rapids = "(tmp= tst (match (cols data [1]) [\"sD\",\"sC\",\"sB\"] -1 ignored))";
        Val val = Rapids.exec(rapids);
        output = val.getFrame();
        assertVecEquals(data.vec(0), output.vec(0), 0.0);
    } finally {
        data.delete();
        if (output != null) {
            output.delete();
        }
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 37 with Val

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

the class AstGrepTest method testGrep_outputLogical.

@Test
public void testGrep_outputLogical() throws Exception {
    final Frame data = makeTestFrame();
    Frame output = null;
    try {
        String rapids = "(tmp= tst (grep (cols data [" + _col + "]) \"" + _regex + "\" " + _ignoreCase + " " + _invert + " 1))";
        Val val = Rapids.exec(rapids);
        output = val.getFrame();
        assertVecEquals(data.vec(0), output.vec(0), 0.0);
    } finally {
        data.delete();
        if (output != null) {
            output.delete();
        }
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 38 with Val

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

the class AstMomentTest method vectimeTest.

@Test
public void vectimeTest() {
    Scope.enter();
    try {
        Session session = new Session();
        new TestFrameBuilder().withName("$fr", session).withColNames("day", "hour", "min").withDataForCol(0, ard(1, 1.1, 1.2, 2, 3)).withDataForCol(1, ard(0, Double.NaN, 11, 13, 15)).withDataForCol(2, ar(0, 0, 30, 0, 0)).build();
        Val result = Rapids.exec("(moment 2016 12 (cols $fr 'day') 0 0 0 0)->$res1", session);
        assertTrue(result.isFrame());
        Frame fr = result.getFrame();
        Scope.track(fr);
        assertEquals(1, fr.numCols());
        assertEquals(5, fr.numRows());
        assertEquals(Vec.T_TIME, fr.vec(0).get_type());
        long t0 = (long) fr.vec(0).at(0);
        long t1 = (long) fr.vec(0).at(1);
        long t2 = (long) fr.vec(0).at(2);
        long t3 = (long) fr.vec(0).at(3);
        long t4 = (long) fr.vec(0).at(4);
        assertEquals(0, t0 - t1);
        assertEquals(0, t1 - t2);
        assertEquals(24 * 3600 * 1000, t3 - t2);
        assertEquals(24 * 3600 * 1000, t4 - t3);
        result = Rapids.exec("(moment 2016 12 1 (cols $fr 'hour') (cols $fr 'min') 0 0)->$res2", session);
        assertTrue(result.isFrame());
        fr = result.getFrame();
        Scope.track(fr);
        assertEquals(1, fr.numCols());
        assertEquals(5, fr.numRows());
        assertEquals(Vec.T_TIME, fr.vec(0).get_type());
        double d0 = fr.vec(0).at(0);
        double d1 = fr.vec(0).at(1);
        double d2 = fr.vec(0).at(2);
        double d3 = fr.vec(0).at(3);
        double d4 = fr.vec(0).at(4);
        assertTrue("d1 should have been NaN, got " + d1 + " instead", Double.isNaN(d1));
        assertEquals((11 * 60 + 30) * 60 * 1000, (long) (d2 - d0));
        assertEquals((13 * 60) * 60 * 1000, (long) (d3 - d0));
        assertEquals((15 * 60) * 60 * 1000, (long) (d4 - d0));
    } finally {
        Scope.exit();
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) TestFrameBuilder(water.fvec.TestFrameBuilder) Session(water.rapids.Session) Test(org.junit.Test)

Example 39 with Val

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

the class AstMomentTest method naTest.

@Test
public void naTest() {
    Scope.enter();
    try {
        Val result = Rapids.exec("(moment 2000 1 1 0 0 0 NaN)->$f1");
        assertTrue(result.isFrame());
        Frame fr = result.getFrame();
        Scope.track(fr);
        assertEquals(1, fr.numCols());
        assertEquals(1, fr.numRows());
        assertEquals(Vec.T_TIME, fr.vec(0).get_type());
        assertTrue(Double.isNaN(fr.vec(0).at(0)));
        Session s = new Session();
        new TestFrameBuilder().withName("$year", s).withColNames("year").withDataForCol(0, ard(2000, 2004, 2008)).build();
        result = Rapids.exec("(moment $year 1 1 0 0 NaN 0)->$f2", s);
        assertTrue(result.isFrame());
        fr = result.getFrame();
        Scope.track(fr);
        assertEquals(1, fr.numCols());
        assertEquals(3, fr.numRows());
        assertEquals(Vec.T_TIME, fr.vec(0).get_type());
        assertTrue(Double.isNaN(fr.vec(0).at(0)));
        assertTrue(Double.isNaN(fr.vec(0).at(1)));
        assertTrue(Double.isNaN(fr.vec(0).at(2)));
        new TestFrameBuilder().withName("$day", s).withColNames("day").withDataForCol(0, ard(28, 29, 30)).build();
        result = Rapids.exec("(moment 2001 2 $day 0 0 0 0)->$f3", s);
        assertTrue(result.isFrame());
        fr = result.getFrame();
        Scope.track(fr);
        assertEquals(1, fr.numCols());
        assertEquals(3, fr.numRows());
        assertEquals(Vec.T_TIME, fr.vec(0).get_type());
        assertTrue(!Double.isNaN(fr.vec(0).at(0)));
        assertTrue(Double.isNaN(fr.vec(0).at(1)));
        assertTrue(Double.isNaN(fr.vec(0).at(2)));
    } finally {
        Scope.exit();
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) TestFrameBuilder(water.fvec.TestFrameBuilder) Session(water.rapids.Session) Test(org.junit.Test)

Example 40 with Val

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

the class AstGetrowTest method TestGetrow.

/** Test that in normal case the result has the correct type and value. */
@Test
public void TestGetrow() {
    Frame f = null;
    try {
        f = ArrayUtils.frame(ar("A", "B", "C", "D", "E"), ard(1.0, -3, 12, 1000000, Double.NaN));
        Val v = Rapids.exec("(getrow " + f._key + ")");
        assertTrue(v instanceof ValRow);
        double[] row = v.getRow();
        assertEquals(row.length, 5);
        assertArrayEquals(ard(1.0, -3, 12, 1000000, Double.NaN), row, 1e-8);
    } finally {
        if (f != null)
            f.delete();
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) ValRow(water.rapids.vals.ValRow) 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