From 149aade763b5afd989f1245c323fd3ee52b1271a Mon Sep 17 00:00:00 2001 From: "Zikes, Jan" Date: Tue, 3 Nov 2015 14:50:17 +0100 Subject: [PATCH 1/2] Fixed string comparison on arrays in new Gaussian process described in issue #5663 --- sklearn/gaussian_process/kernels.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sklearn/gaussian_process/kernels.py b/sklearn/gaussian_process/kernels.py index a34286e358ed5..8f363ef7f8e24 100644 --- a/sklearn/gaussian_process/kernels.py +++ b/sklearn/gaussian_process/kernels.py @@ -77,7 +77,7 @@ class Hyperparameter(namedtuple('Hyperparameter', __slots__ = () def __new__(cls, name, value_type, bounds, n_elements=1, fixed=None): - if bounds != "fixed": + if not isinstance(bounds, six.string_types) or bounds != "fixed": bounds = np.atleast_2d(bounds) if n_elements > 1: # vector-valued parameter if bounds.shape[0] == 1: @@ -88,7 +88,9 @@ def __new__(cls, name, value_type, bounds, n_elements=1, fixed=None): % (name, n_elements, bounds.shape[0])) if fixed is None: - fixed = (bounds == "fixed") + fixed = False + if isinstance(bounds, six.string_types) and bounds == "fixed": + fixed = True return super(Hyperparameter, cls).__new__( cls, name, value_type, bounds, n_elements, fixed) From b9fdeb056d99aeb185bdfe52b83608dfd442f2ac Mon Sep 17 00:00:00 2001 From: "Zikes, Jan" Date: Tue, 3 Nov 2015 15:35:10 +0100 Subject: [PATCH 2/2] shortened if condition based on glouppe's suggestion --- sklearn/gaussian_process/kernels.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sklearn/gaussian_process/kernels.py b/sklearn/gaussian_process/kernels.py index 8f363ef7f8e24..912b03a487f01 100644 --- a/sklearn/gaussian_process/kernels.py +++ b/sklearn/gaussian_process/kernels.py @@ -88,9 +88,7 @@ def __new__(cls, name, value_type, bounds, n_elements=1, fixed=None): % (name, n_elements, bounds.shape[0])) if fixed is None: - fixed = False - if isinstance(bounds, six.string_types) and bounds == "fixed": - fixed = True + fixed = isinstance(bounds, six.string_types) and bounds == "fixed" return super(Hyperparameter, cls).__new__( cls, name, value_type, bounds, n_elements, fixed)