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/domain_builder/column_domain_builder.py b/great_expectations/rule_based_profiler/domain_builder/column_domain_builder.py
--- a/great_expectations/rule_based_profiler/domain_builder/column_domain_builder.py
+++ b/great_expectations/rule_based_profiler/domain_builder/column_domain_builder.py
@@ -407,7 +407,6 @@ def _get_domains(
             variables=variables,
         )
 
-        column_name: str
         domains: List[Domain] = build_domains_from_column_names(
             rule_name=rule_name,
             column_names=effective_column_names,


Test patch:
diff --git a/tests/expectations/metrics/test_metric_providers.py b/tests/expectations/metrics/test_metric_providers.py
--- a/tests/expectations/metrics/test_metric_providers.py
+++ b/tests/expectations/metrics/test_metric_providers.py
@@ -1,5 +1,10 @@
+from __future__ import annotations
+
+import copy
 from typing import Any, Dict, List
 
+import pytest
+
 from great_expectations.execution_engine import (
     PandasExecutionEngine,
     SparkDFExecutionEngine,
@@ -29,17 +34,27 @@
 from great_expectations.expectations.metrics.table_metric_provider import (
     TableMetricProvider,
 )
-from great_expectations.expectations.registry import (
-    _registered_metrics,
-)
+from great_expectations.expectations import registry
 
 
-def test__base_metric_provider__registration():
-    """This tests whether the MetricProvider class registers the correct metrics."""
+@pytest.fixture
+def mock_registry(monkeypatch: pytest.MonkeyPatch):
+    """Ensures consistent `_registered_metrics` state among test cases runs."""
+    monkeypatch.setattr(
+        registry,
+        "_registered_metrics",
+        copy.deepcopy(registry._registered_metrics),
+        raising=True,
+    )
+    yield registry
+
 
-    registered_metric_keys = list(_registered_metrics.keys())
+def test__base_metric_provider__registration(mock_registry):
+    """This tests whether the MetricProvider class registers the correct metrics."""
+    registered_metric_keys = list(mock_registry._registered_metrics.keys())
     for key in registered_metric_keys:
         assert "custom_metric" not in key
+
     prev_registered_metric_key_count = len(registered_metric_keys)
 
     class CustomMetricProvider(MetricProvider):
@@ -81,16 +96,19 @@ def _spark(
 
     CustomMetricProvider()
 
-    assert len(_registered_metrics.keys()) == prev_registered_metric_key_count + 1
-    assert "custom_metric" in _registered_metrics.keys()
+    assert (
+        len(mock_registry._registered_metrics.keys())
+        == prev_registered_metric_key_count + 1
+    )
+    assert "custom_metric" in mock_registry._registered_metrics.keys()
 
 
-def test__table_metric_provider__registration():
+def test__table_metric_provider__registration(mock_registry):
     """This tests whether the TableMetricProvider class registers the correct metrics."""
-
-    registered_metric_keys = list(_registered_metrics.keys())
+    registered_metric_keys = list(mock_registry._registered_metrics.keys())
     for key in registered_metric_keys:
         assert "table.custom_metric" not in key
+
     prev_registered_metric_key_count = len(registered_metric_keys)
 
     class CustomTableMetricProvider(TableMetricProvider):
@@ -131,21 +149,24 @@ def _spark(
 
     CustomTableMetricProvider()
 
-    assert len(_registered_metrics.keys()) == prev_registered_metric_key_count + 1
-    assert "table.custom_metric" in _registered_metrics.keys()
+    assert (
+        len(mock_registry._registered_metrics.keys())
+        == prev_registered_metric_key_count + 1
+    )
+    assert "table.custom_metric" in mock_registry._registered_metrics.keys()
 
 
-def test__column_map_metric__registration():
+def test__column_map_metric__registration(mock_registry):
     """This tests whether the ColumnMapMetricProvider class registers the correct metrics.
 
     The actual logic for this lives in the private method: `_register_metric_functions`, which is invoked from within `__new__` for the ancestor class `MetricProvider`.
 
     Since _register_metric_functions is private, we don't want to test it directly. Instead, we declare a custom ColumnMapMetricProvider, and test that the correct metrics are registered.
     """
-
-    registered_metric_keys = list(_registered_metrics.keys())
+    registered_metric_keys = list(mock_registry._registered_metrics.keys())
     for key in registered_metric_keys:
         assert "column_values.equal_seven" not in key
+
     prev_registered_metric_key_count = len(registered_metric_keys)
 
     class CustomColumnValuesEqualSeven(ColumnMapMetricProvider):
@@ -166,7 +187,10 @@ def _spark(cls, column, **kwargs):
 
     CustomColumnValuesEqualSeven()
 
-    assert len(_registered_metrics.keys()) == prev_registered_metric_key_count + 8
+    assert (
+        len(mock_registry._registered_metrics.keys())
+        == prev_registered_metric_key_count + 8
+    )
 
     new_keys = [
         "column_values.equal_seven.condition",
@@ -179,15 +203,15 @@ def _spark(cls, column, **kwargs):
         "column_values.equal_seven.unexpected_count.aggregate_fn",
     ]
     for key in new_keys:
-        assert key in _registered_metrics.keys()
+        assert key in mock_registry._registered_metrics.keys()
 
 
-def test__column_pair_map_metric__registration():
+def test__column_pair_map_metric__registration(mock_registry):
     """This tests whether the ColumnPairMapMetricProvider class registers the correct metrics."""
-
-    registered_metric_keys = list(_registered_metrics.keys())
+    registered_metric_keys = list(mock_registry._registered_metrics.keys())
     for key in registered_metric_keys:
         assert "column_pair_values.equal_seven" not in key
+
     prev_registered_metric_key_count = len(registered_metric_keys)
 
     class CustomColumnPairValuesEqualSeven(ColumnPairMapMetricProvider):
@@ -207,9 +231,12 @@ def _spark(cls, column_A, column_B, **kwargs):
 
     CustomColumnPairValuesEqualSeven()
 
-    assert len(_registered_metrics.keys()) == prev_registered_metric_key_count + 7
+    assert (
+        len(mock_registry._registered_metrics.keys())
+        == prev_registered_metric_key_count + 7
+    )
 
-    for key in _registered_metrics.keys():
+    for key in mock_registry._registered_metrics.keys():
         if "column_pair_values.equal_seven" in key:
             print(key)
 
@@ -223,15 +250,15 @@ def _spark(cls, column_A, column_B, **kwargs):
         "column_pair_values.equal_seven.filtered_row_count",
     ]
     for key in new_keys:
-        assert key in _registered_metrics.keys()
+        assert key in mock_registry._registered_metrics.keys()
 
 
-def test__multicolumn_map_metric__registration():
+def test__multicolumn_map_metric__registration(mock_registry):
     """This tests whether the MultiColumnMapMetricProvider class registers the correct metrics."""
-
-    registered_metric_keys = list(_registered_metrics.keys())
+    registered_metric_keys = list(mock_registry._registered_metrics.keys())
     for key in registered_metric_keys:
         assert "multicolumn_values.equal_seven" not in key
+
     prev_registered_metric_key_count = len(registered_metric_keys)
 
     class CustomMultiColumnValuesEqualSeven(MulticolumnMapMetricProvider):
@@ -261,7 +288,10 @@ def _spark(cls, column_list, **kwargs):
 
     CustomMultiColumnValuesEqualSeven()
 
-    assert len(_registered_metrics.keys()) == prev_registered_metric_key_count + 7
+    assert (
+        len(mock_registry._registered_metrics.keys())
+        == prev_registered_metric_key_count + 7
+    )
 
     new_keys = [
         "multicolumn_values.equal_seven.condition",
@@ -273,15 +303,15 @@ def _spark(cls, column_list, **kwargs):
         "multicolumn_values.equal_seven.filtered_row_count",
     ]
     for key in new_keys:
-        assert key in _registered_metrics.keys()
+        assert key in mock_registry._registered_metrics.keys()
 
 
-def test__query_metric_provider__registration():
+def test__query_metric_provider__registration(mock_registry):
     """This tests whether the QueryMetricProvider class registers the correct metrics."""
-
-    registered_metric_keys = list(_registered_metrics.keys())
+    registered_metric_keys = list(mock_registry._registered_metrics.keys())
     for key in registered_metric_keys:
         assert "query.custom_metric" not in key
+
     prev_registered_metric_key_count = len(registered_metric_keys)
 
     class CustomQueryMetricProvider(QueryMetricProvider):
@@ -311,5 +341,8 @@ def _spark(
 
     CustomQueryMetricProvider()
 
-    assert len(_registered_metrics.keys()) == prev_registered_metric_key_count + 1
-    assert "query.custom_metric" in _registered_metrics.keys()
+    assert (
+        len(mock_registry._registered_metrics.keys())
+        == prev_registered_metric_key_count + 1
+    )
+    assert "query.custom_metric" in mock_registry._registered_metrics.keys()