Search in sources :

Example 16 with Val

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

the class AstMomentTest method testOneRowFrame.

@Test
public void testOneRowFrame() {
    Scope.enter();
    try {
        Session s = new Session();
        new TestFrameBuilder().withName("$frame1", s).withColNames("day", "hour").withDataForCol(0, ar(1)).withDataForCol(1, ard(Double.NaN)).build();
        new TestFrameBuilder().withName("$month", s).withColNames("month").withDataForCol(0, ar(2, 3)).build();
        Val result = Rapids.exec("(moment 2010 $month (cols $frame1 'day') 0 0 0 0)->$res1", s);
        assertTrue(result.isFrame());
        Frame fr = result.getFrame();
        Scope.track(fr);
        assertEquals(1, fr.numCols());
        assertEquals(2, fr.numRows());
        assertEquals(Vec.T_TIME, fr.vec(0).get_type());
        result = Rapids.exec("(moment 2010 $month 1 (cols $frame1 'hour') 0 0 0)->$res2", s);
        assertTrue(result.isFrame());
        fr = result.getFrame();
        Scope.track(fr);
        assertEquals(1, fr.numCols());
        assertEquals(2, 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)));
    } 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 17 with Val

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

the class TimeSeriesTests method testIsax.

@Test
public void testIsax() {
    //
    Val res1 = Rapids.exec("(cumsum " + f._key + " 1)");
    fr1 = res1.getFrame();
    DKV.put(fr1);
    // 10 words 10 max cardinality 0 optimize card
    Val res2 = Rapids.exec("(isax " + fr1._key + " 10 10 0)");
    fr2 = res2.getFrame();
    String expected = "0^10_0^10_0^10_0^10_5^10_7^10_8^10_9^10_9^10_8^10";
    final String actual = fr2.vec(0).atStr(new BufferedString(), 0).toString();
    Assert.assertEquals(expected, actual);
}
Also used : Val(water.rapids.Val) BufferedString(water.parser.BufferedString) BufferedString(water.parser.BufferedString) Test(org.junit.Test)

Example 18 with Val

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

the class AstGetrowTest method TestGetrow3.

/** Test columns of various types */
@Test
public void TestGetrow3() {
    Frame f = null;
    Vec[] vv = null;
    try {
        f = ArrayUtils.frame(ar("D1", "D2"), ard(0, 1));
        vv = f.vec(0).makeCons(5, 0, ar(ar("N", "Y"), ar("a", "b", "c"), null, null, null), ar(Vec.T_CAT, Vec.T_CAT, Vec.T_TIME, Vec.T_STR, Vec.T_UUID));
        f.add(ar("C1", "C2", "T1", "S1", "U1"), vv);
        Val v = Rapids.exec("(getrow " + f._key + ")");
        assertTrue(v instanceof ValRow);
        double[] row = v.getRow();
        assertEquals(7, row.length);
        assertArrayEquals(ard(0, 1, Double.NaN, Double.NaN, 0, Double.NaN, Double.NaN), row, 1e-8);
    } finally {
        if (f != null)
            f.delete();
        if (vv != null)
            for (Vec v : vv) v.remove();
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) ValRow(water.rapids.vals.ValRow) Vec(water.fvec.Vec) Test(org.junit.Test)

Example 19 with Val

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

the class AstGetrowTest method TestGetrow2.

/** Test that an exception is thrown when number of rows in the frame is > 1. */
@Test
public void TestGetrow2() {
    Frame f = null;
    try {
        f = ArrayUtils.frame(ard(-3, 4), ard(0, 1));
        Val v2 = null;
        try {
            v2 = Rapids.exec("(getrow " + f._key + ")");
        } catch (IllegalArgumentException ignored) {
        }
        assertNull("getrow is allowed only for single-row frames", v2);
    } finally {
        if (f != null)
            f.delete();
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 20 with Val

use of water.rapids.Val 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)

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