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/__init__.py b/great_expectations/rule_based_profiler/__init__.py
--- a/great_expectations/rule_based_profiler/__init__.py
+++ b/great_expectations/rule_based_profiler/__init__.py
@@ -1 +1 @@
-from .profiler import RuleBasedProfiler
+from .rule_based_profiler import RuleBasedProfiler
diff --git a/great_expectations/rule_based_profiler/profiler.py b/great_expectations/rule_based_profiler/rule_based_profiler.py
similarity index 88%
rename from great_expectations/rule_based_profiler/profiler.py
rename to great_expectations/rule_based_profiler/rule_based_profiler.py
--- a/great_expectations/rule_based_profiler/profiler.py
+++ b/great_expectations/rule_based_profiler/rule_based_profiler.py
@@ -7,12 +7,6 @@
 from great_expectations.core.expectation_configuration import ExpectationConfiguration
 from great_expectations.core.expectation_suite import ExpectationSuite
 from great_expectations.data_context.util import instantiate_class_from_config
-from great_expectations.rule_based_profiler.config.base import (
-    RuleConfig,
-    domainBuilderConfigSchema,
-    expectationConfigurationBuilderConfigSchema,
-    parameterBuilderConfigSchema,
-)
 from great_expectations.rule_based_profiler.domain_builder.domain_builder import (
     DomainBuilder,
 )
@@ -44,7 +38,7 @@ class RuleBasedProfiler:
         how_to_guide_url:
         maturity: Experimental
         maturity_details:
-            api_stability: Low (instantiation of Profiler and the signature of the profile() method will change)
+            api_stability: Low (instantiation of Profiler and the signature of the run() method will change)
             implementation_completeness: Moderate (some augmentation and/or growth in capabilities is to be expected)
             unit_test_coverage: High (but not complete -- additional unit tests will be added, commensurate with the upcoming new functionality)
             integration_infrastructure_test_coverage: N/A -> TBD
@@ -108,8 +102,8 @@ def __init__(
         *,
         name: str,
         config_version: float,
-        rules: Dict[str, RuleConfig],
         variables: Optional[Dict[str, Any]] = None,
+        rules: Dict[str, CommentedMap],
         data_context: Optional["DataContext"] = None,  # noqa: F821
     ):
         """
@@ -127,11 +121,14 @@ def __init__(
         """
         self._name = name
         self._config_version = config_version
-        self._data_context = data_context
         self._variables = variables or {}
-        self._rules = self._init_rules(rules, variables, data_context)
+        self._rules = self._init_rules(
+            rules=rules, variables=variables, data_context=data_context
+        )
+
+        self._data_context = data_context
 
-        # Necessary to annotate ExpectationSuite during `profile()`
+        # Necessary to annotate ExpectationSuite during `run()`
         self._citation = {
             "name": name,
             "config_version": config_version,
@@ -139,11 +136,11 @@ def __init__(
             "variables": variables,
         }
 
+    @staticmethod
     def _init_rules(
-        self,
-        rules: Dict[str, RuleConfig],
+        rules: Dict[str, CommentedMap],
         variables: Dict[str, Any],
-        data_context: Optional["DataContext"],
+        data_context: Optional["DataContext"] = None,  # noqa: F821
     ) -> List[Rule]:
         resulting_rules = []
         for rule_name, rule_config in rules.items():
@@ -158,12 +155,20 @@ def _init_rules(
                     )
 
             # Instantiate builder attributes
-            domain_builder = self._init_domain_builder(rule_config, data_context)
-            parameter_builders = self._init_parameter_builders(
-                rule_config, data_context
+            domain_builder = RuleBasedProfiler._init_domain_builder(
+                domain_builder_config=rule_config["domain_builder"],
+                data_context=data_context,
+            )
+            parameter_builders = RuleBasedProfiler._init_parameter_builders(
+                parameter_builder_configs=rule_config.get("parameter_builders"),
+                data_context=data_context,
             )
             expectation_configuration_builders = (
-                self._init_expectation_configuration_builders(rule_config, data_context)
+                RuleBasedProfiler._init_expectation_configuration_builders(
+                    expectation_configuration_builder_configs=rule_config[
+                        "expectation_configuration_builders"
+                    ]
+                )
             )
 
             # Convert variables to ParameterContainer
@@ -184,12 +189,11 @@ def _init_rules(
 
         return resulting_rules
 
+    @staticmethod
     def _init_domain_builder(
-        self,
-        rule_config: CommentedMap,
-        data_context: Optional["DataContext"],  # noqa: F821
+        domain_builder_config: CommentedMap,
+        data_context: Optional["DataContext"] = None,  # noqa: F821
     ) -> DomainBuilder:
-        domain_builder_config: CommentedMap = rule_config["domain_builder"]
         domain_builder: DomainBuilder = instantiate_class_from_config(
             config=domain_builder_config,
             runtime_environment={"data_context": data_context},
@@ -200,16 +204,15 @@ def _init_domain_builder(
 
         return domain_builder
 
+    @staticmethod
     def _init_parameter_builders(
-        self,
-        rule_config: CommentedMap,
-        data_context: Optional["DataContext"],  # noqa: F821
+        parameter_builder_configs: Optional[List[CommentedMap]] = None,
+        data_context: Optional["DataContext"] = None,  # noqa: F821
     ) -> List[ParameterBuilder]:
-        parameter_builders: List[ParameterBuilder] = []
-        parameter_builder_configs: List[CommentedMap] = rule_config.get(
-            "parameter_builders", []
-        )
+        if parameter_builder_configs is None:
+            parameter_builder_configs = []
 
+        parameter_builders: List[ParameterBuilder] = []
         for parameter_builder_config in parameter_builder_configs:
             parameter_builder = instantiate_class_from_config(
                 config=parameter_builder_config,
@@ -222,16 +225,11 @@ def _init_parameter_builders(
 
         return parameter_builders
 
+    @staticmethod
     def _init_expectation_configuration_builders(
-        self,
-        rule_config: CommentedMap,
-        data_context: Optional["DataContext"],  # noqa: F821
+        expectation_configuration_builder_configs: List[CommentedMap],
     ) -> List[ExpectationConfigurationBuilder]:
         expectation_configuration_builders: List[ExpectationConfigurationBuilder] = []
-        expectation_configuration_builder_configs: List[CommentedMap] = rule_config[
-            "expectation_configuration_builders"
-        ]
-
         for (
             expectation_configuration_builder_config
         ) in expectation_configuration_builder_configs:
@@ -247,7 +245,7 @@ def _init_expectation_configuration_builders(
 
         return expectation_configuration_builders
 
-    def profile(
+    def run(
         self,
         *,
         expectation_suite_name: Optional[str] = None,


Test patch:
diff --git a/tests/integration/docusaurus/expectations/advanced/multi_batch_rule_based_profiler_example.py b/tests/integration/docusaurus/expectations/advanced/multi_batch_rule_based_profiler_example.py
--- a/tests/integration/docusaurus/expectations/advanced/multi_batch_rule_based_profiler_example.py
+++ b/tests/integration/docusaurus/expectations/advanced/multi_batch_rule_based_profiler_example.py
@@ -1,7 +1,7 @@
 from ruamel import yaml
 
 from great_expectations import DataContext
-from great_expectations.rule_based_profiler.profiler import Profiler
+from great_expectations.rule_based_profiler.rule_based_profiler import RuleBasedProfiler
 
 profiler_config = """
 # This profiler is meant to be used on the NYC taxi data (yellow_tripdata_sample_<YEAR>-<MONTH>.csv)
@@ -99,14 +99,17 @@
 
 data_context = DataContext()
 
-# Instantiate Profiler
+# Instantiate RuleBasedProfiler
 full_profiler_config_dict: dict = yaml.load(profiler_config)
-profiler: Profiler = Profiler(
-    profiler_config=full_profiler_config_dict,
+rule_based_profiler: RuleBasedProfiler = RuleBasedProfiler(
+    name=full_profiler_config_dict["name"],
+    config_version=full_profiler_config_dict["config_version"],
+    rules=full_profiler_config_dict["rules"],
+    variables=full_profiler_config_dict["variables"],
     data_context=data_context,
 )
 
-suite = profiler.profile(expectation_suite_name="test_suite_name")
+suite = rule_based_profiler.run(expectation_suite_name="test_suite_name")
 print(suite)
 
 # Please note that this docstring is here to demonstrate output for docs. It is not needed for normal use.
diff --git a/tests/rule_based_profiler/alpha/test_profiler_user_workflows.py b/tests/rule_based_profiler/alpha/test_profiler_user_workflows.py
--- a/tests/rule_based_profiler/alpha/test_profiler_user_workflows.py
+++ b/tests/rule_based_profiler/alpha/test_profiler_user_workflows.py
@@ -12,7 +12,7 @@
 from great_expectations.core import ExpectationSuite
 from great_expectations.core.batch import BatchRequest
 from great_expectations.datasource import DataConnector, Datasource
-from great_expectations.rule_based_profiler.profiler import RuleBasedProfiler
+from great_expectations.rule_based_profiler.rule_based_profiler import RuleBasedProfiler
 from great_expectations.validator.metric_configuration import MetricConfiguration
 from great_expectations.validator.validator import Validator
 
@@ -91,7 +91,7 @@ def test_alice_profiler_user_workflow_single_batch(
         data_context=data_context,
     )
 
-    expectation_suite: ExpectationSuite = profiler.profile(
+    expectation_suite: ExpectationSuite = profiler.run(
         expectation_suite_name=alice_columnar_table_single_batch[
             "expected_expectation_suite_name"
         ],
@@ -104,6 +104,7 @@ def test_alice_profiler_user_workflow_single_batch(
     )
 
 
+# noinspection PyUnusedLocal
 def test_bobby_columnar_table_multi_batch_batches_are_accessible(
     monkeypatch,
     bobby_columnar_table_multi_batch_deterministic_data_context,
@@ -200,7 +201,7 @@ def test_bobby_profiler_user_workflow_multi_batch_row_count_range_rule_and_colum
         data_context=data_context,
     )
 
-    expectation_suite: ExpectationSuite = profiler.profile(
+    expectation_suite: ExpectationSuite = profiler.run(
         expectation_suite_name=bobby_columnar_table_multi_batch[
             "test_configuration_oneshot_sampling_method"
         ]["expectation_suite_name"],
@@ -244,7 +245,7 @@ def test_bobster_profiler_user_workflow_multi_batch_row_count_range_rule_bootstr
         data_context=data_context,
     )
 
-    expectation_suite: ExpectationSuite = profiler.profile(
+    expectation_suite: ExpectationSuite = profiler.run(
         expectation_suite_name=bobster_columnar_table_multi_batch_normal_mean_5000_stdev_1000[
             "test_configuration_bootstrap_sampling_method"
         ][
diff --git a/tests/rule_based_profiler/alpha/test_profiler.py b/tests/rule_based_profiler/alpha/test_rule_based_profiler.py
similarity index 95%
rename from tests/rule_based_profiler/alpha/test_profiler.py
rename to tests/rule_based_profiler/alpha/test_rule_based_profiler.py
--- a/tests/rule_based_profiler/alpha/test_profiler.py
+++ b/tests/rule_based_profiler/alpha/test_rule_based_profiler.py
@@ -5,8 +5,7 @@
 from great_expectations import DataContext
 from great_expectations.core import ExpectationSuite
 from great_expectations.core.batch import BatchRequest
-from great_expectations.rule_based_profiler.config.base import RuleBasedProfilerConfig
-from great_expectations.rule_based_profiler.profiler import RuleBasedProfiler
+from great_expectations.rule_based_profiler.rule_based_profiler import RuleBasedProfiler
 from great_expectations.validator.metric_configuration import MetricConfiguration
 
 yaml = YAML()
@@ -143,7 +142,7 @@ def test_profile_includes_citations(
         data_context=data_context,
     )
 
-    expectation_suite: ExpectationSuite = profiler.profile(
+    expectation_suite: ExpectationSuite = profiler.run(
         expectation_suite_name=alice_columnar_table_single_batch[
             "expected_expectation_suite_name"
         ],
@@ -173,7 +172,7 @@ def test_profile_excludes_citations(
         data_context=data_context,
     )
 
-    expectation_suite: ExpectationSuite = profiler.profile(
+    expectation_suite: ExpectationSuite = profiler.run(
         expectation_suite_name=alice_columnar_table_single_batch[
             "expected_expectation_suite_name"
         ],