From 8ca1d9f795d44aed377a647b700ac005764e7043 Mon Sep 17 00:00:00 2001 From: Villu Ruusmann Date: Mon, 28 Oct 2024 22:26:43 +0200 Subject: [PATCH] Fixed evaluation environments --- sklearn2pmml/preprocessing/tests/__init__.py | 7 +++++++ sklearn2pmml/util/__init__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sklearn2pmml/preprocessing/tests/__init__.py b/sklearn2pmml/preprocessing/tests/__init__.py index 648e080..48053f5 100644 --- a/sklearn2pmml/preprocessing/tests/__init__.py +++ b/sklearn2pmml/preprocessing/tests/__init__.py @@ -405,6 +405,13 @@ def test_func_transform(self): X = numpy.array([[1.5], [0.0], [-3.0]]) self.assertEqual([[1], [0], [-1]], transformer.fit_transform(X).tolist()) + def test_regex_transform(self): + transformer = ExpressionTransformer("pcre2.substitute(r'B+', r'c', X[0])") + X = numpy.array([["ABBA"]]) + self.assertEqual([["AcA"]], transformer.fit_transform(X).tolist()) + transformer = ExpressionTransformer("re.sub(r'B+', r'c', X[0])") + self.assertEqual([["AcA"]], transformer.fit_transform(X).tolist()) + def test_sequence_transform(self): X = DataFrame([[None], [1], [None]], columns = ["a"]) mapper = DataFrameMapper([ diff --git a/sklearn2pmml/util/__init__.py b/sklearn2pmml/util/__init__.py index 36f349a..bb84f76 100644 --- a/sklearn2pmml/util/__init__.py +++ b/sklearn2pmml/util/__init__.py @@ -181,7 +181,7 @@ def to_expr(expr): else: raise TypeError() -def to_expr_func(expr, modules = ["math", "re", "pcre", "numpy", "pandas", "scipy"]): +def to_expr_func(expr, modules = ["math", "re", "pcre", "pcre2", "numpy", "pandas", "scipy"]): env = dict() if isinstance(expr, str):