Skip to content

Commit

Permalink
Replaced PandasCategoricalParser class with PandasUtil utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Dec 14, 2023
1 parent a2eb6ca commit e0ed309
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
4 changes: 1 addition & 3 deletions pmml-lightgbm/src/main/java/org/jpmml/lightgbm/GBDT.java
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,7 @@ private List<List<?>> loadPandasCategorical(Section section){
String id = section.id();

try {
PandasCategoricalParser parser = new PandasCategoricalParser(id);

return parser.parsePandasCategorical();
return PandasUtil.parsePandasCategorical(id);
} catch(Exception e){
throw new IllegalArgumentException(id, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,19 @@
import com.google.gson.JsonParser;
import com.google.gson.ToNumberPolicy;

public class PandasCategoricalParser {
public class PandasUtil {

private String string = null;


public PandasCategoricalParser(String string){
setString(string);
private PandasUtil(){
}

public List<List<?>> parsePandasCategorical(){
String string = getString();
static
public List<List<?>> parsePandasCategorical(String string){

if(!string.startsWith(PandasCategoricalParser.PREFIX)){
if(!string.startsWith(PandasUtil.PREFIX_PANDAS_CATEGORICAL)){
throw new IllegalArgumentException(string);
}

string = string.substring(PandasCategoricalParser.PREFIX.length());
string = string.substring(PandasUtil.PREFIX_PANDAS_CATEGORICAL.length());

JsonElement element = JsonParser.parseString(string);

Expand All @@ -60,17 +56,9 @@ public List<List<?>> parsePandasCategorical(){
return result;
}

public String getString(){
return this.string;
}

private void setString(String string){
this.string = string;
}

static
private class ListOfLists extends ArrayList<List<?>> {
}

private static final String PREFIX = "pandas_categorical:";
public static final String PREFIX_PANDAS_CATEGORICAL = "pandas_categorical:";
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import static org.junit.Assert.assertEquals;

public class PandasCategoricalParserTest {
public class PandasUtilTest {

@Test
public void parse() throws Exception {
Expand All @@ -41,8 +41,6 @@ public void parse() throws Exception {

static
private List<List<?>> parsePandasCategorical(String value){
PandasCategoricalParser parser = new PandasCategoricalParser("pandas_categorical:" + value);

return parser.parsePandasCategorical();
return PandasUtil.parsePandasCategorical(PandasUtil.PREFIX_PANDAS_CATEGORICAL + value);
}
}

0 comments on commit e0ed309

Please sign in to comment.