diff --git a/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/GBDT.java b/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/GBDT.java index ec8276f..bc615fd 100644 --- a/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/GBDT.java +++ b/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/GBDT.java @@ -615,7 +615,12 @@ private List> loadPandasCategorical(Section section){ String id = section.id(); try { - return PandasUtil.parsePandasCategorical(id); + List> result = PandasUtil.parsePandasCategorical(id); + if(result == null){ + result = Collections.emptyList(); + } + + return result; } catch(Exception e){ throw new IllegalArgumentException(id, e); } diff --git a/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/PandasUtil.java b/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/PandasUtil.java index 177705e..4cb9305 100644 --- a/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/PandasUtil.java +++ b/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/PandasUtil.java @@ -19,7 +19,6 @@ package org.jpmml.lightgbm; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import com.google.gson.Gson; @@ -48,12 +47,7 @@ public List> parsePandasCategorical(String string){ .setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE) .create(); - List> result = gson.fromJson(element, ListOfLists.class); - if(result == null){ - result = Collections.emptyList(); - } - - return result; + return gson.fromJson(element, ListOfLists.class); } static diff --git a/pmml-lightgbm/src/test/java/org/jpmml/lightgbm/PandasUtilTest.java b/pmml-lightgbm/src/test/java/org/jpmml/lightgbm/PandasUtilTest.java index ca48f5f..7317201 100644 --- a/pmml-lightgbm/src/test/java/org/jpmml/lightgbm/PandasUtilTest.java +++ b/pmml-lightgbm/src/test/java/org/jpmml/lightgbm/PandasUtilTest.java @@ -19,12 +19,12 @@ package org.jpmml.lightgbm; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class PandasUtilTest { @@ -32,7 +32,7 @@ public class PandasUtilTest { public void parse() throws Exception { List> pandasCategories = parsePandasCategorical("null"); - assertEquals(Collections.emptyList(), pandasCategories); + assertNull(pandasCategories); pandasCategories = parsePandasCategorical("[[\"null\", \"A\", \"B, B\", \"C, [C], C\"], [-2, -1, 0, 1, 2], [-2.0, -1.0, 0.0, 1.0, 2.0], [false, true]]");