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/expectations/metrics/map_metric_provider.py b/great_expectations/expectations/metrics/map_metric_provider.py
--- a/great_expectations/expectations/metrics/map_metric_provider.py
+++ b/great_expectations/expectations/metrics/map_metric_provider.py
@@ -1940,10 +1940,9 @@ def _sqlalchemy_map_condition_unexpected_count_value(
         else_=sa.sql.expression.cast(0, sa.Numeric),
     ).label("condition")
 
-    if MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
-        count_selectable: Select = sa.select([count_case_statement])
-    else:
-        count_selectable = sa.select([count_case_statement]).select_from(selectable)
+    count_selectable: Select = sa.select([count_case_statement])
+    if not MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
+        count_selectable = count_selectable.select_from(selectable)
 
     try:
         if execution_engine.engine.dialect.name.lower() == "mssql":
@@ -2030,16 +2029,11 @@ def _sqlalchemy_column_map_condition_values(
             message=f'Error: The column "{column_name}" in BatchData does not exist.'
         )
 
-    if MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
-        query = sa.select([sa.column(column_name).label("unexpected_values")]).where(
-            unexpected_condition
-        )
-    else:
-        query = (
-            sa.select([sa.column(column_name).label("unexpected_values")])
-            .where(unexpected_condition)
-            .select_from(selectable)
-        )
+    query = sa.select([sa.column(column_name).label("unexpected_values")]).where(
+        unexpected_condition
+    )
+    if not MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
+        query = query.select_from(selectable)
 
     result_format = metric_value_kwargs["result_format"]
     if result_format["result_format"] != "COMPLETE":
@@ -2087,20 +2081,12 @@ def _sqlalchemy_column_pair_map_condition_values(
                 message=f'Error: The column "{column_name}" in BatchData does not exist.'
             )
 
-    if MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
-        query = sa.select(
-            sa.column(column_A_name).label("unexpected_values_A"),
-            sa.column(column_B_name).label("unexpected_values_B"),
-        ).where(boolean_mapped_unexpected_values)
-    else:
-        query = (
-            sa.select(
-                sa.column(column_A_name).label("unexpected_values_A"),
-                sa.column(column_B_name).label("unexpected_values_B"),
-            )
-            .where(boolean_mapped_unexpected_values)
-            .select_from(selectable)
-        )
+    query = sa.select(
+        sa.column(column_A_name).label("unexpected_values_A"),
+        sa.column(column_B_name).label("unexpected_values_B"),
+    ).where(boolean_mapped_unexpected_values)
+    if not MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
+        query = query.select_from(selectable)
 
     result_format = metric_value_kwargs["result_format"]
     if result_format["result_format"] != "COMPLETE":
@@ -2190,14 +2176,9 @@ def _sqlalchemy_multicolumn_map_condition_values(
 
     column_selector = [sa.column(column_name) for column_name in column_list]
 
-    if MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
-        query = sa.select(column_selector).where(boolean_mapped_unexpected_values)
-    else:
-        query = (
-            sa.select(column_selector)
-            .where(boolean_mapped_unexpected_values)
-            .select_from(selectable)
-        )
+    query = sa.select(column_selector).where(boolean_mapped_unexpected_values)
+    if not MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
+        query = query.select_from(selectable)
 
     result_format = metric_value_kwargs["result_format"]
     if result_format["result_format"] != "COMPLETE":
@@ -2280,19 +2261,13 @@ def _sqlalchemy_column_map_condition_value_counts(
 
     column: sa.Column = sa.column(column_name)
 
-    if MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
-        query = (
-            sa.select([column, sa.func.count(column)])
-            .where(unexpected_condition)
-            .group_by(column)
-        )
-    else:
-        query = (
-            sa.select([column, sa.func.count(column)])
-            .where(unexpected_condition)
-            .group_by(column)
-            .select_from(selectable)
-        )
+    query = (
+        sa.select([column, sa.func.count(column)])
+        .where(unexpected_condition)
+        .group_by(column)
+    )
+    if not MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
+        query = query.select_from(selectable)
 
     return execution_engine.engine.execute(query).fetchall()
 
@@ -2323,14 +2298,9 @@ def _sqlalchemy_map_condition_rows(
 
     table_columns = metrics.get("table.columns")
     column_selector = [sa.column(column_name) for column_name in table_columns]
-    if MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
-        query = sa.select(column_selector).where(unexpected_condition)
-    else:
-        query = (
-            sa.select(column_selector)
-            .where(unexpected_condition)
-            .select_from(selectable)
-        )
+    query = sa.select(column_selector).where(unexpected_condition)
+    if not MapMetricProvider.is_sqlalchemy_metric_selectable(map_metric_provider=cls):
+        query = query.select_from(selectable)
 
     result_format = metric_value_kwargs["result_format"]
     if result_format["result_format"] != "COMPLETE":


Test patch: