Fix a bug whereby FactorCovariate fails when "NA" is provided.

Also improved testing around this.
This commit is contained in:
Joel Therrien 2018-07-06 13:33:58 -07:00
parent 6b62ad95c3
commit 4bbb0e0948
3 changed files with 11 additions and 3 deletions

View file

@ -69,7 +69,7 @@ public final class FactorCovariate implements Covariate<String>{
@Override @Override
public FactorValue createValue(String value) { public FactorValue createValue(String value) {
if(value == null){ if(value == null || value.equalsIgnoreCase("na")){
return this.naValue; return this.naValue;
} }

View file

@ -22,6 +22,7 @@ public class TestLoadingCSV {
5,3.0,"mouse",true 5,3.0,"mouse",true
2,1.0,"dog",false 2,1.0,"dog",false
9,1.5,"cat",true 9,1.5,"cat",true
-3,NA,NA,NA
*/ */
@Test @Test
@ -41,7 +42,7 @@ public class TestLoadingCSV {
final List<Row<Double>> data = Main.loadData(covariates, settings); final List<Row<Double>> data = Main.loadData(covariates, settings);
assertEquals(3, data.size()); assertEquals(4, data.size());
Row<Double> row = data.get(0); Row<Double> row = data.get(0);
assertEquals(5.0, (double)row.getResponse()); assertEquals(5.0, (double)row.getResponse());
@ -61,6 +62,12 @@ public class TestLoadingCSV {
assertEquals("cat", row.getCovariateValue("x2").getValue()); assertEquals("cat", row.getCovariateValue("x2").getValue());
assertEquals(true, row.getCovariateValue("x3").getValue()); assertEquals(true, row.getCovariateValue("x3").getValue());
row = data.get(3);
assertEquals(-3.0, (double)row.getResponse());
assertEquals(true, row.getCovariateValue("x1").isNA());
assertEquals(true, row.getCovariateValue("x2").isNA());
assertEquals(true, row.getCovariateValue("x3").isNA());
} }
} }

View file

@ -2,3 +2,4 @@ y,x1,x2,x3
5,3.0,"mouse",true 5,3.0,"mouse",true
2,1.0,"dog",false 2,1.0,"dog",false
9,1.5,"cat",true 9,1.5,"cat",true
-3,NA,NA,NA
1 y x1 x2 x3
2 5 3.0 mouse true
3 2 1.0 dog false
4 9 1.5 cat true
5 -3 NA NA NA