Manage Components

Introduction to Data Quality with Great Expectations

Davina Moossazadeh

Data Scientist

Components

GX components - Python classes that represent data and data validation entities

  • Data Context
  • Data Sources & Data Assets
  • Batch Definitions & Batches
  • Expectations
  • Expectation Suites
  • Validation Definitions
  • Checkpoints & Actions
  • Data Docs
1 https://docs.greatexpectations.io/docs/core/introduction/gx_overview
Introduction to Data Quality with Great Expectations

Component management in GX

Data Sources:

  • connect to data and contain Data Assets

Expectation Suites:

  • house Expectations

Validation Definitions:

  • validate Expectations against data

Checkpoints:

  • group and automate Validations

context.data_sources

$$

context.suites

$$

context.validation_definitions

$$

context.checkpoints

Introduction to Data Quality with Great Expectations

Adding components

Expectation Suite:

suite = context.suites.add(suite)

Validation Definition:

validation_definition = context.validation_definitions.add(validation_definition)

Checkpoint:

checkpoint = context.checkpoints.add(
    checkpoint=checkpoint
)
Introduction to Data Quality with Great Expectations

Adding a Data Source

data_source = context.data_sources.add_<TYPE_NAME>()

1 https://docs.greatexpectations.io/docs/core/connect_to_data/
Introduction to Data Quality with Great Expectations

Adding a pandas Data Source

Use .add_pandas() to easily set up a Data Source for pandas DataFrames:

data_source = context.data_sources.add_pandas(
    name="my_pandas_datasource"
)
Introduction to Data Quality with Great Expectations

Retrieving components

Retrieve components with .get() by specifying their name parameter:

context.<COMPONENT>s.get(

name: str )
data_source = context.data_sources.get(

name="my_pandas_datasource" )
print(data_source)
id: 46c91f1b-1db9-4351-b5dd-83e038c0f511
name: 'my_pandas_datasource'
type: pandas
Introduction to Data Quality with Great Expectations

Retrieving components

Data Sources:

context.data_sources.get(
    name="my_pandas_datasource"
)

Expectation Suites:

context.suites.get(
    name="my_suite"
)

Validation Definitions:

context.validation_definitions.get(
    name="my_validation_definition"
)

Checkpoints:

context.checkpoints.get(
    name="my_checkpoint"
)
Introduction to Data Quality with Great Expectations

Listing components

Use .all() to list all components in your Data Context, including their names and metadata:

context.<COMPONENT>s.all()
data_sources = context.data_sources.all()

print(data_sources)
{
    'my_pandas_datasource': PandasDatasource(
        type='pandas',
        name='my_pandas_datasource', 
        id=UUID('c22b16f7-6945-400e-932f-026cbd63b112'), 
        assets=[]
    )
}
Introduction to Data Quality with Great Expectations

Listing components

Data Sources:

context.data_sources.all()

Expectation Suites:

context.suites.all()

Validation Definitions:

context.validation_definitions.all()

Checkpoints:

context.checkpoints.all()
Introduction to Data Quality with Great Expectations

Deleting components

Use .delete() to remove components by specifying their name:

context.<COMPONENT>s.delete(

name: str )
context.data_sources.delete(
    name="my_pandas_datasource"
)

print(context.data_sources.all())
{}
Introduction to Data Quality with Great Expectations

Deleting components

Data Sources:

context.data_sources.delete(
    name="my_pandas_datasource"
)

Expectation Suites:

context.suites.delete(
    name="my_suite"
)

Validation Definitions:

context.validation_definitions.delete(
    name="my_validation_definition"
)

Checkpoints:

context.checkpoints.delete(
    name="my_checkpoint"
)
Introduction to Data Quality with Great Expectations

Cheat sheet

Add a component to Data Context:

context.data_sources.add(data_source)

context.suites.add(suite)

context.validation_definitions.add(
    validation_definition
)

context.checkpoints.add(checkpoint)

Retrieve a component:

.get(name: str)

List components:

.all()

Delete a component:

.delete(name: str)
Introduction to Data Quality with Great Expectations

Let's practice!

Introduction to Data Quality with Great Expectations

Preparing Video For Download...