Get startedGet started for free

Update Expectation Suites

1. Update Expectation Suites

Expectation Suites rarely stay the same forever. Usually, we either make a mistake creating an Expectation; or the nature of the data changes, so we need to change our Expectations. Now, we'll learn how to update our Expectation Suites.

2. Adding Expectations

Suppose we've created an Expectation that our DataFrame should have 10 columns and an Expectation Suite named "my_suite". As we've been practicing, we can add the Expectation to the Suite using the `.add_expectation()` method, and passing in our Expectation as a parameter.

3. Multiple Expectation Suites

Now, suppose we create another Expectation Suite, and we want to add our Expectation to that Suite, too. Well, we would get this error. This is basically telling us that we can't have the same Expectation in multiple Expectation Suites.

4. Copying Expectations

As the error suggests, one solution is to copy our Expectation to the new Suite. Luckily, the error gives us the directions on how to do so. To copy our Expectation, we use its `.copy()` method. We can set this copy equal to a new variable called, for example, `expectation_copy`. Then, as the error instructs, we have to set the `.id` attribute of the Expectation to `None`. Now we can add our Expectation to the new Suite without error.

5. Checking Expectations

To ensure that our Expectation was added successfully, we can just use regular Python syntax to check if the Expectation is in the Suite's list of Expectations. The expression evaluates to `True`, so we know our Expectation made it in there.

6. Deleting Expectations

Now suppose we want to delete an Expectation from an Expectation Suite. Deleting an Expectation is very similar to adding one. The only difference is we change the method name to `.delete_expectation()`. Just as with adding an Expectation, we pass in the Expectation object as an argument.

7. Adjusting Expectations

We can update the `value` keyword argument of our Expectation by accessing the `.value` attribute. Let's look back at our column count Expectation. Suppose we want to change the Expectation so that our column count should be 11, instead of 10. To do so, we reassign the `.value` attribute of the Expectation to 11. After we do this, we need to save our changes using the Expectation's `.save()` method. Now the changes we made to the Expectation are saved. Note that an Expectation can only be saved if it belongs to an Expectation Suite -- otherwise you'll get an error like this one.

8. Updating an Expectation Suite

Suppose we have a Validation Definition for our Expectation Suite, and we want to update our Expectation Suite and then run our Validation Definition. Let's define an Expectation, add it to our Suite, and run the Validation Definition.

9. Saving an Expectation Suite

We get an error -- how come? Well, just as we need to save an Expectation after modifying it, the same applies to Expectation Suites. Because we made a change to our Suite (by adding an Expectation), we need to save our changes before validating the Suite.

10. Saving an Expectation Suite

We save an Expectation Suite the same way we do an Expectation, using the `.save()` method. Now we can run our Validation Definition, and it completes without error.

11. Cheat sheet

Here is a recap of how to update Expectations and Expectation Suites. You can refer back to this as you complete the exercises.

12. Let's practice!

Time to practice modifying Expectation Suites!

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.