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):