From f90041c712eaf272db913eb9933c91c79ced2575 Mon Sep 17 00:00:00 2001 From: Villu Ruusmann Date: Sat, 20 Apr 2024 12:20:11 +0300 Subject: [PATCH] Refined exception messages --- .../java/sklearn/feature_extraction/text/CountVectorizer.java | 2 +- .../java/sklearn/linear_model/logistic/LogisticRegression.java | 3 ++- pmml-sklearn/src/main/java/sklearn_pandas/DataFrameMapper.java | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pmml-sklearn/src/main/java/sklearn/feature_extraction/text/CountVectorizer.java b/pmml-sklearn/src/main/java/sklearn/feature_extraction/text/CountVectorizer.java index c3b40bf7b..0ba897afe 100644 --- a/pmml-sklearn/src/main/java/sklearn/feature_extraction/text/CountVectorizer.java +++ b/pmml-sklearn/src/main/java/sklearn/feature_extraction/text/CountVectorizer.java @@ -227,7 +227,7 @@ public Object getPreprocessor(){ Object object = getOptionalObject("preprocessor"); if(object != null){ - throw new AttributeException("Attribute \'" + ClassDictUtil.formatMember(this, "preprocessor") + "\' has an unsupported value (" + ClassDictUtil.formatClass(object) + ")"); + throw new AttributeException("Attribute \'" + ClassDictUtil.formatMember(this, "preprocessor") + "\' must be set to the missing (None) value"); } return object; diff --git a/pmml-sklearn/src/main/java/sklearn/linear_model/logistic/LogisticRegression.java b/pmml-sklearn/src/main/java/sklearn/linear_model/logistic/LogisticRegression.java index ca0c82d0d..9c9e3ee3e 100644 --- a/pmml-sklearn/src/main/java/sklearn/linear_model/logistic/LogisticRegression.java +++ b/pmml-sklearn/src/main/java/sklearn/linear_model/logistic/LogisticRegression.java @@ -43,6 +43,7 @@ import org.jpmml.converter.regression.RegressionModelUtil; import org.jpmml.python.AttributeException; import org.jpmml.python.ClassDictUtil; +import org.jpmml.python.PythonFormatterUtil; import sklearn.Estimator; import sklearn.VersionUtil; import sklearn.linear_model.LinearClassifier; @@ -67,7 +68,7 @@ public Model encodeModel(Schema schema){ } else { - throw new AttributeException("Attribute \'" + ClassDictUtil.formatMember(this, "multi_class") + "\' must be explicitly set to the \'" + LogisticRegression.MULTICLASS_OVR + "\' or \'" + LogisticRegression.MULTICLASS_MULTINOMIAL + "\' value"); + throw new AttributeException("Attribute \'" + ClassDictUtil.formatMember(this, "multi_class") + "\' must be set to one of " + PythonFormatterUtil.formatValue(LogisticRegression.MULTICLASS_OVR) + " or " + PythonFormatterUtil.formatValue(LogisticRegression.MULTICLASS_MULTINOMIAL) + " values"); } } diff --git a/pmml-sklearn/src/main/java/sklearn_pandas/DataFrameMapper.java b/pmml-sklearn/src/main/java/sklearn_pandas/DataFrameMapper.java index 8eeb57a67..2642f7f80 100644 --- a/pmml-sklearn/src/main/java/sklearn_pandas/DataFrameMapper.java +++ b/pmml-sklearn/src/main/java/sklearn_pandas/DataFrameMapper.java @@ -30,6 +30,7 @@ import org.jpmml.python.CastFunction; import org.jpmml.python.ClassDictUtil; import org.jpmml.python.HasArray; +import org.jpmml.python.PythonFormatterUtil; import org.jpmml.python.TupleUtil; import org.jpmml.sklearn.SkLearnEncoder; import sklearn.Initializer; @@ -90,7 +91,7 @@ public Boolean getDefault(){ Object object = getOptionalObject("default"); if(!Objects.equals(Boolean.FALSE, object)){ - throw new AttributeException("Attribute \'" + ClassDictUtil.formatMember(this, "default") + "\' must be set to the 'False' value"); + throw new AttributeException("Attribute \'" + ClassDictUtil.formatMember(this, "default") + "\' must be set to the " + PythonFormatterUtil.formatValue(Boolean.FALSE) + " value"); } return (Boolean)object;