Search in sources :

Example 11 with Val

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

the class AstRectangleScalarAssignTest method testNAAssign.

@Test
public void testNAAssign() throws Exception {
    final Frame data = makeTestFrame();
    Frame output = null;
    try {
        double[] expectedNums = vec2array(data.vec(0));
        String[] expectedCats = catVec2array(data.vec(2));
        for (int i = 0; i < _nRows; i++) {
            expectedNums[i + _offset] = Double.NaN;
            expectedCats[i + _offset] = null;
        }
        String rapids = "(tmp= tst (:= data NA [0,2] [" + _offset + ":" + _nRows + "]))";
        Val val = Rapids.exec(rapids);
        output = val.getFrame();
        double[] actualNums = vec2array(output.vec(0));
        assertArrayEquals(expectedNums, actualNums, 0.0001);
        String[] actualCats = catVec2array(output.vec(2));
        assertArrayEquals(expectedCats, actualCats);
    } finally {
        data.delete();
        if (output != null) {
            output.delete();
        }
    }
}
Also used : Val(water.rapids.Val) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 12 with Val

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

the class AstMatchTest method testMatchNumList.

@Test
public void testMatchNumList() throws Exception {
    final Frame data = makeTestFrame();
    Frame output = null;
    try {
        String numList = idx(data.vec(2), "cB", "cC", "cD");
        String rapids = "(tmp= tst (match (cols data [2]) [" + numList + "] -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 13 with Val

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

the class AstGrepTest method testGrep.

@Test
public void testGrep() throws Exception {
    final Frame data = makeTestFrame();
    Frame output = null;
    try {
        String rapids = "(tmp= tst (grep (cols data [" + _col + "]) \"" + _regex + "\" " + _ignoreCase + " " + _invert + " 0))";
        Val val = Rapids.exec(rapids);
        output = val.getFrame();
        int length = (int) output.vec(0).length();
        int lastPos = -1;
        for (int i = 0; i < length; i++) {
            int pos = (int) output.vec(0).at8(i);
            for (int j = lastPos + 1; j < pos; j++) {
                assertEquals(0L, data.vec(0).at8(j));
            }
            assertEquals(1L, data.vec(0).at8(pos));
            lastPos = pos;
        }
    } finally {
        data.delete();
        if (output != null) {
            output.delete();
        }
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 14 with Val

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

the class AstMomentTest method time0Test.

@Test
public void time0Test() {
    Scope.enter();
    try {
        Val result = Rapids.exec("(moment 1970 1 1 0 0 0 0)->$f1");
        assertTrue(result.isFrame());
        Frame fr = result.getFrame();
        assertEquals(1, fr.numCols());
        assertEquals(1, fr.numRows());
        assertEquals(Vec.T_TIME, fr.vec(0).get_type());
        assertEquals(0, fr.vec(0).at8(0));
    } finally {
        Scope.exit();
    }
}
Also used : Val(water.rapids.Val) Frame(water.fvec.Frame) Test(org.junit.Test)

Example 15 with Val

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

the class AstMomentTest method badtimeTest.

@Test
public void badtimeTest() {
    Scope.enter();
    try {
        // Invalid time moment -- should be cast into NaN
        Val result = Rapids.exec("(moment 1970 0 0 0 0 0 0)->$f1");
        assertTrue(result.isFrame());
        Frame fr = result.getFrame();
        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)));
        result = Rapids.exec("(moment 2001 2 29 0 0 0 0)->$f2");
        assertTrue(Double.isNaN(result.getFrame().vec(0).at(0)));
    } finally {
        Scope.exit();
    }
}
Also used : Val(water.rapids.Val) 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