From 5939f84b34f665ac375c078448f2416196f8aab7 Mon Sep 17 00:00:00 2001 From: Villu Ruusmann Date: Sun, 3 Dec 2023 21:16:06 +0200 Subject: [PATCH] Ensured compatibility with Numpy 1.26(.2) --- sklearn2pmml/decoration/__init__.py | 12 ++++-------- sklearn2pmml/decoration/tests/__init__.py | 12 ++++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/sklearn2pmml/decoration/__init__.py b/sklearn2pmml/decoration/__init__.py index 1165579..9dd1029 100644 --- a/sklearn2pmml/decoration/__init__.py +++ b/sklearn2pmml/decoration/__init__.py @@ -226,8 +226,7 @@ def __init__(self, missing_values = None, missing_value_treatment = "as_is", mis def _valid_value_mask(self, X, where): if hasattr(self, "data_min_") and hasattr(self, "data_max_"): - mask = (numpy.greater_equal(X, self.data_min_, where = where) & numpy.less_equal(X, self.data_max_, where = where)) - return numpy.logical_and(mask, where) + return numpy.where((X >= self.data_min_) & (X <= self.data_max_), where, False) return super(ContinuousDomain, self)._valid_value_mask(X, where) def fit(self, X, y = None): @@ -257,16 +256,13 @@ def fit(self, X, y = None): return self def _outlier_mask(self, X, where): - mask = (numpy.less(X, self.low_value, where = where) | numpy.greater(X, self.high_value, where = where)) - return numpy.logical_and(mask, where) + return numpy.where((X < self.low_value) | (X > self.high_value), where, False) def _negative_outlier_mask(self, X, where): - mask = numpy.less(X, self.low_value, where = where) - return numpy.logical_and(mask, where) + return numpy.where(X < self.low_value, where, False) def _positive_outlier_mask(self, X, where): - mask = numpy.greater(X, self.high_value, where = where) - return numpy.logical_and(mask, where) + return numpy.where(X > self.high_value, where, False) def _transform_valid_values(self, X, where): if self.outlier_treatment == "as_missing_values": diff --git a/sklearn2pmml/decoration/tests/__init__.py b/sklearn2pmml/decoration/tests/__init__.py index 7dd7b0c..198eadd 100644 --- a/sklearn2pmml/decoration/tests/__init__.py +++ b/sklearn2pmml/decoration/tests/__init__.py @@ -271,9 +271,9 @@ def test_fit_float_outlier(self): X = DataFrame([[-2.0, float("NaN")], [2.0, 4.0], [float("NaN"), 0.0]]) mask = domain._missing_value_mask(X) self.assertEqual([[False, True], [False, False], [True, False]], mask.values.tolist()) - self.assertEqual([[True, False], [False, True], [False, False]], domain._outlier_mask(X, ~mask).values.tolist()) - self.assertEqual([[True, False], [False, False], [False, False]], domain._negative_outlier_mask(X, ~mask).values.tolist()) - self.assertEqual([[False, False], [False, True], [False, False]], domain._positive_outlier_mask(X, ~mask).values.tolist()) + self.assertEqual([[True, False], [False, True], [False, False]], domain._outlier_mask(X, ~mask).tolist()) + self.assertEqual([[True, False], [False, False], [False, False]], domain._negative_outlier_mask(X, ~mask).tolist()) + self.assertEqual([[False, False], [False, True], [False, False]], domain._positive_outlier_mask(X, ~mask).tolist()) Xt = domain.fit_transform(X) self.assertEqual([1.0, 2.0, 1.0], Xt[0].tolist()) self.assertEqual([1.0, 1.0, 0.0], Xt[1].tolist()) @@ -281,9 +281,9 @@ def test_fit_float_outlier(self): X = DataFrame([[-2.0, -1.0], [2.0, 4.0], [-1.0, 0.0]]) mask = domain._missing_value_mask(X) self.assertEqual([[False, True], [False, False], [True, False]], mask.values.tolist()) - self.assertEqual([[True, False], [False, True], [False, False]], domain._outlier_mask(X, ~mask).values.tolist()) - self.assertEqual([[True, False], [False, False], [False, False]], domain._negative_outlier_mask(X, ~mask).values.tolist()) - self.assertEqual([[False, False], [False, True], [False, False]], domain._positive_outlier_mask(X, ~mask).values.tolist()) + self.assertEqual([[True, False], [False, True], [False, False]], domain._outlier_mask(X, ~mask).tolist()) + self.assertEqual([[True, False], [False, False], [False, False]], domain._negative_outlier_mask(X, ~mask).tolist()) + self.assertEqual([[False, False], [False, True], [False, False]], domain._positive_outlier_mask(X, ~mask).tolist()) Xt = domain.fit_transform(X) self.assertEqual([0.0, 2.0, -1.0], X[0].tolist()) self.assertEqual([-1.0, 3.0, 0.0], X[1].tolist())