Skip to main content
Version: 1.2.4

Organize Expectations into an Expectation Suite

An Expectation Suite contains a group of Expectations that describe the same set of data. Combining all the Expectations that you apply to a given set of data into an Expectation Suite allows you to evaluate them as a group, rather than individually. All of the Expectations that you use to validate your data in production workflows should be grouped into Expectation Suites.

Prerequisites

Procedure

  1. Retrieve or create a Data Context.

    In this procedure, your Data Context is stored in the variable context. For information on creating or connecting to a Data Context see Create a Data Context.

  2. Create an Expectation Suite.

    To create a new Expectation Suite you will instantiate the ExpectationSuite class, which is available from the great_expectations module.

    Each Expectation Suite will require a unique name. In the following code update the variable suite_name with a a name relevant to your data. Then execute the code to create your Expectation Suite:

    Python input
    suite_name = "my_expectation_suite"
    suite = gx.ExpectationSuite(name=suite_name)
  3. Add the Expectation Suite to your Data Context

    Once you have finalized the contents of your Expectation Suite you should save it to your Data Context:

    Python input
    suite = context.suites.add(suite)

    With a File or GX Cloud Data Context your saved Expectation Suite will be available between Python sessions. You can retrieve your Expectation Suite from your Data Context with the following code:

    Python input
    existing_suite_name = (
    "my_expectation_suite" # replace this with the name of your Expectation Suite
    )
    suite = context.suites.get(name=existing_suite_name)
  4. Create an Expectation.

    In this procedure, your Expectation is stored in the variable expectation. For information on creating an Expectation see Create an Expectation.

  5. Add the Expectation to the Expectation Suite.

    An Expectation Suite's add_expectation(...) method takes in an instance of an Expectation and adds it to the Expectation Suite's configuraton:

    Python input
    suite.add_expectation(expectation)

    If you have a configured Data Source, Data Asset, and Batch Definition you can test your Expectation before adding it to your Expectation Suite. To do this see Test an Expectation.

    However, if you test and modify an Expectation after you have added it to your Expectation Suite you must explicitly save those modifications before they will be pushed to the Expectation Suite's configuration:

    Python input
    expectation.column = "pickup_location_id"
    expectation.save()

    Because the save() method of a modified Expectation updates its Expectation Suite's configuration, the save() method will only function if the Expectation Suite has been added to your Data Context.

  6. Continue to create and add additional Expectations

    Repeat the process of creating, testing, and adding Expectations to your Expectation Suite until the Expectation Suite adequately describes your data's ideal state.