From 68e5487a100866017976e3bd163c2488fd4280c7 Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Fri, 7 Jul 2017 14:15:24 +0530 Subject: [PATCH 1/3] Too few arguments in formatting call --- sklearn/ensemble/bagging.py | 4 ++-- sklearn/multiclass.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sklearn/ensemble/bagging.py b/sklearn/ensemble/bagging.py index cc7e1b95e89b3..7ea3030bdf120 100644 --- a/sklearn/ensemble/bagging.py +++ b/sklearn/ensemble/bagging.py @@ -773,8 +773,8 @@ def decision_function(self, X): if self.n_features_ != X.shape[1]: raise ValueError("Number of features of the model must " - "match the input. Model n_features is {1} and " - "input n_features is {2} " + "match the input. Model n_features is {0} and " + "input n_features is {1} " "".format(self.n_features_, X.shape[1])) # Parallel loop diff --git a/sklearn/multiclass.py b/sklearn/multiclass.py index 3ca3b1ad42a28..a8510cf0a0a85 100644 --- a/sklearn/multiclass.py +++ b/sklearn/multiclass.py @@ -721,7 +721,7 @@ def fit(self, X, y): """ X, y = check_X_y(X, y) if self.code_size <= 0: - raise ValueError("code_size should be greater than 0, got {1}" + raise ValueError("code_size should be greater than 0, got {0}" "".format(self.code_size)) _check_estimator(self.estimator) From d2e0b0f514979e5e2e57ec3847937803ced43813 Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Thu, 13 Jul 2017 18:01:29 +0530 Subject: [PATCH 2/3] Add test --- sklearn/ensemble/tests/test_bagging.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sklearn/ensemble/tests/test_bagging.py b/sklearn/ensemble/tests/test_bagging.py index c0a46d6c15036..18cf7529b7540 100644 --- a/sklearn/ensemble/tests/test_bagging.py +++ b/sklearn/ensemble/tests/test_bagging.py @@ -448,6 +448,14 @@ def test_parallel_classification(): ensemble.set_params(n_jobs=2) decisions2 = ensemble.decision_function(X_test) assert_array_almost_equal(decisions1, decisions2) + try: + X_err = np.hstack((X_test, np.zeros((X_test.shape[0], 1)))) + decisionerr = ensemble.decision_function(X_err) + except ValueError: + print('ok') + except: + print("Unexpected error") + raise ensemble = BaggingClassifier(SVC(decision_function_shape='ovr'), n_jobs=1, From 60467b57eb021692258cdcf5ee271e54450d85c7 Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Thu, 13 Jul 2017 22:36:17 +0530 Subject: [PATCH 3/3] Covered with tests --- sklearn/ensemble/tests/test_bagging.py | 16 ++++++++-------- sklearn/tests/test_multiclass.py | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sklearn/ensemble/tests/test_bagging.py b/sklearn/ensemble/tests/test_bagging.py index 18cf7529b7540..e71462daa3a14 100644 --- a/sklearn/ensemble/tests/test_bagging.py +++ b/sklearn/ensemble/tests/test_bagging.py @@ -19,6 +19,7 @@ from sklearn.utils.testing import assert_false from sklearn.utils.testing import assert_warns from sklearn.utils.testing import assert_warns_message +from sklearn.utils.testing import assert_raise_message from sklearn.dummy import DummyClassifier, DummyRegressor from sklearn.model_selection import GridSearchCV, ParameterGrid @@ -448,14 +449,13 @@ def test_parallel_classification(): ensemble.set_params(n_jobs=2) decisions2 = ensemble.decision_function(X_test) assert_array_almost_equal(decisions1, decisions2) - try: - X_err = np.hstack((X_test, np.zeros((X_test.shape[0], 1)))) - decisionerr = ensemble.decision_function(X_err) - except ValueError: - print('ok') - except: - print("Unexpected error") - raise + + X_err = np.hstack((X_test, np.zeros((X_test.shape[0], 1)))) + assert_raise_message(ValueError, "Number of features of the model " + "must match the input. Model n_features is {0} " + "and input n_features is {1} " + "".format(X_test.shape[1], X_err.shape[1]), + ensemble.decision_function, X_err) ensemble = BaggingClassifier(SVC(decision_function_shape='ovr'), n_jobs=1, diff --git a/sklearn/tests/test_multiclass.py b/sklearn/tests/test_multiclass.py index 7008fff41aaa1..45222a1c12a68 100644 --- a/sklearn/tests/test_multiclass.py +++ b/sklearn/tests/test_multiclass.py @@ -704,6 +704,9 @@ def test_ecoc_float_y(): ovo = OutputCodeClassifier(LinearSVC()) assert_raise_message(ValueError, "Unknown label type", ovo.fit, X, y) + ovo = OutputCodeClassifier(LinearSVC(), code_size=-1) + assert_raise_message(ValueError, "code_size should be greater than 0," + " got -1", ovo.fit, X, y) def test_pairwise_indices():