Skip to content

Commit

Permalink
Ensured compatibility with Numpy 1.26(.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Dec 3, 2023
1 parent 56e279a commit 5939f84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 4 additions & 8 deletions sklearn2pmml/decoration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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":
Expand Down
12 changes: 6 additions & 6 deletions sklearn2pmml/decoration/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,19 @@ 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())
domain = clone(ContinuousDomain(outlier_treatment = "as_extreme_values", low_value = 0.0, high_value = 3.0, missing_values = -1.0))
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())
Expand Down

0 comments on commit 5939f84

Please sign in to comment.