We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Use cleaner solution for non-truncating division in python 2
Prefer `from __future__ import division` to `1.*x/y`

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/expectations/regex_based_column_map_expectation_template.py`
Content:
```
1 """
2 This is a template for creating custom RegexBasedColumnMapExpectations.
3 For detailed instructions on how to use it, please see:
4     https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_regex_based_column_map_expectations
5 """
6 
7 from typing import Dict, Optional
8 
9 from great_expectations.core.expectation_configuration import ExpectationConfiguration
10 from great_expectations.exceptions.exceptions import (
11     InvalidExpectationConfigurationError,
12 )
13 from great_expectations.expectations.regex_based_column_map_expectation import (
14     RegexBasedColumnMapExpectation,
15     RegexColumnMapMetricProvider,
16 )
17 
18 
19 # <snippet>
20 # This class defines the Expectation itself
21 class ExpectColumnValuesToMatchSomeRegex(RegexBasedColumnMapExpectation):
22     """TODO: Add a docstring here"""
23 
24     # These values will be used to configure the metric created by your expectation
25     regex_snake_name = "regex_name"
26     regex_camel_name = "RegexName"
27     regex = "regex pattern"
28     semantic_type_name_plural = None
29 
30     # These examples will be shown in the public gallery.
31     # They will also be executed as unit tests for your Expectation.
32     examples = []
33 
34     # Here your regex is used to create a custom metric for this expectation
35     map_metric = RegexBasedColumnMapExpectation.register_metric(
36         regex_snake_name=regex_snake_name,
37         regex_camel_name=regex_camel_name,
38         regex_=regex,
39     )
40 
41     # This object contains metadata for display in the public Gallery
42     library_metadata = {
43         "tags": [],  # Tags for this Expectation in the Gallery
44         "contributors": [  # Github handles for all contributors to this Expectation.
45             "@your_name_here",  # Don't forget to add your github handle here!
46         ],
47     }
48 
49 
50 # </snippet>
51 if __name__ == "__main__":
52     ExpectColumnValuesToMatchSomeRegex().print_diagnostic_checklist()
53
```

Path: `great_expectations/expectations/regex_based_column_map_expectation.py`
Content:
```
1 import json
2 import logging
3 from abc import ABC
4 from typing import Optional
5 
6 from great_expectations.core.expectation_configuration import ExpectationConfiguration
7 from great_expectations.exceptions.exceptions import (
8     InvalidExpectationConfigurationError,
9 )
10 from great_expectations.execution_engine import (
11     PandasExecutionEngine,
12     SparkDFExecutionEngine,
13     SqlAlchemyExecutionEngine,
14 )
15 from great_expectations.expectations.expectation import (
16     ColumnMapExpectation,
17     ExpectationConfiguration,
18 )
19 from great_expectations.expectations.metrics.map_metric_provider import (
20     ColumnMapMetricProvider,
21     column_condition_partial,
22 )
23 from great_expectations.expectations.metrics.util import get_dialect_regex_expression
24 from great_expectations.expectations.util import render_evaluation_parameter_string
25 from great_expectations.render.renderer.renderer import renderer
26 from great_expectations.render.types import RenderedStringTemplateContent
27 from great_expectations.render.util import (
28     handle_strict_min_max,
29     parse_row_condition_string_pandas_engine,
30     substitute_none_for_missing,
31 )
32 
33 logger = logging.getLogger(__name__)
34 
35 
36 class RegexColumnMapMetricProvider(ColumnMapMetricProvider):
37     condition_value_keys = ()
38 
39     @column_condition_partial(engine=PandasExecutionEngine)
40     def _pandas(cls, column, **kwargs):
41         return column.astype(str).str.contains(cls.regex)
42 
43     @column_condition_partial(engine=SqlAlchemyExecutionEngine)
44     def _sqlalchemy(cls, column, _dialect, **kwargs):
45         regex_expression = get_dialect_regex_expression(column, cls.regex, _dialect)
46 
47         if regex_expression is None:
48             logger.warning(
49                 "Regex is not supported for dialect %s" % str(_dialect.dialect.name)
50             )
51             raise NotImplementedError
52 
53         return regex_expression
54 
55     @column_condition_partial(engine=SparkDFExecutionEngine)
56     def _spark(cls, column, **kwargs):
57         return column.rlike(cls.regex)
58 
59 
60 class RegexBasedColumnMapExpectation(ColumnMapExpectation, ABC):
61     @staticmethod
62     def register_metric(
63         regex_snake_name: str,
64         regex_camel_name: str,
65         regex_: str,
66     ):
67         map_metric = "column_values.match_" + regex_snake_name + "_regex"
68 
69         # Define the class using `type`. This allows us to name it dynamically.
70         new_column_regex_metric_provider = type(
71             f"(ColumnValuesMatch{regex_camel_name}Regex",
72             (RegexColumnMapMetricProvider,),
73             {
74                 "condition_metric_name": map_metric,
75                 "regex": regex_,
76             },
77         )
78 
79         return map_metric
80 
81     def validate_configuration(self, configuration: Optional[ExpectationConfiguration]):
82         super().validate_configuration(configuration)
83         try:
84             assert (
85                 getattr(self, "regex", None) is not None
86             ), "regex is required for RegexBasedColumnMap Expectations"
87             assert (
88                 "column" in configuration.kwargs
89             ), "'column' parameter is required for column map expectations"
90             if "mostly" in configuration.kwargs:
91                 mostly = configuration.kwargs["mostly"]
92                 assert isinstance(
93                     mostly, (int, float)
94                 ), "'mostly' parameter must be an integer or float"
95                 assert 0 <= mostly <= 1, "'mostly' parameter must be between 0 and 1"
96         except AssertionError as e:
97             raise InvalidExpectationConfigurationError(str(e))
98         return True
99 
100     # question, descriptive, prescriptive, diagnostic
101     @classmethod
102     @renderer(renderer_type="renderer.question")
103     def _question_renderer(
104         cls, configuration, result=None, language=None, runtime_configuration=None
105     ):
106         column = configuration.kwargs.get("column")
107         mostly = configuration.kwargs.get("mostly")
108         regex = getattr(cls, "regex")
109         semantic_type_name_plural = getattr(cls, "semantic_type_name_plural", None)
110 
111         if mostly == 1 or mostly is None:
112             if semantic_type_name_plural is not None:
113                 return f'Are all values in column "{column}" valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}?'
114             else:
115                 return f'Do all values in column "{column}" match the regular expression {regex}?'
116         else:
117             if semantic_type_name_plural is not None:
118                 return f'Are at least {mostly * 100}% of values in column "{column}" valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}?'
119             else:
120                 return f'Do at least {mostly * 100}% of values in column "{column}" match the regular expression {regex}?'
121 
122     @classmethod
123     @renderer(renderer_type="renderer.answer")
124     def _answer_renderer(
125         cls, configuration=None, result=None, language=None, runtime_configuration=None
126     ):
127         column = result.expectation_config.kwargs.get("column")
128         mostly = result.expectation_config.kwargs.get("mostly")
129         regex = result.expectation_config.kwargs.get("regex")
130         semantic_type_name_plural = configuration.kwargs.get(
131             "semantic_type_name_plural"
132         )
133 
134         if result.success:
135             if mostly == 1 or mostly is None:
136                 if semantic_type_name_plural is not None:
137                     return f'All values in column "{column}" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'
138                 else:
139                     return f'All values in column "{column}" match the regular expression {regex}.'
140             else:
141                 if semantic_type_name_plural is not None:
142                     return f'At least {mostly * 100}% of values in column "{column}" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'
143                 else:
144                     return f'At least {mostly * 100}% of values in column "{column}" match the regular expression {regex}.'
145         else:
146             if semantic_type_name_plural is not None:
147                 return f' Less than {mostly * 100}% of values in column "{column}" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'
148             else:
149                 return f'Less than {mostly * 100}% of values in column "{column}" match the regular expression {regex}.'
150 
151     @classmethod
152     def _atomic_prescriptive_template(
153         cls,
154         configuration=None,
155         result=None,
156         language=None,
157         runtime_configuration=None,
158         **kwargs,
159     ):
160         runtime_configuration = runtime_configuration or {}
161         include_column_name = runtime_configuration.get("include_column_name", True)
162         include_column_name = (
163             include_column_name if include_column_name is not None else True
164         )
165         styling = runtime_configuration.get("styling")
166         params = substitute_none_for_missing(
167             configuration.kwargs,
168             ["column", "regex", "mostly", "row_condition", "condition_parser"],
169         )
170         params_with_json_schema = {
171             "column": {"schema": {"type": "string"}, "value": params.get("column")},
172             "mostly": {"schema": {"type": "number"}, "value": params.get("mostly")},
173             "mostly_pct": {
174                 "schema": {"type": "number"},
175                 "value": params.get("mostly_pct"),
176             },
177             "regex": {"schema": {"type": "string"}, "value": params.get("regex")},
178             "row_condition": {
179                 "schema": {"type": "string"},
180                 "value": params.get("row_condition"),
181             },
182             "condition_parser": {
183                 "schema": {"type": "string"},
184                 "value": params.get("condition_parser"),
185             },
186         }
187 
188         if not params.get("regex"):
189             template_str = (
190                 "values must match a regular expression but none was specified."
191             )
192         else:
193             template_str = "values must match this regular expression: $regex"
194             if params["mostly"] is not None:
195                 params_with_json_schema["mostly_pct"]["value"] = num_to_str(
196                     params["mostly"] * 100, precision=15, no_scientific=True
197                 )
198                 template_str += ", at least $mostly_pct % of the time."
199             else:
200                 template_str += "."
201 
202         if include_column_name:
203             template_str = "$column " + template_str
204 
205         if params["row_condition"] is not None:
206             (
207                 conditional_template_str,
208                 conditional_params,
209             ) = parse_row_condition_string_pandas_engine(
210                 params["row_condition"], with_schema=True
211             )
212             template_str = conditional_template_str + ", then " + template_str
213             params_with_json_schema.update(conditional_params)
214 
215         return (template_str, params_with_json_schema, styling)
216 
217     @classmethod
218     @renderer(renderer_type="renderer.prescriptive")
219     @render_evaluation_parameter_string
220     def _prescriptive_renderer(
221         cls,
222         configuration=None,
223         result=None,
224         language=None,
225         runtime_configuration=None,
226         **kwargs,
227     ):
228         runtime_configuration = runtime_configuration or {}
229         include_column_name = runtime_configuration.get("include_column_name", True)
230         include_column_name = (
231             include_column_name if include_column_name is not None else True
232         )
233         styling = runtime_configuration.get("styling")
234         params = substitute_none_for_missing(
235             configuration.kwargs,
236             ["column", "regex", "mostly", "row_condition", "condition_parser"],
237         )
238 
239         if not params.get("regex"):
240             template_str = (
241                 "values must match a regular expression but none was specified."
242             )
243         else:
244             template_str = "values must match this regular expression: $regex"
245             if params["mostly"] is not None:
246                 params["mostly_pct"] = num_to_str(
247                     params["mostly"] * 100, precision=15, no_scientific=True
248                 )
249                 # params["mostly_pct"] = "{:.14f}".format(params["mostly"]*100).rstrip("0").rstrip(".")
250                 template_str += ", at least $mostly_pct % of the time."
251             else:
252                 template_str += "."
253 
254         if include_column_name:
255             template_str = "$column " + template_str
256 
257         if params["row_condition"] is not None:
258             (
259                 conditional_template_str,
260                 conditional_params,
261             ) = parse_row_condition_string_pandas_engine(params["row_condition"])
262             template_str = conditional_template_str + ", then " + template_str
263             params.update(conditional_params)
264 
265         params_with_json_schema = {
266             "column": {"schema": {"type": "string"}, "value": params.get("column")},
267             "mostly": {"schema": {"type": "number"}, "value": params.get("mostly")},
268             "mostly_pct": {
269                 "schema": {"type": "number"},
270                 "value": params.get("mostly_pct"),
271             },
272             "regex": {"schema": {"type": "string"}, "value": params.get("regex")},
273             "row_condition": {
274                 "schema": {"type": "string"},
275                 "value": params.get("row_condition"),
276             },
277             "condition_parser": {
278                 "schema": {"type": "string"},
279                 "value": params.get("condition_parser"),
280             },
281         }
282 
283         return [
284             RenderedStringTemplateContent(
285                 **{
286                     "content_block_type": "string_template",
287                     "string_template": {
288                         "template": template_str,
289                         "params": params,
290                         "styling": styling,
291                     },
292                 }
293             )
294         ]
295
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/expectations/regex_based_column_map_expectation_template.py b/examples/expectations/regex_based_column_map_expectation_template.py
--- a/examples/expectations/regex_based_column_map_expectation_template.py
+++ b/examples/expectations/regex_based_column_map_expectation_template.py
@@ -22,7 +22,6 @@
     """TODO: Add a docstring here"""
 
     # These values will be used to configure the metric created by your expectation
-    regex_snake_name = "regex_name"
     regex_camel_name = "RegexName"
     regex = "regex pattern"
     semantic_type_name_plural = None
@@ -33,7 +32,6 @@
 
     # Here your regex is used to create a custom metric for this expectation
     map_metric = RegexBasedColumnMapExpectation.register_metric(
-        regex_snake_name=regex_snake_name,
         regex_camel_name=regex_camel_name,
         regex_=regex,
     )
diff --git a/great_expectations/expectations/regex_based_column_map_expectation.py b/great_expectations/expectations/regex_based_column_map_expectation.py
--- a/great_expectations/expectations/regex_based_column_map_expectation.py
+++ b/great_expectations/expectations/regex_based_column_map_expectation.py
@@ -29,6 +29,7 @@
     parse_row_condition_string_pandas_engine,
     substitute_none_for_missing,
 )
+from great_expectations.util import camel_to_snake
 
 logger = logging.getLogger(__name__)
 
@@ -60,10 +61,10 @@
 class RegexBasedColumnMapExpectation(ColumnMapExpectation, ABC):
     @staticmethod
     def register_metric(
-        regex_snake_name: str,
         regex_camel_name: str,
         regex_: str,
     ):
+        regex_snake_name = camel_to_snake(regex_camel_name)
         map_metric = "column_values.match_" + regex_snake_name + "_regex"
 
         # Define the class using `type`. This allows us to name it dynamically.

{"golden_diff": "diff --git a/examples/expectations/regex_based_column_map_expectation_template.py b/examples/expectations/regex_based_column_map_expectation_template.py\n--- a/examples/expectations/regex_based_column_map_expectation_template.py\n+++ b/examples/expectations/regex_based_column_map_expectation_template.py\n@@ -22,7 +22,6 @@\n     \"\"\"TODO: Add a docstring here\"\"\"\n \n     # These values will be used to configure the metric created by your expectation\n-    regex_snake_name = \"regex_name\"\n     regex_camel_name = \"RegexName\"\n     regex = \"regex pattern\"\n     semantic_type_name_plural = None\n@@ -33,7 +32,6 @@\n \n     # Here your regex is used to create a custom metric for this expectation\n     map_metric = RegexBasedColumnMapExpectation.register_metric(\n-        regex_snake_name=regex_snake_name,\n         regex_camel_name=regex_camel_name,\n         regex_=regex,\n     )\ndiff --git a/great_expectations/expectations/regex_based_column_map_expectation.py b/great_expectations/expectations/regex_based_column_map_expectation.py\n--- a/great_expectations/expectations/regex_based_column_map_expectation.py\n+++ b/great_expectations/expectations/regex_based_column_map_expectation.py\n@@ -29,6 +29,7 @@\n     parse_row_condition_string_pandas_engine,\n     substitute_none_for_missing,\n )\n+from great_expectations.util import camel_to_snake\n \n logger = logging.getLogger(__name__)\n \n@@ -60,10 +61,10 @@\n class RegexBasedColumnMapExpectation(ColumnMapExpectation, ABC):\n     @staticmethod\n     def register_metric(\n-        regex_snake_name: str,\n         regex_camel_name: str,\n         regex_: str,\n     ):\n+        regex_snake_name = camel_to_snake(regex_camel_name)\n         map_metric = \"column_values.match_\" + regex_snake_name + \"_regex\"\n \n         # Define the class using `type`. This allows us to name it dynamically.\n", "issue": "Use cleaner solution for non-truncating division in python 2\nPrefer `from __future__ import division` to `1.*x/y`\n", "before_files": [{"content": "\"\"\"\nThis is a template for creating custom RegexBasedColumnMapExpectations.\nFor detailed instructions on how to use it, please see:\n    https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_regex_based_column_map_expectations\n\"\"\"\n\nfrom typing import Dict, Optional\n\nfrom great_expectations.core.expectation_configuration import ExpectationConfiguration\nfrom great_expectations.exceptions.exceptions import (\n    InvalidExpectationConfigurationError,\n)\nfrom great_expectations.expectations.regex_based_column_map_expectation import (\n    RegexBasedColumnMapExpectation,\n    RegexColumnMapMetricProvider,\n)\n\n\n# <snippet>\n# This class defines the Expectation itself\nclass ExpectColumnValuesToMatchSomeRegex(RegexBasedColumnMapExpectation):\n    \"\"\"TODO: Add a docstring here\"\"\"\n\n    # These values will be used to configure the metric created by your expectation\n    regex_snake_name = \"regex_name\"\n    regex_camel_name = \"RegexName\"\n    regex = \"regex pattern\"\n    semantic_type_name_plural = None\n\n    # These examples will be shown in the public gallery.\n    # They will also be executed as unit tests for your Expectation.\n    examples = []\n\n    # Here your regex is used to create a custom metric for this expectation\n    map_metric = RegexBasedColumnMapExpectation.register_metric(\n        regex_snake_name=regex_snake_name,\n        regex_camel_name=regex_camel_name,\n        regex_=regex,\n    )\n\n    # This object contains metadata for display in the public Gallery\n    library_metadata = {\n        \"tags\": [],  # Tags for this Expectation in the Gallery\n        \"contributors\": [  # Github handles for all contributors to this Expectation.\n            \"@your_name_here\",  # Don't forget to add your github handle here!\n        ],\n    }\n\n\n# </snippet>\nif __name__ == \"__main__\":\n    ExpectColumnValuesToMatchSomeRegex().print_diagnostic_checklist()\n", "path": "examples/expectations/regex_based_column_map_expectation_template.py"}, {"content": "import json\nimport logging\nfrom abc import ABC\nfrom typing import Optional\n\nfrom great_expectations.core.expectation_configuration import ExpectationConfiguration\nfrom great_expectations.exceptions.exceptions import (\n    InvalidExpectationConfigurationError,\n)\nfrom great_expectations.execution_engine import (\n    PandasExecutionEngine,\n    SparkDFExecutionEngine,\n    SqlAlchemyExecutionEngine,\n)\nfrom great_expectations.expectations.expectation import (\n    ColumnMapExpectation,\n    ExpectationConfiguration,\n)\nfrom great_expectations.expectations.metrics.map_metric_provider import (\n    ColumnMapMetricProvider,\n    column_condition_partial,\n)\nfrom great_expectations.expectations.metrics.util import get_dialect_regex_expression\nfrom great_expectations.expectations.util import render_evaluation_parameter_string\nfrom great_expectations.render.renderer.renderer import renderer\nfrom great_expectations.render.types import RenderedStringTemplateContent\nfrom great_expectations.render.util import (\n    handle_strict_min_max,\n    parse_row_condition_string_pandas_engine,\n    substitute_none_for_missing,\n)\n\nlogger = logging.getLogger(__name__)\n\n\nclass RegexColumnMapMetricProvider(ColumnMapMetricProvider):\n    condition_value_keys = ()\n\n    @column_condition_partial(engine=PandasExecutionEngine)\n    def _pandas(cls, column, **kwargs):\n        return column.astype(str).str.contains(cls.regex)\n\n    @column_condition_partial(engine=SqlAlchemyExecutionEngine)\n    def _sqlalchemy(cls, column, _dialect, **kwargs):\n        regex_expression = get_dialect_regex_expression(column, cls.regex, _dialect)\n\n        if regex_expression is None:\n            logger.warning(\n                \"Regex is not supported for dialect %s\" % str(_dialect.dialect.name)\n            )\n            raise NotImplementedError\n\n        return regex_expression\n\n    @column_condition_partial(engine=SparkDFExecutionEngine)\n    def _spark(cls, column, **kwargs):\n        return column.rlike(cls.regex)\n\n\nclass RegexBasedColumnMapExpectation(ColumnMapExpectation, ABC):\n    @staticmethod\n    def register_metric(\n        regex_snake_name: str,\n        regex_camel_name: str,\n        regex_: str,\n    ):\n        map_metric = \"column_values.match_\" + regex_snake_name + \"_regex\"\n\n        # Define the class using `type`. This allows us to name it dynamically.\n        new_column_regex_metric_provider = type(\n            f\"(ColumnValuesMatch{regex_camel_name}Regex\",\n            (RegexColumnMapMetricProvider,),\n            {\n                \"condition_metric_name\": map_metric,\n                \"regex\": regex_,\n            },\n        )\n\n        return map_metric\n\n    def validate_configuration(self, configuration: Optional[ExpectationConfiguration]):\n        super().validate_configuration(configuration)\n        try:\n            assert (\n                getattr(self, \"regex\", None) is not None\n            ), \"regex is required for RegexBasedColumnMap Expectations\"\n            assert (\n                \"column\" in configuration.kwargs\n            ), \"'column' parameter is required for column map expectations\"\n            if \"mostly\" in configuration.kwargs:\n                mostly = configuration.kwargs[\"mostly\"]\n                assert isinstance(\n                    mostly, (int, float)\n                ), \"'mostly' parameter must be an integer or float\"\n                assert 0 <= mostly <= 1, \"'mostly' parameter must be between 0 and 1\"\n        except AssertionError as e:\n            raise InvalidExpectationConfigurationError(str(e))\n        return True\n\n    # question, descriptive, prescriptive, diagnostic\n    @classmethod\n    @renderer(renderer_type=\"renderer.question\")\n    def _question_renderer(\n        cls, configuration, result=None, language=None, runtime_configuration=None\n    ):\n        column = configuration.kwargs.get(\"column\")\n        mostly = configuration.kwargs.get(\"mostly\")\n        regex = getattr(cls, \"regex\")\n        semantic_type_name_plural = getattr(cls, \"semantic_type_name_plural\", None)\n\n        if mostly == 1 or mostly is None:\n            if semantic_type_name_plural is not None:\n                return f'Are all values in column \"{column}\" valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}?'\n            else:\n                return f'Do all values in column \"{column}\" match the regular expression {regex}?'\n        else:\n            if semantic_type_name_plural is not None:\n                return f'Are at least {mostly * 100}% of values in column \"{column}\" valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}?'\n            else:\n                return f'Do at least {mostly * 100}% of values in column \"{column}\" match the regular expression {regex}?'\n\n    @classmethod\n    @renderer(renderer_type=\"renderer.answer\")\n    def _answer_renderer(\n        cls, configuration=None, result=None, language=None, runtime_configuration=None\n    ):\n        column = result.expectation_config.kwargs.get(\"column\")\n        mostly = result.expectation_config.kwargs.get(\"mostly\")\n        regex = result.expectation_config.kwargs.get(\"regex\")\n        semantic_type_name_plural = configuration.kwargs.get(\n            \"semantic_type_name_plural\"\n        )\n\n        if result.success:\n            if mostly == 1 or mostly is None:\n                if semantic_type_name_plural is not None:\n                    return f'All values in column \"{column}\" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'\n                else:\n                    return f'All values in column \"{column}\" match the regular expression {regex}.'\n            else:\n                if semantic_type_name_plural is not None:\n                    return f'At least {mostly * 100}% of values in column \"{column}\" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'\n                else:\n                    return f'At least {mostly * 100}% of values in column \"{column}\" match the regular expression {regex}.'\n        else:\n            if semantic_type_name_plural is not None:\n                return f' Less than {mostly * 100}% of values in column \"{column}\" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'\n            else:\n                return f'Less than {mostly * 100}% of values in column \"{column}\" match the regular expression {regex}.'\n\n    @classmethod\n    def _atomic_prescriptive_template(\n        cls,\n        configuration=None,\n        result=None,\n        language=None,\n        runtime_configuration=None,\n        **kwargs,\n    ):\n        runtime_configuration = runtime_configuration or {}\n        include_column_name = runtime_configuration.get(\"include_column_name\", True)\n        include_column_name = (\n            include_column_name if include_column_name is not None else True\n        )\n        styling = runtime_configuration.get(\"styling\")\n        params = substitute_none_for_missing(\n            configuration.kwargs,\n            [\"column\", \"regex\", \"mostly\", \"row_condition\", \"condition_parser\"],\n        )\n        params_with_json_schema = {\n            \"column\": {\"schema\": {\"type\": \"string\"}, \"value\": params.get(\"column\")},\n            \"mostly\": {\"schema\": {\"type\": \"number\"}, \"value\": params.get(\"mostly\")},\n            \"mostly_pct\": {\n                \"schema\": {\"type\": \"number\"},\n                \"value\": params.get(\"mostly_pct\"),\n            },\n            \"regex\": {\"schema\": {\"type\": \"string\"}, \"value\": params.get(\"regex\")},\n            \"row_condition\": {\n                \"schema\": {\"type\": \"string\"},\n                \"value\": params.get(\"row_condition\"),\n            },\n            \"condition_parser\": {\n                \"schema\": {\"type\": \"string\"},\n                \"value\": params.get(\"condition_parser\"),\n            },\n        }\n\n        if not params.get(\"regex\"):\n            template_str = (\n                \"values must match a regular expression but none was specified.\"\n            )\n        else:\n            template_str = \"values must match this regular expression: $regex\"\n            if params[\"mostly\"] is not None:\n                params_with_json_schema[\"mostly_pct\"][\"value\"] = num_to_str(\n                    params[\"mostly\"] * 100, precision=15, no_scientific=True\n                )\n                template_str += \", at least $mostly_pct % of the time.\"\n            else:\n                template_str += \".\"\n\n        if include_column_name:\n            template_str = \"$column \" + template_str\n\n        if params[\"row_condition\"] is not None:\n            (\n                conditional_template_str,\n                conditional_params,\n            ) = parse_row_condition_string_pandas_engine(\n                params[\"row_condition\"], with_schema=True\n            )\n            template_str = conditional_template_str + \", then \" + template_str\n            params_with_json_schema.update(conditional_params)\n\n        return (template_str, params_with_json_schema, styling)\n\n    @classmethod\n    @renderer(renderer_type=\"renderer.prescriptive\")\n    @render_evaluation_parameter_string\n    def _prescriptive_renderer(\n        cls,\n        configuration=None,\n        result=None,\n        language=None,\n        runtime_configuration=None,\n        **kwargs,\n    ):\n        runtime_configuration = runtime_configuration or {}\n        include_column_name = runtime_configuration.get(\"include_column_name\", True)\n        include_column_name = (\n            include_column_name if include_column_name is not None else True\n        )\n        styling = runtime_configuration.get(\"styling\")\n        params = substitute_none_for_missing(\n            configuration.kwargs,\n            [\"column\", \"regex\", \"mostly\", \"row_condition\", \"condition_parser\"],\n        )\n\n        if not params.get(\"regex\"):\n            template_str = (\n                \"values must match a regular expression but none was specified.\"\n            )\n        else:\n            template_str = \"values must match this regular expression: $regex\"\n            if params[\"mostly\"] is not None:\n                params[\"mostly_pct\"] = num_to_str(\n                    params[\"mostly\"] * 100, precision=15, no_scientific=True\n                )\n                # params[\"mostly_pct\"] = \"{:.14f}\".format(params[\"mostly\"]*100).rstrip(\"0\").rstrip(\".\")\n                template_str += \", at least $mostly_pct % of the time.\"\n            else:\n                template_str += \".\"\n\n        if include_column_name:\n            template_str = \"$column \" + template_str\n\n        if params[\"row_condition\"] is not None:\n            (\n                conditional_template_str,\n                conditional_params,\n            ) = parse_row_condition_string_pandas_engine(params[\"row_condition\"])\n            template_str = conditional_template_str + \", then \" + template_str\n            params.update(conditional_params)\n\n        params_with_json_schema = {\n            \"column\": {\"schema\": {\"type\": \"string\"}, \"value\": params.get(\"column\")},\n            \"mostly\": {\"schema\": {\"type\": \"number\"}, \"value\": params.get(\"mostly\")},\n            \"mostly_pct\": {\n                \"schema\": {\"type\": \"number\"},\n                \"value\": params.get(\"mostly_pct\"),\n            },\n            \"regex\": {\"schema\": {\"type\": \"string\"}, \"value\": params.get(\"regex\")},\n            \"row_condition\": {\n                \"schema\": {\"type\": \"string\"},\n                \"value\": params.get(\"row_condition\"),\n            },\n            \"condition_parser\": {\n                \"schema\": {\"type\": \"string\"},\n                \"value\": params.get(\"condition_parser\"),\n            },\n        }\n\n        return [\n            RenderedStringTemplateContent(\n                **{\n                    \"content_block_type\": \"string_template\",\n                    \"string_template\": {\n                        \"template\": template_str,\n                        \"params\": params,\n                        \"styling\": styling,\n                    },\n                }\n            )\n        ]\n", "path": "great_expectations/expectations/regex_based_column_map_expectation.py"}], "after_files": [{"content": "\"\"\"\nThis is a template for creating custom RegexBasedColumnMapExpectations.\nFor detailed instructions on how to use it, please see:\n    https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_regex_based_column_map_expectations\n\"\"\"\n\nfrom typing import Dict, Optional\n\nfrom great_expectations.core.expectation_configuration import ExpectationConfiguration\nfrom great_expectations.exceptions.exceptions import (\n    InvalidExpectationConfigurationError,\n)\nfrom great_expectations.expectations.regex_based_column_map_expectation import (\n    RegexBasedColumnMapExpectation,\n    RegexColumnMapMetricProvider,\n)\n\n\n# <snippet>\n# This class defines the Expectation itself\nclass ExpectColumnValuesToMatchSomeRegex(RegexBasedColumnMapExpectation):\n    \"\"\"TODO: Add a docstring here\"\"\"\n\n    # These values will be used to configure the metric created by your expectation\n    regex_camel_name = \"RegexName\"\n    regex = \"regex pattern\"\n    semantic_type_name_plural = None\n\n    # These examples will be shown in the public gallery.\n    # They will also be executed as unit tests for your Expectation.\n    examples = []\n\n    # Here your regex is used to create a custom metric for this expectation\n    map_metric = RegexBasedColumnMapExpectation.register_metric(\n        regex_camel_name=regex_camel_name,\n        regex_=regex,\n    )\n\n    # This object contains metadata for display in the public Gallery\n    library_metadata = {\n        \"tags\": [],  # Tags for this Expectation in the Gallery\n        \"contributors\": [  # Github handles for all contributors to this Expectation.\n            \"@your_name_here\",  # Don't forget to add your github handle here!\n        ],\n    }\n\n\n# </snippet>\nif __name__ == \"__main__\":\n    ExpectColumnValuesToMatchSomeRegex().print_diagnostic_checklist()\n", "path": "examples/expectations/regex_based_column_map_expectation_template.py"}, {"content": "import json\nimport logging\nfrom abc import ABC\nfrom typing import Optional\n\nfrom great_expectations.core.expectation_configuration import ExpectationConfiguration\nfrom great_expectations.exceptions.exceptions import (\n    InvalidExpectationConfigurationError,\n)\nfrom great_expectations.execution_engine import (\n    PandasExecutionEngine,\n    SparkDFExecutionEngine,\n    SqlAlchemyExecutionEngine,\n)\nfrom great_expectations.expectations.expectation import (\n    ColumnMapExpectation,\n    ExpectationConfiguration,\n)\nfrom great_expectations.expectations.metrics.map_metric_provider import (\n    ColumnMapMetricProvider,\n    column_condition_partial,\n)\nfrom great_expectations.expectations.metrics.util import get_dialect_regex_expression\nfrom great_expectations.expectations.util import render_evaluation_parameter_string\nfrom great_expectations.render.renderer.renderer import renderer\nfrom great_expectations.render.types import RenderedStringTemplateContent\nfrom great_expectations.render.util import (\n    handle_strict_min_max,\n    parse_row_condition_string_pandas_engine,\n    substitute_none_for_missing,\n)\nfrom great_expectations.util import camel_to_snake\n\nlogger = logging.getLogger(__name__)\n\n\nclass RegexColumnMapMetricProvider(ColumnMapMetricProvider):\n    condition_value_keys = ()\n\n    @column_condition_partial(engine=PandasExecutionEngine)\n    def _pandas(cls, column, **kwargs):\n        return column.astype(str).str.contains(cls.regex)\n\n    @column_condition_partial(engine=SqlAlchemyExecutionEngine)\n    def _sqlalchemy(cls, column, _dialect, **kwargs):\n        regex_expression = get_dialect_regex_expression(column, cls.regex, _dialect)\n\n        if regex_expression is None:\n            logger.warning(\n                \"Regex is not supported for dialect %s\" % str(_dialect.dialect.name)\n            )\n            raise NotImplementedError\n\n        return regex_expression\n\n    @column_condition_partial(engine=SparkDFExecutionEngine)\n    def _spark(cls, column, **kwargs):\n        return column.rlike(cls.regex)\n\n\nclass RegexBasedColumnMapExpectation(ColumnMapExpectation, ABC):\n    @staticmethod\n    def register_metric(\n        regex_camel_name: str,\n        regex_: str,\n    ):\n        regex_snake_name = camel_to_snake(regex_camel_name)\n        map_metric = \"column_values.match_\" + regex_snake_name + \"_regex\"\n\n        # Define the class using `type`. This allows us to name it dynamically.\n        new_column_regex_metric_provider = type(\n            f\"(ColumnValuesMatch{regex_camel_name}Regex\",\n            (RegexColumnMapMetricProvider,),\n            {\n                \"condition_metric_name\": map_metric,\n                \"regex\": regex_,\n            },\n        )\n\n        return map_metric\n\n    def validate_configuration(self, configuration: Optional[ExpectationConfiguration]):\n        super().validate_configuration(configuration)\n        try:\n            assert (\n                getattr(self, \"regex\", None) is not None\n            ), \"regex is required for RegexBasedColumnMap Expectations\"\n            assert (\n                \"column\" in configuration.kwargs\n            ), \"'column' parameter is required for column map expectations\"\n            if \"mostly\" in configuration.kwargs:\n                mostly = configuration.kwargs[\"mostly\"]\n                assert isinstance(\n                    mostly, (int, float)\n                ), \"'mostly' parameter must be an integer or float\"\n                assert 0 <= mostly <= 1, \"'mostly' parameter must be between 0 and 1\"\n        except AssertionError as e:\n            raise InvalidExpectationConfigurationError(str(e))\n        return True\n\n    # question, descriptive, prescriptive, diagnostic\n    @classmethod\n    @renderer(renderer_type=\"renderer.question\")\n    def _question_renderer(\n        cls, configuration, result=None, language=None, runtime_configuration=None\n    ):\n        column = configuration.kwargs.get(\"column\")\n        mostly = configuration.kwargs.get(\"mostly\")\n        regex = getattr(cls, \"regex\")\n        semantic_type_name_plural = getattr(cls, \"semantic_type_name_plural\", None)\n\n        if mostly == 1 or mostly is None:\n            if semantic_type_name_plural is not None:\n                return f'Are all values in column \"{column}\" valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}?'\n            else:\n                return f'Do all values in column \"{column}\" match the regular expression {regex}?'\n        else:\n            if semantic_type_name_plural is not None:\n                return f'Are at least {mostly * 100}% of values in column \"{column}\" valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}?'\n            else:\n                return f'Do at least {mostly * 100}% of values in column \"{column}\" match the regular expression {regex}?'\n\n    @classmethod\n    @renderer(renderer_type=\"renderer.answer\")\n    def _answer_renderer(\n        cls, configuration=None, result=None, language=None, runtime_configuration=None\n    ):\n        column = result.expectation_config.kwargs.get(\"column\")\n        mostly = result.expectation_config.kwargs.get(\"mostly\")\n        regex = result.expectation_config.kwargs.get(\"regex\")\n        semantic_type_name_plural = configuration.kwargs.get(\n            \"semantic_type_name_plural\"\n        )\n\n        if result.success:\n            if mostly == 1 or mostly is None:\n                if semantic_type_name_plural is not None:\n                    return f'All values in column \"{column}\" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'\n                else:\n                    return f'All values in column \"{column}\" match the regular expression {regex}.'\n            else:\n                if semantic_type_name_plural is not None:\n                    return f'At least {mostly * 100}% of values in column \"{column}\" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'\n                else:\n                    return f'At least {mostly * 100}% of values in column \"{column}\" match the regular expression {regex}.'\n        else:\n            if semantic_type_name_plural is not None:\n                return f' Less than {mostly * 100}% of values in column \"{column}\" are valid {semantic_type_name_plural}, as judged by matching the regular expression {regex}.'\n            else:\n                return f'Less than {mostly * 100}% of values in column \"{column}\" match the regular expression {regex}.'\n\n    @classmethod\n    def _atomic_prescriptive_template(\n        cls,\n        configuration=None,\n        result=None,\n        language=None,\n        runtime_configuration=None,\n        **kwargs,\n    ):\n        runtime_configuration = runtime_configuration or {}\n        include_column_name = runtime_configuration.get(\"include_column_name\", True)\n        include_column_name = (\n            include_column_name if include_column_name is not None else True\n        )\n        styling = runtime_configuration.get(\"styling\")\n        params = substitute_none_for_missing(\n            configuration.kwargs,\n            [\"column\", \"regex\", \"mostly\", \"row_condition\", \"condition_parser\"],\n        )\n        params_with_json_schema = {\n            \"column\": {\"schema\": {\"type\": \"string\"}, \"value\": params.get(\"column\")},\n            \"mostly\": {\"schema\": {\"type\": \"number\"}, \"value\": params.get(\"mostly\")},\n            \"mostly_pct\": {\n                \"schema\": {\"type\": \"number\"},\n                \"value\": params.get(\"mostly_pct\"),\n            },\n            \"regex\": {\"schema\": {\"type\": \"string\"}, \"value\": params.get(\"regex\")},\n            \"row_condition\": {\n                \"schema\": {\"type\": \"string\"},\n                \"value\": params.get(\"row_condition\"),\n            },\n            \"condition_parser\": {\n                \"schema\": {\"type\": \"string\"},\n                \"value\": params.get(\"condition_parser\"),\n            },\n        }\n\n        if not params.get(\"regex\"):\n            template_str = (\n                \"values must match a regular expression but none was specified.\"\n            )\n        else:\n            template_str = \"values must match this regular expression: $regex\"\n            if params[\"mostly\"] is not None:\n                params_with_json_schema[\"mostly_pct\"][\"value\"] = num_to_str(\n                    params[\"mostly\"] * 100, precision=15, no_scientific=True\n                )\n                template_str += \", at least $mostly_pct % of the time.\"\n            else:\n                template_str += \".\"\n\n        if include_column_name:\n            template_str = \"$column \" + template_str\n\n        if params[\"row_condition\"] is not None:\n            (\n                conditional_template_str,\n                conditional_params,\n            ) = parse_row_condition_string_pandas_engine(\n                params[\"row_condition\"], with_schema=True\n            )\n            template_str = conditional_template_str + \", then \" + template_str\n            params_with_json_schema.update(conditional_params)\n\n        return (template_str, params_with_json_schema, styling)\n\n    @classmethod\n    @renderer(renderer_type=\"renderer.prescriptive\")\n    @render_evaluation_parameter_string\n    def _prescriptive_renderer(\n        cls,\n        configuration=None,\n        result=None,\n        language=None,\n        runtime_configuration=None,\n        **kwargs,\n    ):\n        runtime_configuration = runtime_configuration or {}\n        include_column_name = runtime_configuration.get(\"include_column_name\", True)\n        include_column_name = (\n            include_column_name if include_column_name is not None else True\n        )\n        styling = runtime_configuration.get(\"styling\")\n        params = substitute_none_for_missing(\n            configuration.kwargs,\n            [\"column\", \"regex\", \"mostly\", \"row_condition\", \"condition_parser\"],\n        )\n\n        if not params.get(\"regex\"):\n            template_str = (\n                \"values must match a regular expression but none was specified.\"\n            )\n        else:\n            template_str = \"values must match this regular expression: $regex\"\n            if params[\"mostly\"] is not None:\n                params[\"mostly_pct\"] = num_to_str(\n                    params[\"mostly\"] * 100, precision=15, no_scientific=True\n                )\n                # params[\"mostly_pct\"] = \"{:.14f}\".format(params[\"mostly\"]*100).rstrip(\"0\").rstrip(\".\")\n                template_str += \", at least $mostly_pct % of the time.\"\n            else:\n                template_str += \".\"\n\n        if include_column_name:\n            template_str = \"$column \" + template_str\n\n        if params[\"row_condition\"] is not None:\n            (\n                conditional_template_str,\n                conditional_params,\n            ) = parse_row_condition_string_pandas_engine(params[\"row_condition\"])\n            template_str = conditional_template_str + \", then \" + template_str\n            params.update(conditional_params)\n\n        params_with_json_schema = {\n            \"column\": {\"schema\": {\"type\": \"string\"}, \"value\": params.get(\"column\")},\n            \"mostly\": {\"schema\": {\"type\": \"number\"}, \"value\": params.get(\"mostly\")},\n            \"mostly_pct\": {\n                \"schema\": {\"type\": \"number\"},\n                \"value\": params.get(\"mostly_pct\"),\n            },\n            \"regex\": {\"schema\": {\"type\": \"string\"}, \"value\": params.get(\"regex\")},\n            \"row_condition\": {\n                \"schema\": {\"type\": \"string\"},\n                \"value\": params.get(\"row_condition\"),\n            },\n            \"condition_parser\": {\n                \"schema\": {\"type\": \"string\"},\n                \"value\": params.get(\"condition_parser\"),\n            },\n        }\n\n        return [\n            RenderedStringTemplateContent(\n                **{\n                    \"content_block_type\": \"string_template\",\n                    \"string_template\": {\n                        \"template\": template_str,\n                        \"params\": params,\n                        \"styling\": styling,\n                    },\n                }\n            )\n        ]\n", "path": "great_expectations/expectations/regex_based_column_map_expectation.py"}]}