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_partition.py b/great_expectations/expectations/metrics/column_aggregate_metrics/column_partition.py
--- a/great_expectations/expectations/metrics/column_aggregate_metrics/column_partition.py
+++ b/great_expectations/expectations/metrics/column_aggregate_metrics/column_partition.py
@@ -36,7 +36,9 @@ def _pandas(
     ):
         bins = metric_value_kwargs.get("bins", cls.default_kwarg_values["bins"])
         n_bins = metric_value_kwargs.get("n_bins", cls.default_kwarg_values["n_bins"])
-        return _get_column_partition_using_metrics(bins, n_bins, metrics)
+        return _get_column_partition_using_metrics(
+            bins=bins, n_bins=n_bins, _metrics=metrics
+        )
 
     @metric_value(engine=SqlAlchemyExecutionEngine)
     def _sqlalchemy(
@@ -49,7 +51,9 @@ def _sqlalchemy(
     ):
         bins = metric_value_kwargs.get("bins", cls.default_kwarg_values["bins"])
         n_bins = metric_value_kwargs.get("n_bins", cls.default_kwarg_values["n_bins"])
-        return _get_column_partition_using_metrics(bins, n_bins, metrics)
+        return _get_column_partition_using_metrics(
+            bins=bins, n_bins=n_bins, _metrics=metrics
+        )
 
     @metric_value(engine=SparkDFExecutionEngine)
     def _spark(
@@ -62,7 +66,9 @@ def _spark(
     ):
         bins = metric_value_kwargs.get("bins", cls.default_kwarg_values["bins"])
         n_bins = metric_value_kwargs.get("n_bins", cls.default_kwarg_values["n_bins"])
-        return _get_column_partition_using_metrics(bins, n_bins, metrics)
+        return _get_column_partition_using_metrics(
+            bins=bins, n_bins=n_bins, _metrics=metrics
+        )
 
     @classmethod
     def _get_evaluation_dependencies(
@@ -122,7 +128,7 @@ def _get_evaluation_dependencies(
         return dependencies
 
 
-def _get_column_partition_using_metrics(bins, n_bins, _metrics):
+def _get_column_partition_using_metrics(bins: int, n_bins: int, _metrics: dict) -> list:
     if bins == "uniform":
         min_ = _metrics["column.min"]
         max_ = _metrics["column.max"]
@@ -135,14 +141,19 @@ def _get_column_partition_using_metrics(bins, n_bins, _metrics):
     elif bins == "auto":
         # Use the method from numpy histogram_bin_edges
         nonnull_count = _metrics["column_values.nonnull.count"]
-        sturges = np.log2(nonnull_count + 1)
+        sturges = np.log2(1.0 * nonnull_count + 1.0)
         min_, _25, _75, max_ = _metrics["column.quantile_values"]
         iqr = _75 - _25
         if iqr < 1.0e-10:  # Consider IQR 0 and do not use variance-based estimator
             n_bins = int(np.ceil(sturges))
         else:
-            fd = (2 * float(iqr)) / (nonnull_count ** (1 / 3))
-            n_bins = max(int(np.ceil(sturges)), int(np.ceil(float(max_ - min_) / fd)))
+            if nonnull_count == 0:
+                n_bins = 0
+            else:
+                fd = (2 * float(iqr)) / (nonnull_count ** (1.0 / 3.0))
+                n_bins = max(
+                    int(np.ceil(sturges)), int(np.ceil(float(max_ - min_) / fd))
+                )
 
         bins = np.linspace(start=float(min_), stop=float(max_), num=n_bins + 1).tolist()
     else:


Test patch: