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/expectation.py b/great_expectations/expectations/expectation.py
--- a/great_expectations/expectations/expectation.py
+++ b/great_expectations/expectations/expectation.py
@@ -82,7 +82,7 @@
     evaluate_json_test_cfe,
     generate_expectation_tests,
 )
-from great_expectations.util import camel_to_snake, is_parseable_date, isclose
+from great_expectations.util import camel_to_snake, is_parseable_date
 from great_expectations.validator.metric_configuration import MetricConfiguration
 from great_expectations.validator.validator import Validator
 
@@ -97,10 +97,6 @@
 )
 
 
-RTOL: float = 1.0e-4
-ATOL: float = 1.0e-8
-
-
 # noinspection PyMethodParameters
 class MetaExpectation(ABCMeta):
     """MetaExpectation registers Expectations as they are defined, adding them to the Expectation registry.
@@ -1748,16 +1744,7 @@ def _validate_metric_value_between(
             if strict_min:
                 above_min = metric_value > min_value
             else:
-                # TODO: <Alex>Make "rtol" and "atol" customizable at "ExpectationConfiguration" level.</Alex>
-                above_min = (
-                    isclose(
-                        operand_a=metric_value,
-                        operand_b=min_value,
-                        rtol=RTOL,
-                        atol=ATOL,
-                    )
-                    or metric_value >= min_value
-                )
+                above_min = metric_value >= min_value
         else:
             above_min = True
 
@@ -1765,16 +1752,7 @@ def _validate_metric_value_between(
             if strict_max:
                 below_max = metric_value < max_value
             else:
-                # TODO: <Alex>Make "rtol" and "atol" customizable at "ExpectationConfiguration" level.</Alex>
-                below_max = (
-                    isclose(
-                        operand_a=metric_value,
-                        operand_b=min_value,
-                        rtol=RTOL,
-                        atol=ATOL,
-                    )
-                    or metric_value <= max_value
-                )
+                below_max = metric_value <= max_value
         else:
             below_max = True
 
diff --git a/great_expectations/expectations/metrics/column_map_metrics/column_values_between.py b/great_expectations/expectations/metrics/column_map_metrics/column_values_between.py
--- a/great_expectations/expectations/metrics/column_map_metrics/column_values_between.py
+++ b/great_expectations/expectations/metrics/column_map_metrics/column_values_between.py
@@ -8,13 +8,11 @@
     SparkDFExecutionEngine,
     SqlAlchemyExecutionEngine,
 )
-from great_expectations.expectations.expectation import ATOL, RTOL
 from great_expectations.expectations.metrics.import_manager import F, sa
 from great_expectations.expectations.metrics.map_metric_provider import (
     ColumnMapMetricProvider,
     column_condition_partial,
 )
-from great_expectations.util import isclose
 
 
 class ColumnValuesBetween(ColumnMapMetricProvider):
@@ -110,45 +108,11 @@ def is_between(val):
                     if strict_min and strict_max:
                         return (min_value < val) and (val < max_value)
                     elif strict_min:
-                        return (min_value < val) and (
-                            isclose(
-                                operand_a=val,
-                                operand_b=max_value,
-                                rtol=RTOL,
-                                atol=ATOL,
-                            )
-                            or (val <= max_value)
-                        )
+                        return (min_value < val) and (val <= max_value)
                     elif strict_max:
-                        # noinspection PyTypeChecker
-                        return (
-                            isclose(
-                                operand_a=val,
-                                operand_b=min_value,
-                                rtol=RTOL,
-                                atol=ATOL,
-                            )
-                            or (min_value <= val)
-                        ) and (val < max_value)
+                        return (min_value <= val) and (val < max_value)
                     else:
-                        # noinspection PyTypeChecker
-                        return (
-                            isclose(
-                                operand_a=val,
-                                operand_b=min_value,
-                                rtol=RTOL,
-                                atol=ATOL,
-                            )
-                            or (min_value <= val)
-                        ) and (
-                            isclose(
-                                operand_a=val,
-                                operand_b=max_value,
-                                rtol=RTOL,
-                                atol=ATOL,
-                            )
-                            or (val <= max_value)
-                        )
+                        return (min_value <= val) and (val <= max_value)
 
             elif min_value is None and max_value is not None:
                 if allow_cross_type_comparisons:
@@ -169,12 +133,7 @@ def is_between(val):
                     if strict_max:
                         return val < max_value
                     else:
-                        return isclose(
-                            operand_a=val,
-                            operand_b=max_value,
-                            rtol=RTOL,
-                            atol=ATOL,
-                        ) or (val <= max_value)
+                        return val <= max_value
 
             elif min_value is not None and max_value is None:
                 if allow_cross_type_comparisons:
@@ -195,13 +154,7 @@ def is_between(val):
                     if strict_min:
                         return min_value < val
                     else:
-                        # noinspection PyTypeChecker
-                        return isclose(
-                            operand_a=val,
-                            operand_b=min_value,
-                            rtol=RTOL,
-                            atol=ATOL,
-                        ) or (min_value <= val)
+                        return min_value <= val
 
             else:
                 return False
@@ -255,11 +208,7 @@ def _sqlalchemy(
             if isinstance(max_value, (str, datetime.datetime)):
                 return column <= sa.literal(max_value)
 
-            return sa.or_(
-                sa.func.abs(column - sa.literal(max_value))
-                <= sa.literal(ATOL + RTOL * abs(max_value)),
-                column <= sa.literal(max_value),
-            )
+            return column <= sa.literal(max_value)
 
         elif max_value is None:
             if strict_min:
@@ -268,11 +217,7 @@ def _sqlalchemy(
             if isinstance(min_value, (str, datetime.datetime)):
                 return column >= sa.literal(min_value)
 
-            return sa.or_(
-                sa.func.abs(sa.literal(min_value) - column)
-                <= ATOL + RTOL * sa.func.abs(column),
-                column >= sa.literal(min_value),
-            )
+            return column >= sa.literal(min_value)
 
         else:
             if strict_min and strict_max:
@@ -289,11 +234,7 @@ def _sqlalchemy(
 
                 return sa.and_(
                     sa.literal(min_value) < column,
-                    sa.or_(
-                        column <= sa.literal(max_value),
-                        sa.func.abs(column - sa.literal(max_value))
-                        <= sa.literal(ATOL + RTOL * abs(max_value)),
-                    ),
+                    column <= sa.literal(max_value),
                 )
 
             if strict_max:
@@ -305,11 +246,7 @@ def _sqlalchemy(
 
                 return sa.and_(
                     column < sa.literal(max_value),
-                    sa.or_(
-                        column >= sa.literal(min_value),
-                        sa.func.abs(sa.literal(min_value) - column)
-                        <= ATOL + RTOL * sa.func.abs(column),
-                    ),
+                    column >= sa.literal(min_value),
                 )
 
             if (isinstance(max_value, str) and isinstance(min_value, str)) or (
@@ -324,34 +261,18 @@ def _sqlalchemy(
             if isinstance(max_value, (str, datetime.datetime)):
                 return sa.and_(
                     column <= sa.literal(max_value),
-                    sa.or_(
-                        column >= sa.literal(min_value),
-                        sa.func.abs(sa.literal(min_value) - column)
-                        <= ATOL + RTOL * sa.func.abs(column),
-                    ),
+                    column >= sa.literal(min_value),
                 )
 
             if isinstance(min_value, (str, datetime.datetime)):
                 return sa.and_(
                     column >= sa.literal(min_value),
-                    sa.or_(
-                        column <= sa.literal(max_value),
-                        sa.func.abs(column - sa.literal(max_value))
-                        <= sa.literal(ATOL + RTOL * abs(max_value)),
-                    ),
+                    column <= sa.literal(max_value),
                 )
 
             return sa.and_(
-                sa.or_(
-                    column >= sa.literal(min_value),
-                    sa.func.abs(sa.literal(min_value) - column)
-                    <= ATOL + RTOL * sa.func.abs(column),
-                ),
-                sa.or_(
-                    column <= sa.literal(max_value),
-                    sa.func.abs(column - sa.literal(max_value))
-                    <= sa.literal(ATOL + RTOL * abs(max_value)),
-                ),
+                column >= sa.literal(min_value),
+                column <= sa.literal(max_value),
             )
 
     @column_condition_partial(engine=SparkDFExecutionEngine)
@@ -401,9 +322,7 @@ def _spark(
             if isinstance(max_value, (str, datetime.datetime)):
                 return column <= F.lit(max_value)
 
-            return (
-                F.abs(column - F.lit(max_value)) <= F.lit(ATOL + RTOL * abs(max_value))
-            ) | (column <= F.lit(max_value))
+            return column <= F.lit(max_value)
 
         elif max_value is None:
             if strict_min:
@@ -412,9 +331,7 @@ def _spark(
             if isinstance(min_value, (str, datetime.datetime)):
                 return F.lit(min_value) <= column
 
-            return (F.abs(F.lit(min_value) - column) <= ATOL + RTOL * F.abs(column)) | (
-                F.lit(min_value) <= column
-            )
+            return F.lit(min_value) <= column
 
         else:
             if strict_min and strict_max:
@@ -424,22 +341,13 @@ def _spark(
                 if isinstance(max_value, (str, datetime.datetime)):
                     return (F.lit(min_value) < column) & (column <= F.lit(max_value))
 
-                return (F.lit(min_value) < column) & (
-                    (
-                        F.abs(column - F.lit(max_value))
-                        <= F.lit(ATOL + RTOL * abs(max_value))
-                    )
-                    | (column <= F.lit(max_value))
-                )
+                return (F.lit(min_value) < column) & (column <= F.lit(max_value))
 
             if strict_max:
                 if isinstance(min_value, (str, datetime.datetime)):
                     return (F.lit(min_value) <= column) & (column < F.lit(max_value))
 
-                return (
-                    (F.abs(F.lit(min_value) - column) <= ATOL + RTOL * F.abs(column))
-                    | (F.lit(min_value) <= column)
-                ) & (column < F.lit(max_value))
+                return (F.lit(min_value) <= column) & (column < F.lit(max_value))
 
             if (isinstance(max_value, str) and isinstance(min_value, str)) or (
                 isinstance(max_value, datetime.datetime)
@@ -448,27 +356,9 @@ def _spark(
                 return (F.lit(min_value) <= column) & (column <= F.lit(max_value))
 
             if isinstance(max_value, (str, datetime.datetime)):
-                return (
-                    (F.abs(F.lit(min_value) - column) <= ATOL + RTOL * F.abs(column))
-                    | (F.lit(min_value) <= column)
-                ) & (column <= F.lit(max_value))
+                return (F.lit(min_value) <= column) & (column <= F.lit(max_value))
 
             if isinstance(min_value, (str, datetime.datetime)):
-                return (F.lit(min_value) <= column) & (
-                    (
-                        F.abs(column - F.lit(max_value))
-                        <= F.lit(ATOL + RTOL * abs(max_value))
-                    )
-                    | (column <= F.lit(max_value))
-                )
+                return (F.lit(min_value) <= column) & (column <= F.lit(max_value))
 
-            return (
-                (F.abs(F.lit(min_value) - column) <= ATOL + RTOL * F.abs(column))
-                | (F.lit(min_value) <= column)
-            ) & (
-                (
-                    F.abs(column - F.lit(max_value))
-                    <= F.lit(ATOL + RTOL * abs(max_value))
-                )
-                | (column <= F.lit(max_value))
-            )
+            return (F.lit(min_value) <= column) & (column <= F.lit(max_value))


Test patch: