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/self_check/util.py b/great_expectations/self_check/util.py
--- a/great_expectations/self_check/util.py
+++ b/great_expectations/self_check/util.py
@@ -22,7 +22,7 @@
     ExpectationSuiteValidationResultSchema,
     ExpectationValidationResultSchema,
 )
-from great_expectations.core.batch import Batch
+from great_expectations.core.batch import Batch, BatchDefinition
 from great_expectations.core.util import (
     get_or_create_spark_application,
     get_sql_dialect_floating_point_infinity_value,
@@ -795,13 +795,22 @@ def get_test_validator_with_data(
         raise ValueError("Unknown dataset_type " + str(execution_engine))
 
 
-def build_pandas_validator_with_data(df: pd.DataFrame) -> Validator:
-    batch: Batch = Batch(data=df)
+def build_pandas_validator_with_data(
+    df: pd.DataFrame,
+    batch_definition: Optional[BatchDefinition] = None,
+) -> Validator:
+    batch: Batch = Batch(data=df, batch_definition=batch_definition)
     return Validator(execution_engine=PandasExecutionEngine(), batches=(batch,))
 
 
 def build_sa_validator_with_data(
-    df, sa_engine_name, schemas=None, caching=True, table_name=None, sqlite_db_path=None
+    df,
+    sa_engine_name,
+    schemas=None,
+    caching=True,
+    table_name=None,
+    sqlite_db_path=None,
+    batch_definition: Optional[BatchDefinition] = None,
 ):
     dialect_classes = {
         "sqlite": sqlitetypes.dialect,
@@ -892,7 +901,7 @@ def build_sa_validator_with_data(
     )
 
     batch_data = SqlAlchemyBatchData(execution_engine=engine, table_name=table_name)
-    batch = Batch(data=batch_data)
+    batch = Batch(data=batch_data, batch_definition=batch_definition)
     execution_engine = SqlAlchemyExecutionEngine(caching=caching, engine=engine)
 
     return Validator(execution_engine=execution_engine, batches=(batch,))
@@ -917,7 +926,9 @@ def locale_wrapper(*args, **kwargs):
 
 
 def build_spark_validator_with_data(
-    df: Union[pd.DataFrame, SparkDataFrame], spark: SparkSession
+    df: Union[pd.DataFrame, SparkDataFrame],
+    spark: SparkSession,
+    batch_definition: Optional[BatchDefinition] = None,
 ) -> Validator:
     if isinstance(df, pd.DataFrame):
         df = spark.createDataFrame(
@@ -930,15 +941,20 @@ def build_spark_validator_with_data(
             ],
             df.columns.tolist(),
         )
-    batch: Batch = Batch(data=df)
+    batch: Batch = Batch(data=df, batch_definition=batch_definition)
     execution_engine: SparkDFExecutionEngine = build_spark_engine(
-        spark=spark, df=df, batch_id=batch.id
+        spark=spark,
+        df=df,
+        batch_id=batch.id,
     )
     return Validator(execution_engine=execution_engine, batches=(batch,))
 
 
-def build_pandas_engine(df: pd.DataFrame) -> PandasExecutionEngine:
+def build_pandas_engine(
+    df: pd.DataFrame,
+) -> PandasExecutionEngine:
     batch: Batch = Batch(data=df)
+
     execution_engine: PandasExecutionEngine = PandasExecutionEngine(
         batch_data_dict={batch.id: batch.data}
     )
@@ -983,8 +999,28 @@ def build_sa_engine(
 
 # Builds a Spark Execution Engine
 def build_spark_engine(
-    spark: SparkSession, df: Union[pd.DataFrame, SparkDataFrame], batch_id: str
+    spark: SparkSession,
+    df: Union[pd.DataFrame, SparkDataFrame],
+    batch_id: Optional[str] = None,
+    batch_definition: Optional[BatchDefinition] = None,
 ) -> SparkDFExecutionEngine:
+    if (
+        sum(
+            bool(x)
+            for x in [
+                batch_id is not None,
+                batch_definition is not None,
+            ]
+        )
+        != 1
+    ):
+        raise ValueError(
+            "Exactly one of batch_id or batch_definition must be specified."
+        )
+
+    if batch_id is None:
+        batch_id = batch_definition.id
+
     if isinstance(df, pd.DataFrame):
         df = spark.createDataFrame(
             [


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
@@ -1040,7 +1040,7 @@ def test_z_score_under_threshold_spark(spark_session):
     assert results[desired_metric.id] == 0
 
 
-def test_table_metric_pd():
+def test_table_metric_pd(caplog):
     df = pd.DataFrame({"a": [1, 2, 3, 3, None], "b": [1, 2, 3, 3, None]})
     engine = PandasExecutionEngine(batch_data_dict={"my_id": df})
     desired_metric = MetricConfiguration(
@@ -1050,6 +1050,10 @@ def test_table_metric_pd():
     )
     results = engine.resolve_metrics(metrics_to_resolve=(desired_metric,))
     assert results == {desired_metric.id: 5}
+    assert (
+        'Unexpected key(s) "column" found in domain_kwargs for domain type "table"'
+        in caplog.text
+    )
 
 
 def test_column_pairs_equal_metric_pd():