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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
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();
}
}
Aggregations