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: `great_expectations/rule_based_profiler/helpers/cardinality_checker.py`
Content:
```
1 import abc
2 import enum
3 from dataclasses import dataclass
4 from typing import Optional, Tuple, Union
5 
6 from great_expectations.core.util import convert_to_json_serializable
7 from great_expectations.exceptions import ProfilerConfigurationError
8 from great_expectations.types import SerializableDictDot
9 
10 
11 @dataclass(frozen=True)
12 class CardinalityLimit(abc.ABC, SerializableDictDot):
13     name: str
14 
15 
16 @dataclass(frozen=True)
17 class RelativeCardinalityLimit(CardinalityLimit):
18     max_proportion_unique: float
19     metric_name_defining_limit: str = "column.unique_proportion"
20 
21     def to_json_dict(self) -> dict:
22         return convert_to_json_serializable(
23             {
24                 "name": self.name,
25                 "max_proportion_unique": self.max_proportion_unique,
26                 "metric_name_defining_limit": self.metric_name_defining_limit,
27             }
28         )
29 
30 
31 @dataclass(frozen=True)
32 class AbsoluteCardinalityLimit(CardinalityLimit):
33     max_unique_values: int
34     metric_name_defining_limit: str = "column.distinct_values.count"
35 
36     def to_json_dict(self) -> dict:
37         return convert_to_json_serializable(
38             {
39                 "name": self.name,
40                 "max_proportion_unique": self.max_unique_values,
41                 "metric_name_defining_limit": self.metric_name_defining_limit,
42             }
43         )
44 
45 
46 class CardinalityLimitMode(enum.Enum):
47     """Preset limits based on unique values (cardinality)
48 
49     Defines relative (ratio) and absolute number of records (table rows) that
50     correspond to each cardinality category.
51 
52     Used to determine appropriate Expectation configurations based on data.
53     """
54 
55     ZERO = AbsoluteCardinalityLimit("ZERO", 0)
56     ONE = AbsoluteCardinalityLimit("ONE", 1)
57     TWO = AbsoluteCardinalityLimit("TWO", 2)
58     VERY_FEW = AbsoluteCardinalityLimit("VERY_FEW", 10)
59     FEW = AbsoluteCardinalityLimit("FEW", 100)
60     SOME = AbsoluteCardinalityLimit("SOME", 1000)
61     MANY = AbsoluteCardinalityLimit("MANY", 10000)
62     VERY_MANY = AbsoluteCardinalityLimit("VERY_MANY", 100000)
63     UNIQUE = RelativeCardinalityLimit("UNIQUE", 1.0)
64     ABS_10 = AbsoluteCardinalityLimit("ABS_10", 10)
65     ABS_100 = AbsoluteCardinalityLimit("ABS_100", 100)
66     ABS_1000 = AbsoluteCardinalityLimit("ABS_1000", 1000)
67     ABS_10_000 = AbsoluteCardinalityLimit("ABS_10_000", int(1e4))
68     ABS_100_000 = AbsoluteCardinalityLimit("ABS_100_000", int(1e5))
69     ABS_1_000_000 = AbsoluteCardinalityLimit("ABS_1_000_000", int(1e6))
70     ABS_10_000_000 = AbsoluteCardinalityLimit("ABS_10_000_000", int(1e7))
71     ABS_100_000_000 = AbsoluteCardinalityLimit("ABS_100_000_000", int(1e8))
72     ABS_1_000_000_000 = AbsoluteCardinalityLimit("ABS_1_000_000_000", int(1e9))
73     REL_0 = RelativeCardinalityLimit("REL_0", 0.0)
74     REL_001 = RelativeCardinalityLimit("REL_001", 1e-5)
75     REL_01 = RelativeCardinalityLimit("REL_01", 1e-4)
76     REL_0_1 = RelativeCardinalityLimit("REL_0_1", 1e-3)
77     REL_1 = RelativeCardinalityLimit("REL_1", 1e-2)
78     REL_10 = RelativeCardinalityLimit("REL_10", 0.10)
79     REL_25 = RelativeCardinalityLimit("REL_25", 0.25)
80     REL_50 = RelativeCardinalityLimit("REL_50", 0.50)
81     REL_75 = RelativeCardinalityLimit("REL_75", 0.75)
82     REL_100 = RelativeCardinalityLimit("REL_100", 1.0)
83     ONE_PCT = RelativeCardinalityLimit("ONE_PCT", 0.01)
84     TEN_PCT = RelativeCardinalityLimit("TEN_PCT", 0.10)
85 
86 
87 class CardinalityChecker:
88     """Handles cardinality checking given cardinality limit mode and measured value.
89 
90     This class also validates cardinality limit settings and converts from
91     various types of settings. You can choose one of the attributes listed
92     below to create an instance.
93 
94     Attributes:
95         cardinality_limit_mode: CardinalityLimitMode or string name of the mode
96             defining the maximum allowable cardinality.
97         max_unique_values: number of max unique rows for a custom
98             cardinality limit.
99         max_proportion_unique: proportion of unique values for a
100             custom cardinality limit.
101     """
102 
103     SUPPORTED_CARDINALITY_LIMIT_MODE_CLASSES: Tuple[
104         Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]
105     ] = (
106         AbsoluteCardinalityLimit,
107         RelativeCardinalityLimit,
108     )
109     SUPPORTED_LIMIT_MODE_CLASS_NAMES: Tuple[str] = (
110         mode.__name__ for mode in SUPPORTED_CARDINALITY_LIMIT_MODE_CLASSES
111     )
112     SUPPORTED_CARDINALITY_LIMIT_MODE_STRINGS: Tuple[str] = (
113         mode.name for mode in CardinalityLimitMode
114     )
115 
116     def __init__(
117         self,
118         cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,
119         max_unique_values: Optional[int] = None,
120         max_proportion_unique: Optional[float] = None,
121     ) -> None:
122         self._cardinality_limit_mode = self._convert_to_cardinality_limit_mode(
123             cardinality_limit_mode=cardinality_limit_mode,
124             max_unique_values=max_unique_values,
125             max_proportion_unique=max_proportion_unique,
126         )
127 
128     @property
129     def cardinality_limit_mode(
130         self,
131     ) -> Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]:
132         return self._cardinality_limit_mode
133 
134     def cardinality_within_limit(self, metric_value: float) -> bool:
135         """Determine if the cardinality is within configured limit.
136 
137         The metric_value supplied should be either a proportion of unique values
138         or number of unique values based on the configured cardinality limit.
139 
140         Args:
141             metric_value: int if number of unique values, float if proportion
142                 of unique values.
143 
144         Returns:
145             Boolean of whether the cardinality is within the configured limit
146         """
147         self._validate_metric_value(metric_value=metric_value)
148         if isinstance(self._cardinality_limit_mode, AbsoluteCardinalityLimit):
149             return metric_value <= self._cardinality_limit_mode.max_unique_values
150         elif isinstance(self._cardinality_limit_mode, RelativeCardinalityLimit):
151             return metric_value <= self._cardinality_limit_mode.max_proportion_unique
152 
153     @staticmethod
154     def _validate_metric_value(metric_value: float) -> None:
155         if not isinstance(metric_value, (int, float)):
156             raise ProfilerConfigurationError(
157                 f"Value of measured cardinality must be of type int or float, you provided {type(metric_value)}"
158             )
159 
160         if metric_value < 0.00:
161             raise ProfilerConfigurationError(
162                 f"Value of cardinality (number of rows or percent unique) should be greater than 0.00, your value is {metric_value}"
163             )
164 
165     @staticmethod
166     def _convert_to_cardinality_limit_mode(
167         cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,
168         max_unique_values: Optional[int] = None,
169         max_proportion_unique: Optional[float] = None,
170     ) -> Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]:
171         validate_input_parameters(
172             cardinality_limit_mode=cardinality_limit_mode,
173             max_unique_values=max_unique_values,
174             max_proportion_unique=max_proportion_unique,
175         )
176 
177         if cardinality_limit_mode is not None:
178             if isinstance(cardinality_limit_mode, str):
179                 try:
180                     return CardinalityLimitMode[cardinality_limit_mode.upper()].value
181                 except KeyError:
182                     raise ProfilerConfigurationError(
183                         f"Please specify a supported cardinality mode. Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}"
184                     )
185             elif isinstance(cardinality_limit_mode, dict):
186                 validate_input_parameters(
187                     cardinality_limit_mode=cardinality_limit_mode.get("name"),
188                     max_unique_values=cardinality_limit_mode.get("max_unique_values"),
189                     max_proportion_unique=cardinality_limit_mode.get(
190                         "max_proportion_unique"
191                     ),
192                     required_num_supplied_params=2,
193                 )
194                 try:
195                     return AbsoluteCardinalityLimit(
196                         name=cardinality_limit_mode["name"],
197                         max_unique_values=cardinality_limit_mode["max_unique_values"],
198                         metric_name_defining_limit=cardinality_limit_mode[
199                             "metric_name_defining_limit"
200                         ],
201                     )
202                 except (KeyError, ValueError):
203                     try:
204                         return RelativeCardinalityLimit(
205                             name=cardinality_limit_mode["name"],
206                             max_proportion_unique=cardinality_limit_mode[
207                                 "max_proportion_unique"
208                             ],
209                             metric_name_defining_limit=cardinality_limit_mode[
210                                 "metric_name_defining_limit"
211                             ],
212                         )
213                     except (KeyError, ValueError):
214                         raise ProfilerConfigurationError(
215                             f"Please specify a supported cardinality mode.  Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}"
216                         )
217             else:
218                 return cardinality_limit_mode.value
219 
220         if max_unique_values is not None:
221             return AbsoluteCardinalityLimit(
222                 name=f"CUSTOM_ABS_{max_unique_values}",
223                 max_unique_values=max_unique_values,
224             )
225 
226         if max_proportion_unique is not None:
227             return RelativeCardinalityLimit(
228                 name=f"CUSTOM_REL_{max_proportion_unique}",
229                 max_proportion_unique=max_proportion_unique,
230             )
231 
232 
233 def validate_input_parameters(
234     cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,
235     max_unique_values: Optional[int] = None,
236     max_proportion_unique: Optional[int] = None,
237     required_num_supplied_params: int = 1,
238 ) -> None:
239     num_supplied_params: int = sum(
240         [
241             0 if param is None else 1
242             for param in (
243                 cardinality_limit_mode,
244                 max_unique_values,
245                 max_proportion_unique,
246             )
247         ]
248     )
249     if num_supplied_params != required_num_supplied_params:
250         raise ProfilerConfigurationError(
251             f"Please pass ONE of the following parameters: cardinality_limit_mode, max_unique_values, max_proportion_unique, you passed {num_supplied_params} parameters."
252         )
253 
254     if cardinality_limit_mode is not None:
255         if not isinstance(cardinality_limit_mode, (str, CardinalityLimitMode, dict)):
256             raise ProfilerConfigurationError(
257                 f"Please specify a supported cardinality limit type, supported classes are {','.join(CardinalityChecker.SUPPORTED_LIMIT_MODE_CLASS_NAMES)} and supported strings are {','.join(CardinalityChecker.SUPPORTED_CARDINALITY_LIMIT_MODE_STRINGS)}"
258             )
259 
260         if required_num_supplied_params == 2:
261             try:
262                 return CardinalityLimitMode[cardinality_limit_mode.upper()].value
263             except KeyError:
264                 raise ProfilerConfigurationError(
265                     f"Please specify a supported cardinality mode. Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}"
266                 )
267 
268     if max_unique_values is not None:
269         if not isinstance(max_unique_values, int):
270             raise ProfilerConfigurationError(
271                 f"Please specify an int, you specified a {type(max_unique_values)}"
272             )
273 
274     if max_proportion_unique is not None:
275         if not isinstance(max_proportion_unique, (float, int)):
276             raise ProfilerConfigurationError(
277                 f"Please specify a float or int, you specified a {type(max_proportion_unique)}"
278             )
279
```
--- 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/great_expectations/rule_based_profiler/helpers/cardinality_checker.py b/great_expectations/rule_based_profiler/helpers/cardinality_checker.py
--- a/great_expectations/rule_based_profiler/helpers/cardinality_checker.py
+++ b/great_expectations/rule_based_profiler/helpers/cardinality_checker.py
@@ -1,7 +1,7 @@
 import abc
 import enum
 from dataclasses import dataclass
-from typing import Optional, Tuple, Union
+from typing import Optional, Tuple, Union, cast
 
 from great_expectations.core.util import convert_to_json_serializable
 from great_expectations.exceptions import ProfilerConfigurationError
@@ -147,9 +147,14 @@
         self._validate_metric_value(metric_value=metric_value)
         if isinstance(self._cardinality_limit_mode, AbsoluteCardinalityLimit):
             return metric_value <= self._cardinality_limit_mode.max_unique_values
-        elif isinstance(self._cardinality_limit_mode, RelativeCardinalityLimit):
+
+        if isinstance(self._cardinality_limit_mode, RelativeCardinalityLimit):
             return metric_value <= self._cardinality_limit_mode.max_proportion_unique
 
+        raise ValueError(
+            f'Unknown "cardinality_limit_mode" mode "{self._cardinality_limit_mode}" encountered.'
+        )
+
     @staticmethod
     def _validate_metric_value(metric_value: float) -> None:
         if not isinstance(metric_value, (int, float)):
@@ -215,7 +220,7 @@
                             f"Please specify a supported cardinality mode.  Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}"
                         )
             else:
-                return cardinality_limit_mode.value
+                return cast(CardinalityLimitMode, cardinality_limit_mode).value
 
         if max_unique_values is not None:
             return AbsoluteCardinalityLimit(

{"golden_diff": "diff --git a/great_expectations/rule_based_profiler/helpers/cardinality_checker.py b/great_expectations/rule_based_profiler/helpers/cardinality_checker.py\n--- a/great_expectations/rule_based_profiler/helpers/cardinality_checker.py\n+++ b/great_expectations/rule_based_profiler/helpers/cardinality_checker.py\n@@ -1,7 +1,7 @@\n import abc\n import enum\n from dataclasses import dataclass\n-from typing import Optional, Tuple, Union\n+from typing import Optional, Tuple, Union, cast\n \n from great_expectations.core.util import convert_to_json_serializable\n from great_expectations.exceptions import ProfilerConfigurationError\n@@ -147,9 +147,14 @@\n         self._validate_metric_value(metric_value=metric_value)\n         if isinstance(self._cardinality_limit_mode, AbsoluteCardinalityLimit):\n             return metric_value <= self._cardinality_limit_mode.max_unique_values\n-        elif isinstance(self._cardinality_limit_mode, RelativeCardinalityLimit):\n+\n+        if isinstance(self._cardinality_limit_mode, RelativeCardinalityLimit):\n             return metric_value <= self._cardinality_limit_mode.max_proportion_unique\n \n+        raise ValueError(\n+            f'Unknown \"cardinality_limit_mode\" mode \"{self._cardinality_limit_mode}\" encountered.'\n+        )\n+\n     @staticmethod\n     def _validate_metric_value(metric_value: float) -> None:\n         if not isinstance(metric_value, (int, float)):\n@@ -215,7 +220,7 @@\n                             f\"Please specify a supported cardinality mode.  Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}\"\n                         )\n             else:\n-                return cardinality_limit_mode.value\n+                return cast(CardinalityLimitMode, cardinality_limit_mode).value\n \n         if max_unique_values is not None:\n             return AbsoluteCardinalityLimit(\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": "import abc\nimport enum\nfrom dataclasses import dataclass\nfrom typing import Optional, Tuple, Union\n\nfrom great_expectations.core.util import convert_to_json_serializable\nfrom great_expectations.exceptions import ProfilerConfigurationError\nfrom great_expectations.types import SerializableDictDot\n\n\n@dataclass(frozen=True)\nclass CardinalityLimit(abc.ABC, SerializableDictDot):\n    name: str\n\n\n@dataclass(frozen=True)\nclass RelativeCardinalityLimit(CardinalityLimit):\n    max_proportion_unique: float\n    metric_name_defining_limit: str = \"column.unique_proportion\"\n\n    def to_json_dict(self) -> dict:\n        return convert_to_json_serializable(\n            {\n                \"name\": self.name,\n                \"max_proportion_unique\": self.max_proportion_unique,\n                \"metric_name_defining_limit\": self.metric_name_defining_limit,\n            }\n        )\n\n\n@dataclass(frozen=True)\nclass AbsoluteCardinalityLimit(CardinalityLimit):\n    max_unique_values: int\n    metric_name_defining_limit: str = \"column.distinct_values.count\"\n\n    def to_json_dict(self) -> dict:\n        return convert_to_json_serializable(\n            {\n                \"name\": self.name,\n                \"max_proportion_unique\": self.max_unique_values,\n                \"metric_name_defining_limit\": self.metric_name_defining_limit,\n            }\n        )\n\n\nclass CardinalityLimitMode(enum.Enum):\n    \"\"\"Preset limits based on unique values (cardinality)\n\n    Defines relative (ratio) and absolute number of records (table rows) that\n    correspond to each cardinality category.\n\n    Used to determine appropriate Expectation configurations based on data.\n    \"\"\"\n\n    ZERO = AbsoluteCardinalityLimit(\"ZERO\", 0)\n    ONE = AbsoluteCardinalityLimit(\"ONE\", 1)\n    TWO = AbsoluteCardinalityLimit(\"TWO\", 2)\n    VERY_FEW = AbsoluteCardinalityLimit(\"VERY_FEW\", 10)\n    FEW = AbsoluteCardinalityLimit(\"FEW\", 100)\n    SOME = AbsoluteCardinalityLimit(\"SOME\", 1000)\n    MANY = AbsoluteCardinalityLimit(\"MANY\", 10000)\n    VERY_MANY = AbsoluteCardinalityLimit(\"VERY_MANY\", 100000)\n    UNIQUE = RelativeCardinalityLimit(\"UNIQUE\", 1.0)\n    ABS_10 = AbsoluteCardinalityLimit(\"ABS_10\", 10)\n    ABS_100 = AbsoluteCardinalityLimit(\"ABS_100\", 100)\n    ABS_1000 = AbsoluteCardinalityLimit(\"ABS_1000\", 1000)\n    ABS_10_000 = AbsoluteCardinalityLimit(\"ABS_10_000\", int(1e4))\n    ABS_100_000 = AbsoluteCardinalityLimit(\"ABS_100_000\", int(1e5))\n    ABS_1_000_000 = AbsoluteCardinalityLimit(\"ABS_1_000_000\", int(1e6))\n    ABS_10_000_000 = AbsoluteCardinalityLimit(\"ABS_10_000_000\", int(1e7))\n    ABS_100_000_000 = AbsoluteCardinalityLimit(\"ABS_100_000_000\", int(1e8))\n    ABS_1_000_000_000 = AbsoluteCardinalityLimit(\"ABS_1_000_000_000\", int(1e9))\n    REL_0 = RelativeCardinalityLimit(\"REL_0\", 0.0)\n    REL_001 = RelativeCardinalityLimit(\"REL_001\", 1e-5)\n    REL_01 = RelativeCardinalityLimit(\"REL_01\", 1e-4)\n    REL_0_1 = RelativeCardinalityLimit(\"REL_0_1\", 1e-3)\n    REL_1 = RelativeCardinalityLimit(\"REL_1\", 1e-2)\n    REL_10 = RelativeCardinalityLimit(\"REL_10\", 0.10)\n    REL_25 = RelativeCardinalityLimit(\"REL_25\", 0.25)\n    REL_50 = RelativeCardinalityLimit(\"REL_50\", 0.50)\n    REL_75 = RelativeCardinalityLimit(\"REL_75\", 0.75)\n    REL_100 = RelativeCardinalityLimit(\"REL_100\", 1.0)\n    ONE_PCT = RelativeCardinalityLimit(\"ONE_PCT\", 0.01)\n    TEN_PCT = RelativeCardinalityLimit(\"TEN_PCT\", 0.10)\n\n\nclass CardinalityChecker:\n    \"\"\"Handles cardinality checking given cardinality limit mode and measured value.\n\n    This class also validates cardinality limit settings and converts from\n    various types of settings. You can choose one of the attributes listed\n    below to create an instance.\n\n    Attributes:\n        cardinality_limit_mode: CardinalityLimitMode or string name of the mode\n            defining the maximum allowable cardinality.\n        max_unique_values: number of max unique rows for a custom\n            cardinality limit.\n        max_proportion_unique: proportion of unique values for a\n            custom cardinality limit.\n    \"\"\"\n\n    SUPPORTED_CARDINALITY_LIMIT_MODE_CLASSES: Tuple[\n        Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]\n    ] = (\n        AbsoluteCardinalityLimit,\n        RelativeCardinalityLimit,\n    )\n    SUPPORTED_LIMIT_MODE_CLASS_NAMES: Tuple[str] = (\n        mode.__name__ for mode in SUPPORTED_CARDINALITY_LIMIT_MODE_CLASSES\n    )\n    SUPPORTED_CARDINALITY_LIMIT_MODE_STRINGS: Tuple[str] = (\n        mode.name for mode in CardinalityLimitMode\n    )\n\n    def __init__(\n        self,\n        cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,\n        max_unique_values: Optional[int] = None,\n        max_proportion_unique: Optional[float] = None,\n    ) -> None:\n        self._cardinality_limit_mode = self._convert_to_cardinality_limit_mode(\n            cardinality_limit_mode=cardinality_limit_mode,\n            max_unique_values=max_unique_values,\n            max_proportion_unique=max_proportion_unique,\n        )\n\n    @property\n    def cardinality_limit_mode(\n        self,\n    ) -> Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]:\n        return self._cardinality_limit_mode\n\n    def cardinality_within_limit(self, metric_value: float) -> bool:\n        \"\"\"Determine if the cardinality is within configured limit.\n\n        The metric_value supplied should be either a proportion of unique values\n        or number of unique values based on the configured cardinality limit.\n\n        Args:\n            metric_value: int if number of unique values, float if proportion\n                of unique values.\n\n        Returns:\n            Boolean of whether the cardinality is within the configured limit\n        \"\"\"\n        self._validate_metric_value(metric_value=metric_value)\n        if isinstance(self._cardinality_limit_mode, AbsoluteCardinalityLimit):\n            return metric_value <= self._cardinality_limit_mode.max_unique_values\n        elif isinstance(self._cardinality_limit_mode, RelativeCardinalityLimit):\n            return metric_value <= self._cardinality_limit_mode.max_proportion_unique\n\n    @staticmethod\n    def _validate_metric_value(metric_value: float) -> None:\n        if not isinstance(metric_value, (int, float)):\n            raise ProfilerConfigurationError(\n                f\"Value of measured cardinality must be of type int or float, you provided {type(metric_value)}\"\n            )\n\n        if metric_value < 0.00:\n            raise ProfilerConfigurationError(\n                f\"Value of cardinality (number of rows or percent unique) should be greater than 0.00, your value is {metric_value}\"\n            )\n\n    @staticmethod\n    def _convert_to_cardinality_limit_mode(\n        cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,\n        max_unique_values: Optional[int] = None,\n        max_proportion_unique: Optional[float] = None,\n    ) -> Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]:\n        validate_input_parameters(\n            cardinality_limit_mode=cardinality_limit_mode,\n            max_unique_values=max_unique_values,\n            max_proportion_unique=max_proportion_unique,\n        )\n\n        if cardinality_limit_mode is not None:\n            if isinstance(cardinality_limit_mode, str):\n                try:\n                    return CardinalityLimitMode[cardinality_limit_mode.upper()].value\n                except KeyError:\n                    raise ProfilerConfigurationError(\n                        f\"Please specify a supported cardinality mode. Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}\"\n                    )\n            elif isinstance(cardinality_limit_mode, dict):\n                validate_input_parameters(\n                    cardinality_limit_mode=cardinality_limit_mode.get(\"name\"),\n                    max_unique_values=cardinality_limit_mode.get(\"max_unique_values\"),\n                    max_proportion_unique=cardinality_limit_mode.get(\n                        \"max_proportion_unique\"\n                    ),\n                    required_num_supplied_params=2,\n                )\n                try:\n                    return AbsoluteCardinalityLimit(\n                        name=cardinality_limit_mode[\"name\"],\n                        max_unique_values=cardinality_limit_mode[\"max_unique_values\"],\n                        metric_name_defining_limit=cardinality_limit_mode[\n                            \"metric_name_defining_limit\"\n                        ],\n                    )\n                except (KeyError, ValueError):\n                    try:\n                        return RelativeCardinalityLimit(\n                            name=cardinality_limit_mode[\"name\"],\n                            max_proportion_unique=cardinality_limit_mode[\n                                \"max_proportion_unique\"\n                            ],\n                            metric_name_defining_limit=cardinality_limit_mode[\n                                \"metric_name_defining_limit\"\n                            ],\n                        )\n                    except (KeyError, ValueError):\n                        raise ProfilerConfigurationError(\n                            f\"Please specify a supported cardinality mode.  Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}\"\n                        )\n            else:\n                return cardinality_limit_mode.value\n\n        if max_unique_values is not None:\n            return AbsoluteCardinalityLimit(\n                name=f\"CUSTOM_ABS_{max_unique_values}\",\n                max_unique_values=max_unique_values,\n            )\n\n        if max_proportion_unique is not None:\n            return RelativeCardinalityLimit(\n                name=f\"CUSTOM_REL_{max_proportion_unique}\",\n                max_proportion_unique=max_proportion_unique,\n            )\n\n\ndef validate_input_parameters(\n    cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,\n    max_unique_values: Optional[int] = None,\n    max_proportion_unique: Optional[int] = None,\n    required_num_supplied_params: int = 1,\n) -> None:\n    num_supplied_params: int = sum(\n        [\n            0 if param is None else 1\n            for param in (\n                cardinality_limit_mode,\n                max_unique_values,\n                max_proportion_unique,\n            )\n        ]\n    )\n    if num_supplied_params != required_num_supplied_params:\n        raise ProfilerConfigurationError(\n            f\"Please pass ONE of the following parameters: cardinality_limit_mode, max_unique_values, max_proportion_unique, you passed {num_supplied_params} parameters.\"\n        )\n\n    if cardinality_limit_mode is not None:\n        if not isinstance(cardinality_limit_mode, (str, CardinalityLimitMode, dict)):\n            raise ProfilerConfigurationError(\n                f\"Please specify a supported cardinality limit type, supported classes are {','.join(CardinalityChecker.SUPPORTED_LIMIT_MODE_CLASS_NAMES)} and supported strings are {','.join(CardinalityChecker.SUPPORTED_CARDINALITY_LIMIT_MODE_STRINGS)}\"\n            )\n\n        if required_num_supplied_params == 2:\n            try:\n                return CardinalityLimitMode[cardinality_limit_mode.upper()].value\n            except KeyError:\n                raise ProfilerConfigurationError(\n                    f\"Please specify a supported cardinality mode. Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}\"\n                )\n\n    if max_unique_values is not None:\n        if not isinstance(max_unique_values, int):\n            raise ProfilerConfigurationError(\n                f\"Please specify an int, you specified a {type(max_unique_values)}\"\n            )\n\n    if max_proportion_unique is not None:\n        if not isinstance(max_proportion_unique, (float, int)):\n            raise ProfilerConfigurationError(\n                f\"Please specify a float or int, you specified a {type(max_proportion_unique)}\"\n            )\n", "path": "great_expectations/rule_based_profiler/helpers/cardinality_checker.py"}], "after_files": [{"content": "import abc\nimport enum\nfrom dataclasses import dataclass\nfrom typing import Optional, Tuple, Union, cast\n\nfrom great_expectations.core.util import convert_to_json_serializable\nfrom great_expectations.exceptions import ProfilerConfigurationError\nfrom great_expectations.types import SerializableDictDot\n\n\n@dataclass(frozen=True)\nclass CardinalityLimit(abc.ABC, SerializableDictDot):\n    name: str\n\n\n@dataclass(frozen=True)\nclass RelativeCardinalityLimit(CardinalityLimit):\n    max_proportion_unique: float\n    metric_name_defining_limit: str = \"column.unique_proportion\"\n\n    def to_json_dict(self) -> dict:\n        return convert_to_json_serializable(\n            {\n                \"name\": self.name,\n                \"max_proportion_unique\": self.max_proportion_unique,\n                \"metric_name_defining_limit\": self.metric_name_defining_limit,\n            }\n        )\n\n\n@dataclass(frozen=True)\nclass AbsoluteCardinalityLimit(CardinalityLimit):\n    max_unique_values: int\n    metric_name_defining_limit: str = \"column.distinct_values.count\"\n\n    def to_json_dict(self) -> dict:\n        return convert_to_json_serializable(\n            {\n                \"name\": self.name,\n                \"max_proportion_unique\": self.max_unique_values,\n                \"metric_name_defining_limit\": self.metric_name_defining_limit,\n            }\n        )\n\n\nclass CardinalityLimitMode(enum.Enum):\n    \"\"\"Preset limits based on unique values (cardinality)\n\n    Defines relative (ratio) and absolute number of records (table rows) that\n    correspond to each cardinality category.\n\n    Used to determine appropriate Expectation configurations based on data.\n    \"\"\"\n\n    ZERO = AbsoluteCardinalityLimit(\"ZERO\", 0)\n    ONE = AbsoluteCardinalityLimit(\"ONE\", 1)\n    TWO = AbsoluteCardinalityLimit(\"TWO\", 2)\n    VERY_FEW = AbsoluteCardinalityLimit(\"VERY_FEW\", 10)\n    FEW = AbsoluteCardinalityLimit(\"FEW\", 100)\n    SOME = AbsoluteCardinalityLimit(\"SOME\", 1000)\n    MANY = AbsoluteCardinalityLimit(\"MANY\", 10000)\n    VERY_MANY = AbsoluteCardinalityLimit(\"VERY_MANY\", 100000)\n    UNIQUE = RelativeCardinalityLimit(\"UNIQUE\", 1.0)\n    ABS_10 = AbsoluteCardinalityLimit(\"ABS_10\", 10)\n    ABS_100 = AbsoluteCardinalityLimit(\"ABS_100\", 100)\n    ABS_1000 = AbsoluteCardinalityLimit(\"ABS_1000\", 1000)\n    ABS_10_000 = AbsoluteCardinalityLimit(\"ABS_10_000\", int(1e4))\n    ABS_100_000 = AbsoluteCardinalityLimit(\"ABS_100_000\", int(1e5))\n    ABS_1_000_000 = AbsoluteCardinalityLimit(\"ABS_1_000_000\", int(1e6))\n    ABS_10_000_000 = AbsoluteCardinalityLimit(\"ABS_10_000_000\", int(1e7))\n    ABS_100_000_000 = AbsoluteCardinalityLimit(\"ABS_100_000_000\", int(1e8))\n    ABS_1_000_000_000 = AbsoluteCardinalityLimit(\"ABS_1_000_000_000\", int(1e9))\n    REL_0 = RelativeCardinalityLimit(\"REL_0\", 0.0)\n    REL_001 = RelativeCardinalityLimit(\"REL_001\", 1e-5)\n    REL_01 = RelativeCardinalityLimit(\"REL_01\", 1e-4)\n    REL_0_1 = RelativeCardinalityLimit(\"REL_0_1\", 1e-3)\n    REL_1 = RelativeCardinalityLimit(\"REL_1\", 1e-2)\n    REL_10 = RelativeCardinalityLimit(\"REL_10\", 0.10)\n    REL_25 = RelativeCardinalityLimit(\"REL_25\", 0.25)\n    REL_50 = RelativeCardinalityLimit(\"REL_50\", 0.50)\n    REL_75 = RelativeCardinalityLimit(\"REL_75\", 0.75)\n    REL_100 = RelativeCardinalityLimit(\"REL_100\", 1.0)\n    ONE_PCT = RelativeCardinalityLimit(\"ONE_PCT\", 0.01)\n    TEN_PCT = RelativeCardinalityLimit(\"TEN_PCT\", 0.10)\n\n\nclass CardinalityChecker:\n    \"\"\"Handles cardinality checking given cardinality limit mode and measured value.\n\n    This class also validates cardinality limit settings and converts from\n    various types of settings. You can choose one of the attributes listed\n    below to create an instance.\n\n    Attributes:\n        cardinality_limit_mode: CardinalityLimitMode or string name of the mode\n            defining the maximum allowable cardinality.\n        max_unique_values: number of max unique rows for a custom\n            cardinality limit.\n        max_proportion_unique: proportion of unique values for a\n            custom cardinality limit.\n    \"\"\"\n\n    SUPPORTED_CARDINALITY_LIMIT_MODE_CLASSES: Tuple[\n        Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]\n    ] = (\n        AbsoluteCardinalityLimit,\n        RelativeCardinalityLimit,\n    )\n    SUPPORTED_LIMIT_MODE_CLASS_NAMES: Tuple[str] = (\n        mode.__name__ for mode in SUPPORTED_CARDINALITY_LIMIT_MODE_CLASSES\n    )\n    SUPPORTED_CARDINALITY_LIMIT_MODE_STRINGS: Tuple[str] = (\n        mode.name for mode in CardinalityLimitMode\n    )\n\n    def __init__(\n        self,\n        cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,\n        max_unique_values: Optional[int] = None,\n        max_proportion_unique: Optional[float] = None,\n    ) -> None:\n        self._cardinality_limit_mode = self._convert_to_cardinality_limit_mode(\n            cardinality_limit_mode=cardinality_limit_mode,\n            max_unique_values=max_unique_values,\n            max_proportion_unique=max_proportion_unique,\n        )\n\n    @property\n    def cardinality_limit_mode(\n        self,\n    ) -> Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]:\n        return self._cardinality_limit_mode\n\n    def cardinality_within_limit(self, metric_value: float) -> bool:\n        \"\"\"Determine if the cardinality is within configured limit.\n\n        The metric_value supplied should be either a proportion of unique values\n        or number of unique values based on the configured cardinality limit.\n\n        Args:\n            metric_value: int if number of unique values, float if proportion\n                of unique values.\n\n        Returns:\n            Boolean of whether the cardinality is within the configured limit\n        \"\"\"\n        self._validate_metric_value(metric_value=metric_value)\n        if isinstance(self._cardinality_limit_mode, AbsoluteCardinalityLimit):\n            return metric_value <= self._cardinality_limit_mode.max_unique_values\n\n        if isinstance(self._cardinality_limit_mode, RelativeCardinalityLimit):\n            return metric_value <= self._cardinality_limit_mode.max_proportion_unique\n\n        raise ValueError(\n            f'Unknown \"cardinality_limit_mode\" mode \"{self._cardinality_limit_mode}\" encountered.'\n        )\n\n    @staticmethod\n    def _validate_metric_value(metric_value: float) -> None:\n        if not isinstance(metric_value, (int, float)):\n            raise ProfilerConfigurationError(\n                f\"Value of measured cardinality must be of type int or float, you provided {type(metric_value)}\"\n            )\n\n        if metric_value < 0.00:\n            raise ProfilerConfigurationError(\n                f\"Value of cardinality (number of rows or percent unique) should be greater than 0.00, your value is {metric_value}\"\n            )\n\n    @staticmethod\n    def _convert_to_cardinality_limit_mode(\n        cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,\n        max_unique_values: Optional[int] = None,\n        max_proportion_unique: Optional[float] = None,\n    ) -> Union[AbsoluteCardinalityLimit, RelativeCardinalityLimit]:\n        validate_input_parameters(\n            cardinality_limit_mode=cardinality_limit_mode,\n            max_unique_values=max_unique_values,\n            max_proportion_unique=max_proportion_unique,\n        )\n\n        if cardinality_limit_mode is not None:\n            if isinstance(cardinality_limit_mode, str):\n                try:\n                    return CardinalityLimitMode[cardinality_limit_mode.upper()].value\n                except KeyError:\n                    raise ProfilerConfigurationError(\n                        f\"Please specify a supported cardinality mode. Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}\"\n                    )\n            elif isinstance(cardinality_limit_mode, dict):\n                validate_input_parameters(\n                    cardinality_limit_mode=cardinality_limit_mode.get(\"name\"),\n                    max_unique_values=cardinality_limit_mode.get(\"max_unique_values\"),\n                    max_proportion_unique=cardinality_limit_mode.get(\n                        \"max_proportion_unique\"\n                    ),\n                    required_num_supplied_params=2,\n                )\n                try:\n                    return AbsoluteCardinalityLimit(\n                        name=cardinality_limit_mode[\"name\"],\n                        max_unique_values=cardinality_limit_mode[\"max_unique_values\"],\n                        metric_name_defining_limit=cardinality_limit_mode[\n                            \"metric_name_defining_limit\"\n                        ],\n                    )\n                except (KeyError, ValueError):\n                    try:\n                        return RelativeCardinalityLimit(\n                            name=cardinality_limit_mode[\"name\"],\n                            max_proportion_unique=cardinality_limit_mode[\n                                \"max_proportion_unique\"\n                            ],\n                            metric_name_defining_limit=cardinality_limit_mode[\n                                \"metric_name_defining_limit\"\n                            ],\n                        )\n                    except (KeyError, ValueError):\n                        raise ProfilerConfigurationError(\n                            f\"Please specify a supported cardinality mode.  Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}\"\n                        )\n            else:\n                return cast(CardinalityLimitMode, cardinality_limit_mode).value\n\n        if max_unique_values is not None:\n            return AbsoluteCardinalityLimit(\n                name=f\"CUSTOM_ABS_{max_unique_values}\",\n                max_unique_values=max_unique_values,\n            )\n\n        if max_proportion_unique is not None:\n            return RelativeCardinalityLimit(\n                name=f\"CUSTOM_REL_{max_proportion_unique}\",\n                max_proportion_unique=max_proportion_unique,\n            )\n\n\ndef validate_input_parameters(\n    cardinality_limit_mode: Optional[Union[str, CardinalityLimitMode, dict]] = None,\n    max_unique_values: Optional[int] = None,\n    max_proportion_unique: Optional[int] = None,\n    required_num_supplied_params: int = 1,\n) -> None:\n    num_supplied_params: int = sum(\n        [\n            0 if param is None else 1\n            for param in (\n                cardinality_limit_mode,\n                max_unique_values,\n                max_proportion_unique,\n            )\n        ]\n    )\n    if num_supplied_params != required_num_supplied_params:\n        raise ProfilerConfigurationError(\n            f\"Please pass ONE of the following parameters: cardinality_limit_mode, max_unique_values, max_proportion_unique, you passed {num_supplied_params} parameters.\"\n        )\n\n    if cardinality_limit_mode is not None:\n        if not isinstance(cardinality_limit_mode, (str, CardinalityLimitMode, dict)):\n            raise ProfilerConfigurationError(\n                f\"Please specify a supported cardinality limit type, supported classes are {','.join(CardinalityChecker.SUPPORTED_LIMIT_MODE_CLASS_NAMES)} and supported strings are {','.join(CardinalityChecker.SUPPORTED_CARDINALITY_LIMIT_MODE_STRINGS)}\"\n            )\n\n        if required_num_supplied_params == 2:\n            try:\n                return CardinalityLimitMode[cardinality_limit_mode.upper()].value\n            except KeyError:\n                raise ProfilerConfigurationError(\n                    f\"Please specify a supported cardinality mode. Supported cardinality modes are {[member.name for member in CardinalityLimitMode]}\"\n                )\n\n    if max_unique_values is not None:\n        if not isinstance(max_unique_values, int):\n            raise ProfilerConfigurationError(\n                f\"Please specify an int, you specified a {type(max_unique_values)}\"\n            )\n\n    if max_proportion_unique is not None:\n        if not isinstance(max_proportion_unique, (float, int)):\n            raise ProfilerConfigurationError(\n                f\"Please specify a float or int, you specified a {type(max_proportion_unique)}\"\n            )\n", "path": "great_expectations/rule_based_profiler/helpers/cardinality_checker.py"}]}