use of water.Key in project h2o-3 by h2oai.
the class ParseTimeTest method testDayParseNoTime3.
@Test
public void testDayParseNoTime3() {
DateTimeZone pst = DateTimeZone.forID("America/Los_Angeles");
DateTimeZone localTZ = DateTimeZone.getDefault();
// Just yyyy-mm, no time no day
String data = "Date\n" + "2014-1\n" + "2014-2\n" + "2014-3\n" + "2014-4\n";
Key k1 = ParserTest.makeByteVec(data);
Key r1 = Key.make("r1");
Frame fr = ParseDataset.parse(r1, k1);
Assert.assertTrue(fr.vec(0).get_type_str().equals("Time"));
long[] exp = new long[] { // Date, note: these ms counts all presume PST
1388563200000L, 1391241600000L, 1393660800000L, 1396335600000L };
for (// Adjust exp[] to local time
int i = 0; // Adjust exp[] to local time
i < exp.length; // Adjust exp[] to local time
i++) exp[i] += pst.getOffset(exp[i]) - localTZ.getOffset(exp[i]);
Vec vec = fr.vec("Date");
for (int i = 0; i < exp.length; i++) Assert.assertEquals(exp[i], vec.at8(i));
fr.delete();
}
use of water.Key in project h2o-3 by h2oai.
the class ParserTestARFF method testColNames.
/**
* Helper to check parsed column names
*/
private void testColNames(String[] dataset, String[] exp, int len, String sep) {
StringBuilder sb1 = new StringBuilder();
for (String ds : dataset) sb1.append(ds).append(sep);
Key k1 = makeByteVec(sb1.toString());
Key r1 = Key.make("r1");
ParseDataset.parse(r1, k1);
Frame fr = DKV.get(r1).get();
try {
Assert.assertEquals(len, fr.numRows());
Assert.assertEquals(exp.length, fr.numCols());
for (int j = 0; j < fr.numCols(); ++j) {
Assert.assertTrue(exp[j].equals(fr.names()[j]));
}
} finally {
fr.delete();
}
}
use of water.Key in project h2o-3 by h2oai.
the class ParserTestARFF method testUUIDSplit.
@Test
@Ignore
public void testUUIDSplit() {
String data1 = "@RELATION uuid\n" + "\n" + "@ATTRIBUTE col UUID\n" + "\n" + "@DATA\n" + "19281622-47ff-af63-185c-d8b2a244c78e7c6\n";
String data2 = "19281622-47ff-af63-185c-d8b2a244c78e7c6\n" + "7f79c2b5-da56-721f-22f9-fdd726b13daf8e8\n" + "7f79c2b5-da56-721f-22f9-fdd726b13daf8e8\n";
Key k1 = ParserTest.makeByteVec(data1);
Key k2 = ParserTest.makeByteVec(data2);
Key[] k = new Key[] { k1, k2 };
Frame fr = ParseDataset.parse(Key.make(), k);
Assert.assertTrue(fr.anyVec().isUUID());
Assert.assertFalse(fr.anyVec().isCategorical());
Assert.assertFalse(fr.anyVec().isString());
Assert.assertTrue(!fr.anyVec().isNA(0));
Assert.assertTrue(!fr.anyVec().isNA(1));
fr.delete();
}
use of water.Key in project h2o-3 by h2oai.
the class ParserTestARFF method testTypes.
/**
* Helper to check parsed column types
*/
private void testTypes(String[] dataset, byte[] exp, int len, String sep) {
StringBuilder sb1 = new StringBuilder();
for (String ds : dataset) sb1.append(ds).append(sep);
Key k1 = makeByteVec(sb1.toString());
Key r1 = Key.make("r1");
ParseDataset.parse(r1, k1);
Frame fr = DKV.get(r1).get();
try {
Assert.assertEquals(len, fr.numRows());
Assert.assertEquals(exp.length, fr.numCols());
for (int j = 0; j < fr.numCols(); ++j) {
Vec vec = fr.vecs()[j];
if (exp[j] == Vec.T_TIME) {
//Time
Assert.assertTrue(vec.isTime());
// Assert.assertFalse(vec.isInt()); //FIXME time is encoded as integer, but should isInt() be true?
Assert.assertFalse(vec.isCategorical());
Assert.assertFalse(vec.isString());
Assert.assertFalse(vec.isUUID());
} else if (exp[j] == Vec.T_CAT) {
//Categorical
Assert.assertTrue(vec.isCategorical());
// Assert.assertFalse(vec.isInt()); //FIXME categorical is encoded as integer, but should isInt() be true?
Assert.assertFalse(vec.isString());
Assert.assertFalse(vec.isTime());
Assert.assertFalse(vec.isUUID());
} else if (exp[j] == Vec.T_STR) {
//String
Assert.assertTrue(vec.isString());
Assert.assertFalse(vec.isInt());
Assert.assertFalse(vec.isCategorical());
Assert.assertFalse(vec.isTime());
Assert.assertFalse(vec.isUUID());
} else if (exp[j] == Vec.T_NUM) {
//Numeric (can be Int or not)
Assert.assertTrue(!vec.isCategorical() && !vec.isString() && !vec.isUUID() && !vec.isTime());
} else if (exp[j] == Vec.T_UUID) {
//UUID
Assert.assertTrue(vec.isUUID());
// Assert.assertFalse(vec.isInt()); //FIXME uuid is encoded as integer, but should isInt() be true?
Assert.assertFalse(vec.isCategorical());
Assert.assertFalse(vec.isString());
Assert.assertFalse(vec.isTime());
} else
throw H2O.unimpl();
}
} finally {
fr.delete();
}
}
use of water.Key in project h2o-3 by h2oai.
the class ParserTestARFF method testNumSplit.
@Test
public void testNumSplit() {
String data1 = "@RELATION type\n" + "\n" + "@ATTRIBUTE num numeric\n" + "\n" + "@DATA\n" + "0\n" + "1.324e-13\n" + "-2\n";
String data2 = "4\n" + "5\n" + "6\n";
double[][] exp = new double[][] { ard(0), ard(1.324e-13), ard(-2), ard(4), ard(5), ard(6) };
Key k1 = ParserTest.makeByteVec(data1);
Key k2 = ParserTest.makeByteVec(data2);
Key[] k = new Key[] { k1, k2 };
ParserTest.testParsed(ParseDataset.parse(Key.make(), k), exp, 6);
}
Aggregations