Repository: great-expectations/great_expectations

Issue:
Use cleaner solution for non-truncating division in python 2
Prefer `from __future__ import division` to `1.*x/y`


Discussion:
Done inline during improve_partitions push.

Resolving patch:
diff --git a/great_expectations/rule_based_profiler/data_assistant/data_assistant.py b/great_expectations/rule_based_profiler/data_assistant/data_assistant.py
--- a/great_expectations/rule_based_profiler/data_assistant/data_assistant.py
+++ b/great_expectations/rule_based_profiler/data_assistant/data_assistant.py
@@ -4,7 +4,6 @@
 
 from great_expectations.core import ExpectationSuite
 from great_expectations.core.batch import Batch, BatchRequestBase
-from great_expectations.execution_engine.execution_engine import MetricDomainTypes
 from great_expectations.rule_based_profiler.domain_builder import DomainBuilder
 from great_expectations.rule_based_profiler.expectation_configuration_builder import (
     ExpectationConfigurationBuilder,
@@ -133,9 +132,10 @@ def _build_profiler(self) -> None:
         For each Self-Initializing "Expectation" as specified by "DataAssistant.expectation_kwargs_by_expectation_type"
         interface property, retrieve its "RuleBasedProfiler" configuration, construct "Rule" object based on it, while
         incorporating metrics "ParameterBuilder" objects for "MetricDomainTypes", emitted by "DomainBuilder"
-        of comprised "Rule", specified by "DataAssistant.metrics_parameter_builders_by_domain_type" interface property.
+        of comprised "Rule", specified by "DataAssistant.metrics_parameter_builders_by_domain" interface property.
         Append this "Rule" object to overall DataAssistant "RuleBasedProfiler" object; incorporate "variables" as well.
         """
+        expectation_type: str
         expectation_kwargs: Dict[str, Any]
         for (
             expectation_type,
@@ -150,8 +150,10 @@ def _build_profiler(self) -> None:
                 domain_builder = rule.domain_builder
                 parameter_builders = rule.parameter_builders or []
                 parameter_builders.extend(
-                    self.metrics_parameter_builders_by_domain_type[
-                        domain_builder.domain_type
+                    self.metrics_parameter_builders_by_domain[
+                        Domain(
+                            domain_builder.domain_type,
+                        )
                     ]
                 )
                 expectation_configuration_builders = (
@@ -243,9 +245,9 @@ def expectation_kwargs_by_expectation_type(self) -> Dict[str, Dict[str, Any]]:
 
     @property
     @abstractmethod
-    def metrics_parameter_builders_by_domain_type(
+    def metrics_parameter_builders_by_domain(
         self,
-    ) -> Dict[MetricDomainTypes, List[ParameterBuilder]]:
+    ) -> Dict[Domain, List[ParameterBuilder]]:
         """
         DataAssistant subclasses implement this method to return "ParameterBuilder" objects for "MetricDomainTypes", for
         every "Domain" type, for which generating metrics of interest is desired.  These metrics will be computed in
@@ -291,57 +293,61 @@ def _build_data_assistant_result(
         """
         pass
 
+    # noinspection PyShadowingNames
     def get_metrics_by_domain(self) -> Dict[Domain, Dict[str, ParameterNode]]:
         """
         Obtain subset of all parameter values for fully-qualified parameter names by domain, available from entire
-        "RuleBasedProfiler" state, where "Domain" types are among keys included in provisions as proscribed by return
-        value of "DataAssistant.metrics_parameter_builders_by_domain_type" interface property and actual fully-qualified
-        parameter names match interface properties of "ParameterBuilder" objects, corresponding to these "domain" types.
+        "RuleBasedProfiler" state, where "Domain" objects are among keys included in provisions as proscribed by return
+        value of "DataAssistant.metrics_parameter_builders_by_domain" interface property and fully-qualified parameter
+        names match interface properties of "ParameterBuilder" objects, corresponding to these "Domain" objects.
 
         Returns:
             Dictionaries of values for fully-qualified parameter names by Domain for metrics, from "RuleBasedpRofiler"
         """
+        domain_key: Domain
+
         # noinspection PyTypeChecker
         parameter_values_for_fully_qualified_parameter_names_by_domain: Dict[
             Domain, Dict[str, ParameterNode]
         ] = dict(
             filter(
-                lambda element: element[0].domain_type
-                in list(self.metrics_parameter_builders_by_domain_type.keys()),
+                lambda element: any(
+                    element[0].is_superset(other=domain_key)
+                    for domain_key in list(
+                        self.metrics_parameter_builders_by_domain.keys()
+                    )
+                ),
                 self.profiler.get_parameter_values_for_fully_qualified_parameter_names_by_domain().items(),
             )
         )
 
-        fully_qualified_metrics_parameter_names_by_domain_type: Dict[
-            MetricDomainTypes : List[str]
-        ] = {}
+        domain: Domain
 
-        domain_type: MetricDomainTypes
         parameter_builders: List[ParameterBuilder]
         parameter_builder: ParameterBuilder
-        for (
-            domain_type,
-            parameter_builders,
-        ) in self.metrics_parameter_builders_by_domain_type.items():
-            fully_qualified_metrics_parameter_names_by_domain_type[domain_type] = [
+        fully_qualified_metrics_parameter_names_by_domain: Dict[Domain, List[str]] = {
+            domain: [
                 parameter_builder.fully_qualified_parameter_name
                 for parameter_builder in parameter_builders
             ]
+            for domain, parameter_builders in self.metrics_parameter_builders_by_domain.items()
+        }
 
-        domain: Domain
         parameter_values_for_fully_qualified_parameter_names: Dict[str, ParameterNode]
+        fully_qualified_metrics_parameter_names: List[str]
+
         # noinspection PyTypeChecker
         parameter_values_for_fully_qualified_parameter_names_by_domain = {
             domain: dict(
                 filter(
                     lambda element: element[0]
-                    in fully_qualified_metrics_parameter_names_by_domain_type[
-                        domain.domain_type
-                    ],
+                    in fully_qualified_metrics_parameter_names_by_domain[domain_key],
                     parameter_values_for_fully_qualified_parameter_names.items(),
                 )
             )
+            for domain_key, fully_qualified_metrics_parameter_names in fully_qualified_metrics_parameter_names_by_domain.items()
             for domain, parameter_values_for_fully_qualified_parameter_names in parameter_values_for_fully_qualified_parameter_names_by_domain.items()
+            if domain.is_superset(domain_key)
         }
 
         return parameter_values_for_fully_qualified_parameter_names_by_domain
diff --git a/great_expectations/rule_based_profiler/data_assistant/volume_data_assistant.py b/great_expectations/rule_based_profiler/data_assistant/volume_data_assistant.py
--- a/great_expectations/rule_based_profiler/data_assistant/volume_data_assistant.py
+++ b/great_expectations/rule_based_profiler/data_assistant/volume_data_assistant.py
@@ -9,6 +9,7 @@
 from great_expectations.rule_based_profiler.rule import Rule
 from great_expectations.rule_based_profiler.types import (
     DOMAIN_KWARGS_PARAMETER_FULLY_QUALIFIED_NAME,
+    Domain,
 )
 from great_expectations.rule_based_profiler.types.data_assistant_result import (
     DataAssistantResult,
@@ -53,9 +54,9 @@ def expectation_kwargs_by_expectation_type(self) -> Dict[str, Dict[str, Any]]:
         }
 
     @property
-    def metrics_parameter_builders_by_domain_type(
+    def metrics_parameter_builders_by_domain(
         self,
-    ) -> Dict[MetricDomainTypes, List[ParameterBuilder]]:
+    ) -> Dict[Domain, List[ParameterBuilder]]:
         table_row_count_metric_multi_batch_parameter_builder: MetricMultiBatchParameterBuilder = MetricMultiBatchParameterBuilder(
             name="table_row_count",
             metric_name="table.row_count",
@@ -81,10 +82,10 @@ def metrics_parameter_builders_by_domain_type(
             data_context=None,
         )
         return {
-            MetricDomainTypes.TABLE: [
+            Domain(domain_type=MetricDomainTypes.TABLE,): [
                 table_row_count_metric_multi_batch_parameter_builder,
             ],
-            MetricDomainTypes.COLUMN: [
+            Domain(domain_type=MetricDomainTypes.COLUMN,): [
                 column_distinct_values_metric_multi_batch_parameter_builder,
             ],
         }


Test patch: