Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINTENANCE] Remove DataContext dependency from ExpectationSuite #9512

Merged
merged 9 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions great_expectations/core/expectation_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

if TYPE_CHECKING:
from great_expectations.alias_types import JSONValues
from great_expectations.data_context import AbstractDataContext
from great_expectations.execution_engine import ExecutionEngine
from great_expectations.expectations.expectation import Expectation
from great_expectations.expectations.expectation_configuration import (
Expand All @@ -82,7 +81,6 @@ class ExpectationSuite(SerializableDictDot):
Args:
name: Name of the Expectation Suite
expectation_suite_name (deprecated): Name of the Expectation Suite.
data_context: Data Context associated with this Expectation Suite.
expectations: Expectation Configurations to associate with this Expectation Suite.
evaluation_parameters: Evaluation parameters to be substituted when evaluating Expectations.
data_asset_type: Type of data asset to associate with this suite.
Expand All @@ -94,7 +92,6 @@ class ExpectationSuite(SerializableDictDot):
def __init__( # noqa: PLR0913
self,
name: Optional[str] = None,
data_context: Optional[AbstractDataContext] = None,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not actually being used anywhere

expectations: Optional[
Sequence[Union[dict, ExpectationConfiguration, Expectation]]
] = None,
Expand All @@ -115,7 +112,6 @@ def __init__( # noqa: PLR0913
assert isinstance(expectation_suite_name, str), "Name is a required field."
self.name = expectation_suite_name
self.ge_cloud_id = ge_cloud_id
self._data_context = data_context

self.expectations = [
self._process_expectation(exp) for exp in expectations or []
Expand Down Expand Up @@ -380,9 +376,7 @@ def isEquivalentTo(self, other):
try:
# noinspection PyNoneFunctionAssignment,PyTypeChecker
other_dict: dict = expectationSuiteSchema.load(other)
other = ExpectationSuite(
**other_dict, data_context=self._data_context
)
other = ExpectationSuite(**other_dict)
except ValidationError:
logger.debug(
"Unable to evaluate equivalence of ExpectationConfiguration object with dict because "
Expand Down Expand Up @@ -439,8 +433,6 @@ def __deepcopy__(self, memo: dict):
for key in attributes_to_copy:
setattr(result, key, deepcopy(getattr(self, key), memo))

result._data_context = self._data_context

return result

@public_api
Expand Down
13 changes: 3 additions & 10 deletions great_expectations/data_asset/data_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ def _initialize_expectations(
expectation_suite_dict: dict = expectationSuiteSchema.load(
expectation_suite
)
expectation_suite = ExpectationSuite(
**expectation_suite_dict, data_context=self._data_context
)
expectation_suite = ExpectationSuite(**expectation_suite_dict)
else:
expectation_suite = copy.deepcopy(expectation_suite)

Expand All @@ -356,7 +354,6 @@ def _initialize_expectations(
expectation_suite_name = "default"
self._expectation_suite = ExpectationSuite(
expectation_suite_name=expectation_suite_name,
data_context=self._data_context,
)

self._expectation_suite.data_asset_type = self._data_asset_type
Expand Down Expand Up @@ -712,9 +709,7 @@ def validate( # noqa: C901, PLR0912, PLR0913, PLR0915
expectation_suite_dict: dict = expectationSuiteSchema.loads(
infile.read()
)
expectation_suite = ExpectationSuite(
**expectation_suite_dict, data_context=self._data_context
)
expectation_suite = ExpectationSuite(**expectation_suite_dict)
except ValidationError:
raise
except OSError:
Expand All @@ -723,9 +718,7 @@ def validate( # noqa: C901, PLR0912, PLR0913, PLR0915
)
elif isinstance(expectation_suite, dict):
expectation_suite_dict: dict = expectation_suite
expectation_suite = ExpectationSuite(
**expectation_suite_dict, data_context=None
)
expectation_suite = ExpectationSuite(**expectation_suite_dict)
elif not isinstance(expectation_suite, ExpectationSuite):
logger.error(
"Unable to validate using the provided value for expectation suite; does it need to be "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,6 @@ def _add_expectation_suite( # noqa: PLR0913

expectation_suite = ExpectationSuite(
expectation_suite_name=expectation_suite_name,
data_context=self,
ge_cloud_id=id,
expectations=expectations,
evaluation_parameters=evaluation_parameters,
Expand Down Expand Up @@ -2509,7 +2508,6 @@ def add_or_update_expectation_suite( # noqa: PLR0913

expectation_suite = ExpectationSuite(
expectation_suite_name=expectation_suite_name,
data_context=self,
ge_cloud_id=id,
expectations=expectations,
evaluation_parameters=evaluation_parameters,
Expand Down Expand Up @@ -2606,9 +2604,7 @@ def get_expectation_suite(
dict, self.expectations_store.get(key)
)
# create the ExpectationSuite from constructor
expectation_suite = ExpectationSuite(
**expectations_schema_dict, data_context=self
)
expectation_suite = ExpectationSuite(**expectations_schema_dict)
if include_rendered_content:
expectation_suite.render()
return expectation_suite
Expand Down Expand Up @@ -3793,9 +3789,7 @@ def _compile_evaluation_parameter_dependencies(self) -> None:
expectation_suite_dict: dict = cast(dict, self.expectations_store.get(key))
if not expectation_suite_dict:
continue
expectation_suite = ExpectationSuite(
**expectation_suite_dict, data_context=self
)
expectation_suite = ExpectationSuite(**expectation_suite_dict)

dependencies: dict = (
expectation_suite.get_evaluation_parameter_dependencies()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def create_expectation_suite(
raise ValueError("overwrite_existing must be of type bool.")

expectation_suite = ExpectationSuite(
expectation_suite_name=expectation_suite_name, data_context=self
expectation_suite_name=expectation_suite_name
)

existing_suite_names = self.list_expectation_suite_names()
Expand Down Expand Up @@ -707,9 +707,7 @@ def get_expectation_suite(
)

# create the ExpectationSuite from constructor
expectation_suite = ExpectationSuite(
**expectations_schema_dict, data_context=self
)
expectation_suite = ExpectationSuite(**expectations_schema_dict)
if include_rendered_content:
expectation_suite.render()
return expectation_suite
Expand Down
2 changes: 1 addition & 1 deletion great_expectations/profile/user_configurable_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def build_suite(self) -> ExpectationSuite:
self.profile_dataset._expectation_suite.expectation_suite_name # type: ignore[union-attr]
)
self.profile_dataset._expectation_suite = ExpectationSuite( # type: ignore[union-attr]
expectation_suite_name=suite_name, data_context=None
expectation_suite_name=suite_name
)

if self.semantic_types_dict:
Expand Down
4 changes: 1 addition & 3 deletions great_expectations/render/renderer/site_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@ def build(self, resource_identifiers=None) -> None: # noqa: PLR0912
try:
resource = self.source_store.get(resource_key)
if isinstance(resource_key, ExpectationSuiteIdentifier):
resource = ExpectationSuite(
**resource, data_context=self.data_context
)
resource = ExpectationSuite(**resource)
except exceptions.InvalidKeyError:
logger.warning(
f"Object with Key: {resource_key!s} could not be retrieved. Skipping..."
Expand Down
1 change: 0 additions & 1 deletion great_expectations/rule_based_profiler/helpers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,6 @@ def get_or_create_expectation_suite(
else:
expectation_suite = ExpectationSuite(
expectation_suite_name=expectation_suite_name,
data_context=data_context,
)

return expectation_suite
Expand Down
4 changes: 1 addition & 3 deletions great_expectations/self_check/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2260,9 +2260,7 @@ def evaluate_json_test_v3_api( # noqa: PLR0912, PLR0913
else:
_debug = lambda x: x # noqa: E731

expectation_suite = ExpectationSuite(
"json_test_suite", data_context=validator._data_context
)
expectation_suite = ExpectationSuite("json_test_suite")
# noinspection PyProtectedMember
validator._initialize_expectations(expectation_suite=expectation_suite)
# validator.set_default_expectation_argument("result_format", "COMPLETE")
Expand Down
7 changes: 2 additions & 5 deletions great_expectations/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,9 +1661,7 @@ def _initialize_expectations(
expectation_suite_dict: dict = expectationSuiteSchema.load(
expectation_suite
)
expectation_suite = ExpectationSuite(
**expectation_suite_dict, data_context=self._data_context
)
expectation_suite = ExpectationSuite(**expectation_suite_dict)
else:
expectation_suite = copy.deepcopy(expectation_suite)
self._expectation_suite: ExpectationSuite = expectation_suite
Expand All @@ -1685,8 +1683,7 @@ def _initialize_expectations(
if expectation_suite_name is None:
expectation_suite_name = "default"
self._expectation_suite = ExpectationSuite(
expectation_suite_name=expectation_suite_name,
data_context=self._data_context,
expectation_suite_name=expectation_suite_name
)

self._expectation_suite.execution_engine_type = type(self._execution_engine)
Expand Down
5 changes: 2 additions & 3 deletions tests/actions/test_validation_operators_in_data_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@


@pytest.fixture()
def parameterized_expectation_suite(empty_data_context_stats_enabled):
context = empty_data_context_stats_enabled
def parameterized_expectation_suite():
fixture_path = file_relative_path(
__file__,
"../test_fixtures/expectation_suites/parameterized_expression_expectation_suite_fixture.json",
Expand All @@ -22,7 +21,7 @@ def parameterized_expectation_suite(empty_data_context_stats_enabled):
fixture_path,
) as suite:
expectation_suite_dict: dict = expectationSuiteSchema.load(json.load(suite))
return ExpectationSuite(**expectation_suite_dict, data_context=context)
return ExpectationSuite(**expectation_suite_dict)


@pytest.fixture
Expand Down
8 changes: 3 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,7 @@ def spark_session_v012(test_backends):


@pytest.fixture
def basic_expectation_suite(empty_data_context_stats_enabled):
context = empty_data_context_stats_enabled
def basic_expectation_suite():
expectation_suite = ExpectationSuite(
expectation_suite_name="default",
meta={},
Expand All @@ -664,7 +663,6 @@ def basic_expectation_suite(empty_data_context_stats_enabled):
kwargs={"column": "naturals"},
),
],
data_context=context,
)
return expectation_suite

Expand Down Expand Up @@ -3747,7 +3745,7 @@ def populated_profiler_store(

@pytest.fixture
@freeze_time("09/26/2019 13:42:41")
def alice_columnar_table_single_batch(empty_data_context):
def alice_columnar_table_single_batch():
"""
About the "Alice" User Workflow Fixture

Expand Down Expand Up @@ -4002,7 +4000,7 @@ def alice_columnar_table_single_batch(empty_data_context):

expectation_suite_name: str = "alice_columnar_table_single_batch"
expected_expectation_suite = ExpectationSuite(
expectation_suite_name=expectation_suite_name, data_context=empty_data_context
expectation_suite_name=expectation_suite_name
)
expectation_configuration: ExpectationConfiguration
for expectation_configuration in expectation_configurations:
Expand Down
18 changes: 2 additions & 16 deletions tests/core/test_expectation_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def test_expectation_suite_init_defaults(self, fake_expectation_suite_name: str)
default_meta = {"great_expectations_version": ge_version}

assert suite.expectation_suite_name == fake_expectation_suite_name
assert suite._data_context is None
assert suite.expectations == []
assert suite.evaluation_parameters == {}
assert suite.data_asset_type is None
Expand All @@ -107,13 +106,9 @@ def test_expectation_suite_init_overrides(
fake_expectation_suite_name: str,
expect_column_values_to_be_in_set_col_a_with_meta: ExpectationConfiguration,
):
class DummyDataContext:
pass

class DummyExecutionEngine:
pass

dummy_data_context = DummyDataContext()
test_evaluation_parameters = {"$PARAMETER": "test_evaluation_parameters"}
test_data_asset_type = "test_data_asset_type"
dummy_execution_engine_type = type(DummyExecutionEngine())
Expand All @@ -124,7 +119,6 @@ class DummyExecutionEngine:

suite = ExpectationSuite(
expectation_suite_name=fake_expectation_suite_name,
data_context=dummy_data_context, # type: ignore[arg-type]
expectations=[expect_column_values_to_be_in_set_col_a_with_meta],
evaluation_parameters=test_evaluation_parameters,
data_asset_type=test_data_asset_type,
Expand All @@ -133,7 +127,6 @@ class DummyExecutionEngine:
ge_cloud_id=test_id,
)
assert suite.expectation_suite_name == fake_expectation_suite_name
assert suite._data_context == dummy_data_context
assert suite.expectation_configurations == [
expect_column_values_to_be_in_set_col_a_with_meta
]
Expand Down Expand Up @@ -1130,13 +1123,11 @@ def table_exp3() -> ExpectationConfiguration:


@pytest.fixture
def empty_suite(empty_data_context) -> ExpectationSuite:
context = empty_data_context
def empty_suite() -> ExpectationSuite:
return ExpectationSuite(
expectation_suite_name="warning",
expectations=[],
meta={"notes": "This is an expectation suite."},
data_context=context,
)


Expand All @@ -1150,9 +1141,7 @@ def suite_with_table_and_column_expectations(
table_exp1,
table_exp2,
table_exp3,
empty_data_context,
) -> ExpectationSuite:
context = empty_data_context
suite = ExpectationSuite(
expectation_suite_name="warning",
expectations=[
Expand All @@ -1166,21 +1155,18 @@ def suite_with_table_and_column_expectations(
table_exp3,
],
meta={"notes": "This is an expectation suite."},
data_context=context,
)
return suite


@pytest.fixture
def baseline_suite(
expect_column_values_to_be_in_set_col_a_with_meta, exp2, empty_data_context
expect_column_values_to_be_in_set_col_a_with_meta, exp2
) -> ExpectationSuite:
context = empty_data_context
return ExpectationSuite(
expectation_suite_name="warning",
expectations=[expect_column_values_to_be_in_set_col_a_with_meta, exp2],
meta={"notes": "This is an expectation suite."},
data_context=context,
)


Expand Down