Get startedGet started for free

Create a Suite of Expectations

1. Create a Suite of Expectations

In real-world scenarios, validating data often requires multiple checks at once. For this reason, our Expectations should always be grouped into Expectation Suites.

2. Expectation Suites

An Expectation is a testable assumption about data, and these are grouped into Expectation Suites, which describe how a specific dataset should be validated.

3. Creating an Expectation Suite

To create an Expectation Suite, we can use the `ExpectationSuite` class, populating the `name` parameter with the desired name of our Expectation Suite. Notice here that we called the Python variable `suite`, while the `name` parameter is assigned the string `"my_suite"`.

4. Creating an Expectation Suite

When we print out the Expectation Suite object, we can see that it is essentially a dictionary that contains all of the metadata about our Expectation Suite, such as its name and a list of the Expectations it contains. Note that the latter is empty in this case, as we can tell by the empty list in the `"expectations"` field. This is because we haven't added any Expectations yet.

5. Adding Expectations

To add an Expectation, we use the Suite's `.add_expectation()` method, passing in our Expectation to the `expectation` parameter. Note that this method can only add one Expectation at a time.

6. Adding Expectations

Now when we print out our Expectation Suite, we see that the `"expectations"` field is populated. However, as we add more Expectations, this becomes hard to read.

7. Viewing an Expectation Suite

To view just a list of the Expectations in our Suite, we can use the `.expectations` attribute, or we can use the string `"expectations"` as a key. Both of these will produce the same output: a list of the Suite's Expectations with their associated metadata.

8. Viewing an Expectation Suite

We can access the other fields of our Expectation Suite too, either as attributes or keys. This applies to the name, ID, metadata, and notes of the Suite.

9. Validating an Expectation Suite

To validate an Expectation Suite, we can use the same `batch.validate()` method that we used to validate a single Expectation. We just set the `expect` parameter equal to our Expectation Suite. Let's take a look at our Validation Results.

10. Validating an Expectation Suite

Here are our Validation Results. Let's make them a bit easier to read.

11. Validating an Expectation Suite

Just like we did with single Expectations, we can use the `.success` attribute and `.describe()` method with these Validation Results as well.

12. Expectation Suite Validation Results

Notice that the format of the Validation Results differs slightly from when we validated a single Expectation. Now, we have an `"expectations"` field, which contains a list of the Validation Results of each Expectation in the Suite. Each item of this list looks like the Validation Results of a single Expectation. We also have a `"statistics"` field, which contains information on how many Expectations succeeded or failed. We can see here that there was one unsuccessful Expectation. Because at least one Expectation failed, the entire Suite failed. This is reflected in the `"success"` field at the top, which has a value of `false`.

13. Cheat sheet

Here is a summary of what we covered. Feel free to refer to this as you complete the exercises.

14. Let's practice!

Time to create your own Expectation Suite!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.