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/examples/expectations/multicolumn_map_expectation_template.py b/examples/expectations/multicolumn_map_expectation_template.py
new file mode 100644
--- /dev/null
+++ b/examples/expectations/multicolumn_map_expectation_template.py
@@ -0,0 +1,132 @@
+"""
+This is a template for creating custom MulticolumnMapExpectations.
+For detailed instructions on how to use it, please see:
+    https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_multicolumn_map_expectations
+"""
+
+from typing import Optional
+
+from great_expectations.core.expectation_configuration import ExpectationConfiguration
+from great_expectations.exceptions import InvalidExpectationConfigurationError
+from great_expectations.execution_engine import (
+    PandasExecutionEngine,
+    SparkDFExecutionEngine,
+    SqlAlchemyExecutionEngine,
+)
+from great_expectations.expectations.expectation import MulticolumnMapExpectation
+from great_expectations.expectations.metrics.map_metric_provider import (
+    MulticolumnMapMetricProvider,
+    multicolumn_condition_partial,
+)
+
+
+# This class defines a Metric to support your Expectation.
+# For most MulticolumnMapExpectations, the main business logic for calculation will live in this class.
+# <snippet>
+class MulticolumnValuesMatchSomeCriteria(MulticolumnMapMetricProvider):
+    # </snippet>
+    # This is the id string that will be used to reference your metric.
+    # <snippet>
+    condition_metric_name = "METRIC NAME GOES HERE"
+    # </snippet>
+    # These point your metric at the provided keys to facilitate calculation
+    condition_domain_keys = (
+        "batch_id",
+        "table",
+        "column_list",
+        "row_condition",
+        "condition_parser",
+        "ignore_row_if",
+    )
+    condition_value_keys = ()
+
+    # This method implements the core logic for the PandasExecutionEngine
+    # <snippet>
+    @multicolumn_condition_partial(engine=PandasExecutionEngine)
+    def _pandas(cls, column_list, **kwargs):
+        raise NotImplementedError
+
+    # </snippet>
+
+    # This method defines the business logic for evaluating your metric when using a SqlAlchemyExecutionEngine
+    # @multicolumn_condition_partial(engine=SqlAlchemyExecutionEngine)
+    # def _sqlalchemy(cls, column_list, **kwargs):
+    #     raise NotImplementedError
+
+    # This method defines the business logic for evaluating your metric when using a SparkDFExecutionEngine
+    # @multicolumn_condition_partial(engine=SparkDFExecutionEngine)
+    # def _spark(cls, column_list, **kwargs):
+    #     raise NotImplementedError
+
+
+# This class defines the Expectation itself
+# <snippet>
+class ExpectMulticolumnValuesToMatchSomeCriteria(MulticolumnMapExpectation):
+    # </snippet>
+    # <snippet>
+    """TODO: Add a docstring here"""
+    # </snippet>
+
+    # These examples will be shown in the public gallery.
+    # They will also be executed as unit tests for your Expectation.
+    examples = []
+
+    # This is the id string of the Metric used by this Expectation.
+    # For most Expectations, it will be the same as the `condition_metric_name` defined in your Metric class above.
+    # <snippet>
+    map_metric = "METRIC NAME GOES HERE"
+    # </snippet>
+
+    # This is a list of parameter names that can affect whether the Expectation evaluates to True or False
+    success_keys = (
+        "column_list",
+        "mostly",
+    )
+
+    # This dictionary contains default values for any parameters that should have default values
+    default_kwarg_values = {}
+
+    def validate_configuration(
+        self, configuration: Optional[ExpectationConfiguration]
+    ) -> None:
+        """
+        Validates that a configuration has been set, and sets a configuration if it has yet to be set. Ensures that
+        necessary configuration arguments have been provided for the validation of the expectation.
+
+        Args:
+            configuration (OPTIONAL[ExpectationConfiguration]): \
+                An optional Expectation Configuration entry that will be used to configure the expectation
+        Returns:
+            None. Raises InvalidExpectationConfigurationError if the config is not validated successfully
+        """
+
+        super().validate_configuration(configuration)
+        if configuration is None:
+            configuration = self.configuration
+
+        # # Check other things in configuration.kwargs and raise Exceptions if needed
+        # try:
+        #     assert (
+        #         ...
+        #     ), "message"
+        #     assert (
+        #         ...
+        #     ), "message"
+        # except AssertionError as e:
+        #     raise InvalidExpectationConfigurationError(str(e))
+
+    # This object contains metadata for display in the public Gallery
+    # <snippet>
+    library_metadata = {
+        "tags": [],  # Tags for this Expectation in the Gallery
+        "contributors": [  # Github handles for all contributors to this Expectation.
+            "@your_name_here",  # Don't forget to add your github handle here!
+        ],
+    }
+    # </snippet>
+
+
+if __name__ == "__main__":
+    # <snippet>
+    ExpectMulticolumnValuesToMatchSomeCriteria().print_diagnostic_checklist()
+# </snippet>


Test patch:
diff --git a/tests/integration/docusaurus/expectations/creating_custom_expectations/expect_multicolumn_values_to_be_multiples_of_three.py b/tests/integration/docusaurus/expectations/creating_custom_expectations/expect_multicolumn_values_to_be_multiples_of_three.py
new file mode 100644
--- /dev/null
+++ b/tests/integration/docusaurus/expectations/creating_custom_expectations/expect_multicolumn_values_to_be_multiples_of_three.py
@@ -0,0 +1,164 @@
+from typing import Dict, Optional, Union
+
+from great_expectations.core.expectation_configuration import ExpectationConfiguration
+from great_expectations.exceptions.exceptions import (
+    InvalidExpectationConfigurationError,
+)
+from great_expectations.execution_engine import (
+    ExecutionEngine,
+    PandasExecutionEngine,
+    SparkDFExecutionEngine,
+    SqlAlchemyExecutionEngine,
+)
+from great_expectations.expectations.expectation import (
+    ExpectationValidationResult,
+    MulticolumnMapExpectation,
+)
+from great_expectations.expectations.metrics.import_manager import F, sa, sparktypes
+from great_expectations.expectations.metrics.map_metric_provider import (
+    MulticolumnMapMetricProvider,
+    multicolumn_condition_partial,
+)
+from great_expectations.validator.metric_configuration import MetricConfiguration
+
+
+# <snippet>
+class MulticolumnValuesMultipleThree(MulticolumnMapMetricProvider):
+    # </snippet>
+    """MetricProvider Class for Multicolumn Values Multiple Of Three MetricProvider"""
+
+    # <snippet>
+    condition_metric_name = "multicolumn_values.multiple_three"
+    # </snippet>
+    condition_domain_keys = ("column_list",)
+    condition_value_keys = ()
+    # <snippet>
+
+    @multicolumn_condition_partial(engine=PandasExecutionEngine)
+    def _pandas(cls, column_list, **kwargs):
+        return column_list.apply(lambda x: abs(x) % 3 == 0)
+
+    # </snippet>
+    @multicolumn_condition_partial(engine=SqlAlchemyExecutionEngine)
+    def _sqlalchemy(cls, column_list, **kwargs):
+        return sa.and_(sa.func.abs(x) % 3 == 0 for x in column_list)
+
+    @multicolumn_condition_partial(engine=SparkDFExecutionEngine)
+    def _spark(cls, column_list, **kwargs):
+        raise NotImplementedError
+
+
+# <snippet>
+class ExpectMulticolumnValuesToBeMultiplesOfThree(MulticolumnMapExpectation):
+    # </snippet>
+    # <snippet>
+    """Expect a set of columns to contain multiples of three."""
+    # </snippet>
+    # <snippet>
+    map_metric = "multicolumn_values.multiple_three"
+    # </snippet>
+    # These examples will be shown in the public gallery.
+    # They will also be executed as unit tests for your Expectation.
+    # <snippet>
+    examples = [
+        {
+            "data": {
+                "col_a": [3, 6, 9, 12, -3],
+                "col_b": [0, -3, 6, 33, -9],
+                "col_c": [1, 5, 6, 27, 3],
+                "col_d": [-2, 3, 21, 0, 1],
+            },
+            "tests": [
+                {
+                    "title": "basic_positive_test",
+                    "exact_match_out": False,
+                    "include_in_gallery": True,
+                    "in": {"column_list": ["col_a", "col_b", "col_c"], "mostly": 0.6},
+                    "out": {
+                        "success": True,
+                    },
+                },
+                {
+                    "title": "basic_negative_test",
+                    "exact_match_out": False,
+                    "include_in_gallery": True,
+                    "in": {"column_list": ["col_b", "col_c", "col_d"], "mostly": 0.5},
+                    "out": {
+                        "success": False,
+                    },
+                },
+            ],
+            "test_backends": [
+                {
+                    "backend": "pandas",
+                    "dialects": None,
+                },
+                {
+                    "backend": "sqlalchemy",
+                    "dialects": ["sqlite", "postgresql"],
+                },
+            ],
+        }
+    ]
+    # </snippet>
+    # Setting necessary computation metric dependencies and defining kwargs, as well as assigning kwargs default values
+    success_keys = (
+        "column_list",
+        "mostly",
+    )
+
+    default_kwarg_values = {
+        "row_condition": None,
+        "condition_parser": None,  # we expect this to be explicitly set whenever a row_condition is passed
+        "mostly": 1.0,
+        "result_format": "BASIC",
+        "include_config": True,
+        "catch_exceptions": False,
+    }
+    args_keys = ("column_list",)
+
+    def validate_configuration(
+        self, configuration: Optional[ExpectationConfiguration]
+    ) -> None:
+        super().validate_configuration(configuration)
+        if configuration is None:
+            configuration = self.configuration
+
+            try:
+                assert (
+                    "column_list" in configuration.kwargs
+                ), "column_list must be provided"
+            except AssertionError as e:
+                raise InvalidExpectationConfigurationError(str(e))
+
+    # This dictionary contains metadata for display in the public gallery
+    # <snippet>
+    library_metadata = {
+        "tags": [
+            "basic math",
+            "multi-column expectation",
+        ],
+        "contributors": ["@joegargery"],
+    }
+    # </snippet>
+
+
+if __name__ == "__main__":
+    # <snippet>
+    ExpectMulticolumnValuesToBeMultiplesOfThree().print_diagnostic_checklist()
+    # </snippet>
+# Note to users: code below this line is only for integration testing -- ignore!
+
+diagnostics = ExpectMulticolumnValuesToBeMultiplesOfThree().run_diagnostics()
+
+for check in diagnostics["tests"]:
+    assert check["test_passed"] is True
+    assert check["error_diagnostics"] is None
+
+for check in diagnostics["errors"]:
+    assert check is None
+
+for check in diagnostics["maturity_checklist"]["experimental"]:
+    if check["message"] == "Passes all linting checks":
+        continue
+    assert check["passed"] is True
diff --git a/tests/integration/test_script_runner.py b/tests/integration/test_script_runner.py
--- a/tests/integration/test_script_runner.py
+++ b/tests/integration/test_script_runner.py
@@ -320,6 +320,11 @@ class IntegrationTestFixture:
         user_flow_script="tests/integration/docusaurus/expectations/creating_custom_expectations/expect_queried_table_row_count_to_be.py",
         extra_backend_dependencies=BackendDependencies.SPARK,
     ),
+    IntegrationTestFixture(
+        name="expect_multicolumn_values_to_be_multiples_of_three",
+        user_flow_script="tests/integration/docusaurus/expectations/creating_custom_expectations/expect_multicolumn_values_to_be_multiples_of_three.py",
+        extra_backend_dependencies=BackendDependencies.POSTGRESQL,
+    ),
     IntegrationTestFixture(
         name="how_to_use_great_expectations_in_aws_glue",
         user_flow_script="tests/integration/docusaurus/deployment_patterns/aws_glue_deployment_patterns.py",