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/column_aggregate_metrics/column_histogram.py b/great_expectations/expectations/metrics/column_aggregate_metrics/column_histogram.py
--- a/great_expectations/expectations/metrics/column_aggregate_metrics/column_histogram.py
+++ b/great_expectations/expectations/metrics/column_aggregate_metrics/column_histogram.py
@@ -69,13 +69,38 @@ def _sqlalchemy(
         column = accessor_domain_kwargs["column"]
         bins = metric_value_kwargs["bins"]
 
-        case_conditions = []
         if isinstance(bins, np.ndarray):
             bins = bins.tolist()
         else:
             bins = list(bins)
 
-        if len(bins) == 1:
+        case_conditions = []
+        if len(bins) == 1 and not (
+            (
+                bins[0]
+                == get_sql_dialect_floating_point_infinity_value(
+                    schema="api_np", negative=True
+                )
+            )
+            or (
+                bins[0]
+                == get_sql_dialect_floating_point_infinity_value(
+                    schema="api_cast", negative=True
+                )
+            )
+            or (
+                bins[0]
+                == get_sql_dialect_floating_point_infinity_value(
+                    schema="api_np", negative=False
+                )
+            )
+            or (
+                bins[0]
+                == get_sql_dialect_floating_point_infinity_value(
+                    schema="api_cast", negative=False
+                )
+            )
+        ):
             # Single-valued column data are modeled using "impulse" (or "sample") distributions (on open interval).
             case_conditions.append(
                 sa.func.sum(
@@ -83,8 +108,10 @@ def _sqlalchemy(
                         [
                             (
                                 sa.and_(
-                                    bins[0] - np.finfo(float).eps < sa.column(column),
-                                    sa.column(column) < bins[0] + np.finfo(float).eps,
+                                    float(bins[0] - np.finfo(float).eps)
+                                    < sa.column(column),
+                                    sa.column(column)
+                                    < float(bins[0] + np.finfo(float).eps),
                                 ),
                                 1,
                             )
@@ -218,6 +245,7 @@ def _spark(
         bins = list(
             copy.deepcopy(bins)
         )  # take a copy since we are inserting and popping
+
         if bins[0] == -np.inf or bins[0] == -float("inf"):
             added_min = False
             bins[0] = -float("inf")


Test patch:
diff --git a/tests/expectations/metrics/test_core.py b/tests/expectations/metrics/test_core.py
--- a/tests/expectations/metrics/test_core.py
+++ b/tests/expectations/metrics/test_core.py
@@ -529,7 +529,24 @@ def test_quantiles_metric_spark(spark_session):
 
 
 def test_column_histogram_metric_pd():
-    engine = build_pandas_engine(pd.DataFrame({"a": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}))
+    engine = build_pandas_engine(
+        pd.DataFrame(
+            {
+                "a": [
+                    0,
+                    1,
+                    2,
+                    3,
+                    4,
+                    5,
+                    6,
+                    7,
+                    8,
+                    9,
+                ]
+            }
+        )
+    )
 
     metrics: dict = {}
 
@@ -557,7 +574,37 @@ def test_column_histogram_metric_pd():
 
 
 def test_column_histogram_metric_sa(sa):
-    engine = build_sa_engine(pd.DataFrame({"a": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}), sa)
+    engine = build_sa_engine(
+        pd.DataFrame(
+            {
+                "a": [
+                    0,
+                    1,
+                    2,
+                    3,
+                    4,
+                    5,
+                    6,
+                    7,
+                    8,
+                    9,
+                ],
+                "b": [
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                ],
+            }
+        ),
+        sa,
+    )
 
     metrics: dict = {}
 
@@ -583,11 +630,42 @@ def test_column_histogram_metric_sa(sa):
     metrics.update(results)
     assert results == {desired_metric.id: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}
 
+    desired_metric = MetricConfiguration(
+        metric_name="column.histogram",
+        metric_domain_kwargs={"column": "b"},
+        metric_value_kwargs={
+            "bins": [0.0],
+        },
+        metric_dependencies={
+            "table.columns": table_columns_metric,
+        },
+    )
+    results = engine.resolve_metrics(
+        metrics_to_resolve=(desired_metric,), metrics=metrics
+    )
+    metrics.update(results)
+    assert results == {desired_metric.id: [10]}
+
 
 def test_column_histogram_metric_spark(spark_session):
     engine: SparkDFExecutionEngine = build_spark_engine(
         spark=spark_session,
-        df=pd.DataFrame({"a": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}),
+        df=pd.DataFrame(
+            {
+                "a": [
+                    0,
+                    1,
+                    2,
+                    3,
+                    4,
+                    5,
+                    6,
+                    7,
+                    8,
+                    9,
+                ]
+            }
+        ),
         batch_id="my_id",
     )