Skip to content

Commit

Permalink
Refined exception messages. Fixes jpmml/sklearn2pmml#123, fixes jpmml…
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Jan 20, 2019
1 parent 78c8104 commit 90b9e57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/main/java/sklearn2pmml/pipeline/PMMLPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,28 @@ public Estimator getEstimator(){
List<Object[]> steps = getSteps();

if(steps.size() < 1){
throw new IllegalArgumentException("Expected one or more elements, got zero elements");
throw new IllegalArgumentException("Expected one or more steps, got zero steps");
}

Object[] lastStep = steps.get(steps.size() - 1);

return TupleUtil.extractElement(lastStep, 1, Estimator.class);
try {
return TupleUtil.extractElement(lastStep, 1, Estimator.class);
} catch(IllegalArgumentException iaeEstimator){
Transformer transformer = null;

try {
transformer = TupleUtil.extractElement(lastStep, 1, Transformer.class);
} catch(IllegalArgumentException iaeTransformer){
// Ignored
}

if(transformer != null){
throw new IllegalArgumentException("Expected an estimator object as the last step, got a transformer object (" + ClassDictUtil.formatClass(transformer) + ")");
}

throw iaeEstimator;
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sklearn_pandas/DataFrameMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public List<Feature> initializeFeatures(SkLearnEncoder encoder){
List<Object[]> rows = getFeatures();

if(!(Boolean.FALSE).equals(_default)){
throw new IllegalArgumentException();
throw new IllegalArgumentException("Attribute \'" + ClassDictUtil.formatMember(this, "default") + "\' must be set to the 'False' value");
}

List<Feature> result = new ArrayList<>();
Expand Down

0 comments on commit 90b9e57

Please sign in to comment.