Skip to content

Commit

Permalink
[DOCS] Revises the guidance under the 1.0 prerelease Manage Expectati…
Browse files Browse the repository at this point in the history
…on topic (#9639)
  • Loading branch information
Rachel-Reverie authored Mar 22, 2024
1 parent a17c71e commit 9422f0c
Show file tree
Hide file tree
Showing 21 changed files with 387 additions and 423 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import VersionedLink from '@site/src/components/VersionedLink';

<span><VersionedLink to='/core/installation_and_setup/manage_data_contexts#request-a-data-context'>Request a Data Context</VersionedLink></span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import VersionedLink from '@site/src/components/VersionedLink';

<span><VersionedLink to='/&path_without_extension$'>$Text$</VersionedLink></span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import VersionedLink from '@site/src/components/VersionedLink';

<span><VersionedLink to='/core/manage_and_access_data/connect_to_data'>A preconfigured Data Source and Data Asset connected to your data</VersionedLink></span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import VersionedLink from '@site/src/components/VersionedLink';

<span><VersionedLink to='/core/installation_and_setup/install_gx'>An installation of GX 1.0</VersionedLink></span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import VersionedLink from '@site/src/components/VersionedLink';

<span><VersionedLink to='/core/installation_and_setup/manage_data_contexts'>A preconfigured Data Context</VersionedLink></span>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VersionedLink from '@site/src/components/VersionedLink';
import GxData from '../../../components/_data.jsx';

<span><VersionedLink to='/core/installation_and_setup/set_up_a_python_environment'>An installation of Python, version {GxData.min_python} to {GxData.max_python}</VersionedLink>.</span>
<span><VersionedLink to='/core/installation_and_setup/set_up_a_python_environment'>An installation of Python, version {GxData.min_python} to {GxData.max_python}</VersionedLink></span>
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ import LinkCard from '@site/src/components/LinkCard';
to="/core/create_expectations/expectation_suites/manage_expectation_suites#get-an-existing-expectation-suite"
icon="/img/expectation_icon.svg"
/>
<LinkCard
topIcon
label="Rename an Expectation Suite"
description="Modify the name of a new or existing Expectation Suite and save the new value."
to="/core/create_expectations/expectation_suites/manage_expectation_suites#rename-an-expectation-suite"
icon="/img/expectation_icon.svg"
/>
<LinkCard
topIcon
label="Delete an Expectation Suite"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,26 @@
reviewing this script.
"""
# <snippet name="core/expectation_suites/_examples/add_expectations_to_an_expectation_suite.py full example code">
# 1. Import the GX Core library and `expectations` module.
# <snippet name="core/expectation_suites/_examples/add_expectations_to_an_expectation_suite.py imports">
import great_expectations as gx
import great_expectations.expectations as gxe

# </snippet>
# For this example to run as a stand alone script, we need to create
# the Expectation Suite that will later be retrieved and have Expectations
# added to it. This requires the import of the `ExpectationSuite` class.
from great_expectations.core.expectation_suite import ExpectationSuite

# 2. Get a Data Context
# <snippet name="core/expectation_suites/_examples/add_expectations_to_an_expectation_suite.py get_context">
context = gx.get_context()
# </snippet>

# 3. Create a new or retrieve an existing Expectation Suite
# This section adds a new Expectation Suite to the Data Context.
# Disregard this line if the Expectation Suite you are retrieving has already
# been added to your Data Context.
context.suites.add(ExpectationSuite(name="my_empty_expectation_suite"))
suite = context.suites.add(ExpectationSuite(name="my_expectation_suite"))

# To retrieve an existing suite, use the following:
# <snippet name="core/expectation_suites/_examples/add_expectations_to_an_expectation_suite.py get_suite">
existing_suite_name = (
"my_empty_expectation_suite" # replace this with the name of your Expectation Suite
)
suite = context.suites.get(name=existing_suite_name)
# </snippet>

# 4. Create an Expectation
# <snippet name="core/expectation_suites/_examples/add_expectations_to_an_expectation_suite.py create an Expectation">
expectation = gxe.ExpectColumnValuesToBeInSet(
column="passenger_count", value_set=[1, 2, 3, 4, 5]
)
# </snippet>

# 5. Add the Expectation to the Expectation Suite
# highlight-start
# <snippet name="core/expectation_suites/_examples/add_expectations_to_an_expectation_suite.py add an Expectation to an Expectation Suite">
suite.add_expectation(expectation)
# </snippet>
# highlight-end

# Tip: You can create an Expectation at the same time as you add it to an Expectation suite with:
# highlight-start
# <snippet name="core/expectation_suites/_examples/add_expectations_to_an_expectation_suite.py create and add an Expectation">
suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="pickup_datetime"))
# </snippet>
# highlight-end
# </snippet>
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@
reviewing this script.
"""
# <snippet name="core/expectation_suites/_examples/create_an_expectation_suite.py full example code">
# 1. Import the GX Core library and the `ExpectationSuite` class.
# <snippet name="core/expectation_suites/_examples/create_an_expectation_suite.py imports">
import great_expectations as gx
from great_expectations.core.expectation_suite import ExpectationSuite

# </snippet>

# 2. Get a Data Context
# <snippet name="core/expectation_suites/_examples/create_an_expectation_suite.py get_context">
context = gx.get_context()
# </snippet>

# 3. Create an Expectation Suite
# highlight-start
# <snippet name="core/expectation_suites/_examples/create_an_expectation_suite.py create Expectation Suite">
new_suite_name = "my_first_expectation_suite"
suite = ExpectationSuite(name=new_suite_name)
# </snippet>
# highlight-end

# 4. Add the Expectation Suite to the Data Context
# highlight-start
# <snippet name="core/expectation_suites/_examples/create_an_expectation_suite.py add snippet to Data Context">
suite = context.suites.add(suite)
# </snippet>
# highlight-end

# Tip: Create an Expectation Suite and add it to the Data Context at the same time
# highlight-start
# <snippet name="core/expectation_suites/_examples/create_an_expectation_suite.py create and add Expectation Suite to Data Context">
new_suite_name = "my_second_expectation_suite"
suite = context.suites.add(ExpectationSuite(name=new_suite_name))
# </snippet>
# </snippet>
# highlight-end
# </snippet>
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,30 @@
reviewing this script.
"""
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_in_an_expectation_suite.py full example code">

# 1. Import the Great Expectations library and `expectations` module.
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_in_an_expectation_suite.py imports">
import great_expectations as gx
import great_expectations.expectations as gxe

# </snippet>
# This section creates a new Expectation Suite and adds some Expectations to it.
# Later, the this Expectation Suite will be retrieved and the second
# Expectation will be deleted.
# Disregard this code if you are retrieving an existing Expectation Suite.
from great_expectations.core.expectation_suite import ExpectationSuite

new_suite = ExpectationSuite(name="my_expectation_suite")
new_suite.add_expectation(
gxe.ExpectColumnValuesToBeInSet(column="passenger_count", value_set=[1, 2, 3, 4, 5])
)
new_suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="pickup_datetime"))
new_suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="passenger_count"))

# 2. Get a Data Context
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_in_an_expectation_suite.py get context">
context = gx.get_context()
# </snippet>

# This section adds the Expectation Suite created earlier to the Data Context.
# Disregard this line if the Expectation Suite you are retrieving has already
# been added to your Data Context.
suite = context.suites.add(new_suite)

# 3. Get the Expectation Suite containing the Expectation to delete.
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_in_an_expectation_suite.py get Expectation Suite">
existing_suite_name = (
"my_expectation_suite" # replace this with the name of your Expectation Suite
suite = ExpectationSuite(name="my_expectation_suite")
suite.add_expectation(
gxe.ExpectColumnValuesToBeInSet(column="passenger_count", value_set=[1, 2, 3, 4, 5])
)
suite = context.suites.get(name=existing_suite_name)
# </snippet>
suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="pickup_datetime"))
suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="passenger_count"))
context.suites.add(suite)

# 4. Get the Expectation to delete.
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_in_an_expectation_suite.py get Expectation">
expectation_to_delete = next(
expectation
for expectation in suite.expectations
if isinstance(expectation, gxe.ExpectColumnValuesToNotBeNull)
and expectation.column == "pickup_datetime"
)
# </snippet>

# 5. Use the Expectation Suite to delete the Expectation.
# highlight-start
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_in_an_expectation_suite.py delete the Expectation">
suite.delete_expectation(expectation=expectation_to_delete)
# </snippet>
# highlight-end
# </snippet>
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,26 @@
reviewing this script.
"""
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_suite.py full example code">
# 1. Import the Great Expectations library
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_suite.py imports">
import great_expectations as gx

# </snippet>
# This section creates the Expectation Suite that will later be deleted.
# Disregard these lines if you are deleting an Expectation Suite that has
# already been created.
from great_expectations.core.expectation_suite import ExpectationSuite
context = gx.get_context()

new_suite_name = "my_deletable_expectation_suite"
new_suite = ExpectationSuite(name=new_suite_name)
context.suites.add(new_suite)

# 2. Get a Data Context
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_suite.py get_context">
context = gx.get_context()
# </snippet>

# This section adds the Expectation Suite created earlier to the Data Context.
# Disregard this line if the Expectation Suite you are deleting has already
# been added to your Data Context.
suite = context.suites.add(new_suite)

# 3. Get the Expectation Suite that will be deleted.
# highlight-start
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_suite.py get Expectation Suite">
suite_name = "my_deletable_expectation_suite"
suite = context.suites.get(suite_name)
# </snippet>
# highlight-end

# 4. Use the Data Context to delete the existing Expectation Suite.
# highlight-start
# <snippet name="core/expectation_suites/_examples/delete_an_expectation_suite.py delete Expectation Suite">
context.suites.delete(suite=suite)
# </snippet>
# highlight-end
# </snippet>

Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,43 @@
reviewing this script.
"""
# <snippet name="core/expectation_suites/_examples/edit_a_single_expectation.py full example code">
# The following sections set up an Expectation Suite with Expectations
# that can later be retrieved and edited as an example.
# <snippet name="core/expectation_suites/_examples/edit_a_single_expectation.py imports">
import great_expectations as gx
import great_expectations.expectations as gxe

# </snippet>
# This section creates a new Expectation Suite, which will later have Expectations
# added to it.
# Disregard this code if you are retrieving an existing Expectation Suite..
from great_expectations.core.expectation_suite import ExpectationSuite

# <snippet name="core/expectation_suites/_examples/edit_a_single_expectation.py get data context">
context = gx.get_context()
# </snippet>

new_suite_name = "my_empty_expectation_suite"
new_suite_name = "my_expectation_suite"
new_suite = ExpectationSuite(name=new_suite_name)
context.suites.add(new_suite)

# This section adds the Expectation Suite created earlier to the Data Context.
# Disregard this line if the Expectation Suite you are retrieving has already
# been added to your Data Context.
suite = context.suites.add(new_suite)

# This section adds some Expectations to the Expectations Suite.
# Later the second of these will be retrieved from the Expectation Suite and edited.
suite.add_expectation(
new_suite.add_expectation(
gxe.ExpectColumnValuesToBeInSet(column="passenger_count", value_set=[1, 2, 3, 4, 5])
)
suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="pickup_datetime"))
suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="passenger_count"))
new_suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="pickup_datetime"))
new_suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="passenger_count"))

# 1. Get the Expectation to edit from an Expectation Suite.
# <snippet name="core/expectation_suites/_examples/edit_a_single_expectation.py get expectation to edit">
existing_suite_name = (
"my_empty_expectation_suite" # replace this with the name of your Expectation Suite
"my_expectation_suite" # replace this with the name of your Expectation Suite
)
suite = context.suites.get(name=existing_suite_name)

expectation = next(
expectation
for expectation in suite.expectations
if isinstance(expectation, gxe.ExpectColumnValuesToNotBeNull)
and expectation.column == "pickup_datetime"
)
# </snippet>

# 2. Modify the Expectation's attributes.
# highlight-start
# <snippet name="core/expectation_suites/_examples/edit_a_single_expectation.py edit attribute">
expectation.column = "pickup_location_id"
# </snippet>
# highlight-end

# 3. Save the Expectation.
# highlight-start
# <snippet name="core/expectation_suites/_examples/edit_a_single_expectation.py save the Expectation">
expectation.save()
# </snippet>
# highlight-end
# </snippet>

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
reviewing this script.
"""
# <snippet name="core/expectation_suites/_examples/edit_all_expectations_in_an_expectation_suite.py full example code">
# 1. Get the Expectation Suite containing the Expectations to edit.
# <snippet name="core/expectation_suites/_examples/edit_all_expectations_in_an_expectation_suite.py create and populate Expectation Suite">
import great_expectations as gx
import great_expectations.expectations as gxe
from great_expectations.core.expectation_suite import ExpectationSuite
Expand All @@ -22,24 +20,17 @@
)
suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="pickup_datetime"))
suite.add_expectation(gxe.ExpectColumnValuesToNotBeNull(column="passenger_count"))
# </snippet>

# If you are editing an existing Expectation Suite, retrieve it with:
# <snippet name="core/expectation_suites/_examples/edit_all_expectations_in_an_expectation_suite.py get Expectation Suite">
existing_suite_name = (
"my_expectation_suite" # replace this with the name of your Expectation Suite
)
suite = context.suites.get(name=existing_suite_name)
# </snippet>

# 2. Iterate through the Expectation Suite's Expectations and modify their attributes.
# highlight-start
# <snippet name="core/expectation_suites/_examples/edit_all_expectations_in_an_expectation_suite.py modify Expectations">
for expectation in suite.expectations:
expectation.notes = "This Expectation was generated as part of GX Documentation."
# </snippet>
# highlight-end

# 3. Save the Expectation Suite and all modifications to the Expectations within it.
# highlight-start
# <snippet name="core/expectation_suites/_examples/edit_all_expectations_in_an_expectation_suite.py save Expectation Suite">
suite.save()
# </snippet>
# highlight-end
# </snippet>
Loading

0 comments on commit 9422f0c

Please sign in to comment.