From 7085f6fb0c380163ee5bfe9cba294e2b25cf6012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Thu, 12 Dec 2019 22:35:18 +0100 Subject: [PATCH 1/7] add print to test --- test/test_pairs_classifiers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_pairs_classifiers.py b/test/test_pairs_classifiers.py index 840cd151..e92a95dd 100644 --- a/test/test_pairs_classifiers.py +++ b/test/test_pairs_classifiers.py @@ -121,6 +121,8 @@ def test_threshold_different_scores_is_finite(estimator, build_dataset, estimator.fit(input_data, labels) with pytest.warns(None) as record: estimator.calibrate_threshold(input_data, labels, **kwargs) + for w in record: + print(record[w]) assert len(record) == 0 From f63664c2c1bbaf43267c0b711b836c11c64ebfb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Thu, 12 Dec 2019 22:53:38 +0100 Subject: [PATCH 2/7] fix --- test/test_pairs_classifiers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_pairs_classifiers.py b/test/test_pairs_classifiers.py index e92a95dd..aed08685 100644 --- a/test/test_pairs_classifiers.py +++ b/test/test_pairs_classifiers.py @@ -121,8 +121,7 @@ def test_threshold_different_scores_is_finite(estimator, build_dataset, estimator.fit(input_data, labels) with pytest.warns(None) as record: estimator.calibrate_threshold(input_data, labels, **kwargs) - for w in record: - print(record[w]) + print(record) assert len(record) == 0 From bfcbb0fd77b2eaa537f05bf05ebb4b7d6c8fac11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Thu, 12 Dec 2019 23:09:37 +0100 Subject: [PATCH 3/7] fix again --- test/test_pairs_classifiers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_pairs_classifiers.py b/test/test_pairs_classifiers.py index aed08685..fede9d14 100644 --- a/test/test_pairs_classifiers.py +++ b/test/test_pairs_classifiers.py @@ -121,7 +121,8 @@ def test_threshold_different_scores_is_finite(estimator, build_dataset, estimator.fit(input_data, labels) with pytest.warns(None) as record: estimator.calibrate_threshold(input_data, labels, **kwargs) - print(record) + for i in range(len(record)): + warning = record.list[i].message assert len(record) == 0 From e3c1141cbd80595b48a7610d09b5a12fedbf4a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Thu, 12 Dec 2019 23:10:14 +0100 Subject: [PATCH 4/7] fix again --- test/test_pairs_classifiers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_pairs_classifiers.py b/test/test_pairs_classifiers.py index fede9d14..e3ff6a4a 100644 --- a/test/test_pairs_classifiers.py +++ b/test/test_pairs_classifiers.py @@ -122,7 +122,7 @@ def test_threshold_different_scores_is_finite(estimator, build_dataset, with pytest.warns(None) as record: estimator.calibrate_threshold(input_data, labels, **kwargs) for i in range(len(record)): - warning = record.list[i].message + print(record.list[i].message) assert len(record) == 0 From ff4980babf02050208a28f6053fc31a6c0dfcd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Fri, 13 Dec 2019 08:19:21 +0100 Subject: [PATCH 5/7] remove attributes from check_is_fitted --- metric_learn/base_metric.py | 12 ++++++------ test/test_pairs_classifiers.py | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/metric_learn/base_metric.py b/metric_learn/base_metric.py index 427fcf86..c7d1eaff 100644 --- a/metric_learn/base_metric.py +++ b/metric_learn/base_metric.py @@ -240,14 +240,14 @@ def transform(self, X): X_embedded : `numpy.ndarray`, shape=(n_samples, n_components) The embedded data points. """ - check_is_fitted(self, ['preprocessor_', 'components_']) + check_is_fitted(self) X_checked = check_input(X, type_of_inputs='classic', estimator=self, preprocessor=self.preprocessor_, accept_sparse=True) return X_checked.dot(self.components_.T) def get_metric(self): - check_is_fitted(self, 'components_') + check_is_fitted(self) components_T = self.components_.T.copy() def metric_fun(u, v, squared=False): @@ -300,7 +300,7 @@ def get_mahalanobis_matrix(self): M : `numpy.ndarray`, shape=(n_features, n_features) The copy of the learned Mahalanobis matrix. """ - check_is_fitted(self, 'components_') + check_is_fitted(self) return self.components_.T.dot(self.components_) @@ -363,7 +363,7 @@ def decision_function(self, pairs): y_predicted : `numpy.ndarray` of floats, shape=(n_constraints,) The predicted decision function value for each pair. """ - check_is_fitted(self, 'preprocessor_') + check_is_fitted(self) pairs = check_input(pairs, type_of_inputs='tuples', preprocessor=self.preprocessor_, estimator=self, tuple_size=self._tuple_size) @@ -606,7 +606,7 @@ def predict(self, quadruplets): prediction : `numpy.ndarray` of floats, shape=(n_constraints,) Predictions of the ordering of pairs, for each quadruplet. """ - check_is_fitted(self, 'preprocessor_') + check_is_fitted(self) quadruplets = check_input(quadruplets, type_of_inputs='tuples', preprocessor=self.preprocessor_, estimator=self, tuple_size=self._tuple_size) @@ -635,7 +635,7 @@ def decision_function(self, quadruplets): decision_function : `numpy.ndarray` of floats, shape=(n_constraints,) Metric differences. """ - check_is_fitted(self, 'preprocessor_') + check_is_fitted(self) quadruplets = check_input(quadruplets, type_of_inputs='tuples', preprocessor=self.preprocessor_, estimator=self, tuple_size=self._tuple_size) diff --git a/test/test_pairs_classifiers.py b/test/test_pairs_classifiers.py index e3ff6a4a..840cd151 100644 --- a/test/test_pairs_classifiers.py +++ b/test/test_pairs_classifiers.py @@ -121,8 +121,6 @@ def test_threshold_different_scores_is_finite(estimator, build_dataset, estimator.fit(input_data, labels) with pytest.warns(None) as record: estimator.calibrate_threshold(input_data, labels, **kwargs) - for i in range(len(record)): - print(record.list[i].message) assert len(record) == 0 From 2e7a581577dc13a37c7bdf3af1a148388774fcea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Fri, 13 Dec 2019 10:37:26 +0100 Subject: [PATCH 6/7] if condition based on python version --- metric_learn/base_metric.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/metric_learn/base_metric.py b/metric_learn/base_metric.py index c7d1eaff..27970548 100644 --- a/metric_learn/base_metric.py +++ b/metric_learn/base_metric.py @@ -11,6 +11,7 @@ import six from ._util import ArrayIndexer, check_input, validate_vector import warnings +import sys class BaseMetricLearner(six.with_metaclass(ABCMeta, BaseEstimator)): @@ -240,14 +241,21 @@ def transform(self, X): X_embedded : `numpy.ndarray`, shape=(n_samples, n_components) The embedded data points. """ - check_is_fitted(self) + # TODO: remove when we stop supporting Python < 3.5 + if sys.version_info.major < 3 or sys.version_info.minor < 5: + check_is_fitted(self, ['preprocessor_', 'components_']) + else: + check_is_fitted(self) X_checked = check_input(X, type_of_inputs='classic', estimator=self, preprocessor=self.preprocessor_, accept_sparse=True) return X_checked.dot(self.components_.T) def get_metric(self): - check_is_fitted(self) + if sys.version_info.major < 3 or sys.version_info.minor < 5: + check_is_fitted(self, 'components_') + else: + check_is_fitted(self) components_T = self.components_.T.copy() def metric_fun(u, v, squared=False): @@ -300,7 +308,10 @@ def get_mahalanobis_matrix(self): M : `numpy.ndarray`, shape=(n_features, n_features) The copy of the learned Mahalanobis matrix. """ - check_is_fitted(self) + if sys.version_info.major < 3 or sys.version_info.minor < 5: + check_is_fitted(self, 'components_') + else: + check_is_fitted(self) return self.components_.T.dot(self.components_) @@ -363,7 +374,10 @@ def decision_function(self, pairs): y_predicted : `numpy.ndarray` of floats, shape=(n_constraints,) The predicted decision function value for each pair. """ - check_is_fitted(self) + if sys.version_info.major < 3 or sys.version_info.minor < 5: + check_is_fitted(self, 'preprocessor_') + else: + check_is_fitted(self) pairs = check_input(pairs, type_of_inputs='tuples', preprocessor=self.preprocessor_, estimator=self, tuple_size=self._tuple_size) @@ -606,7 +620,10 @@ def predict(self, quadruplets): prediction : `numpy.ndarray` of floats, shape=(n_constraints,) Predictions of the ordering of pairs, for each quadruplet. """ - check_is_fitted(self) + if sys.version_info.major < 3 or sys.version_info.minor < 5: + check_is_fitted(self, 'preprocessor_') + else: + check_is_fitted(self) quadruplets = check_input(quadruplets, type_of_inputs='tuples', preprocessor=self.preprocessor_, estimator=self, tuple_size=self._tuple_size) @@ -635,7 +652,10 @@ def decision_function(self, quadruplets): decision_function : `numpy.ndarray` of floats, shape=(n_constraints,) Metric differences. """ - check_is_fitted(self) + if sys.version_info.major < 3 or sys.version_info.minor < 5: + check_is_fitted(self, 'preprocessor_') + else: + check_is_fitted(self) quadruplets = check_input(quadruplets, type_of_inputs='tuples', preprocessor=self.preprocessor_, estimator=self, tuple_size=self._tuple_size) From b7f2caae67676b50d9030a7b4f456ffac977fc94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Fri, 13 Dec 2019 11:03:51 +0100 Subject: [PATCH 7/7] add TODO everywhere --- metric_learn/base_metric.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/metric_learn/base_metric.py b/metric_learn/base_metric.py index 27970548..5367a01e 100644 --- a/metric_learn/base_metric.py +++ b/metric_learn/base_metric.py @@ -252,6 +252,7 @@ def transform(self, X): return X_checked.dot(self.components_.T) def get_metric(self): + # TODO: remove when we stop supporting Python < 3.5 if sys.version_info.major < 3 or sys.version_info.minor < 5: check_is_fitted(self, 'components_') else: @@ -308,6 +309,7 @@ def get_mahalanobis_matrix(self): M : `numpy.ndarray`, shape=(n_features, n_features) The copy of the learned Mahalanobis matrix. """ + # TODO: remove when we stop supporting Python < 3.5 if sys.version_info.major < 3 or sys.version_info.minor < 5: check_is_fitted(self, 'components_') else: @@ -374,6 +376,7 @@ def decision_function(self, pairs): y_predicted : `numpy.ndarray` of floats, shape=(n_constraints,) The predicted decision function value for each pair. """ + # TODO: remove when we stop supporting Python < 3.5 if sys.version_info.major < 3 or sys.version_info.minor < 5: check_is_fitted(self, 'preprocessor_') else: @@ -620,6 +623,7 @@ def predict(self, quadruplets): prediction : `numpy.ndarray` of floats, shape=(n_constraints,) Predictions of the ordering of pairs, for each quadruplet. """ + # TODO: remove when we stop supporting Python < 3.5 if sys.version_info.major < 3 or sys.version_info.minor < 5: check_is_fitted(self, 'preprocessor_') else: @@ -652,6 +656,7 @@ def decision_function(self, quadruplets): decision_function : `numpy.ndarray` of floats, shape=(n_constraints,) Metric differences. """ + # TODO: remove when we stop supporting Python < 3.5 if sys.version_info.major < 3 or sys.version_info.minor < 5: check_is_fitted(self, 'preprocessor_') else: