Examine Data Quality with Great Expectations
Great Expectations is a Python-based open-source library for validating, documenting, and profiling your data. It helps you to maintain data quality and improve communication about data between teams.
GreatExpectationsDataQuality
Bases: MonitoringBaseInterface
Data Quality Monitoring using Great Expectations allowing you to create and check your data quality expectations.
Example
from src.sdk.python.rtdip_sdk.monitoring.data_quality.great_expectations.python.great_expectations_data_quality import GreatExpectationsDataQuality
from rtdip_sdk.pipelines.utilities import SparkSessionUtility
import json
# Not required if using Databricks
spark = SparkSessionUtility(config={}).execute()
df = spark_dataframe
context_root_dir = "/dbfs/great_expectations/",
expectation_suite_name = "great_expectations_suite_name"
df_datasource_name = "my_spark_in_memory_datasource",
df_asset_name = "df_asset_name",
expectation_type = "expect_column_values_to_not_be_null"
exception_dict = {
"column": "column_name",
"mostly": 0.75,
}
meta_dict = {
"notes": {
"format": "markdown",
"content": "Comment about this expectation.",
}
}
#Configure the Great Expectations Data Quality
GX = GreatExpectationsDataQuality(spark, context_root_dir, df, expectation_suite_name, df_datasource_name, df_asset_name)
validator, suite = GX.create_expectations()
expectation_configuration = GX.build_expectations(
exception_type, exception_dict, meta_dict
)
GX.add_expectations(suite, expectation_configuration)
GX.save_expectations(validator)
GX.display_expectations(suite)
#Run the Data Quality Check by Validating your data against set expecations in the suite
checkpoint_name = "checkpoint_name"
run_name_template = "run_name_template"
action_list = [
{
"name": "store_validation_result",
"action": {"class_name": "StoreValidationResultAction"},
},
{"name": "update_data_docs", "action": {"class_name": "UpdateDataDocsAction"}},
]
checkpoint_result = GX.check(checkpoint_name, run_name_template, action_list)
print(checkpoint_result)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Dataframe containing the raw data. |
required |
context_root_dir |
str
|
The root directory of the Great Expectations project. |
required |
expectation_suite_name |
str
|
The name of the expectation suite to be created. |
required |
df_datasource_name |
str
|
The name of the datasource. |
'my_spark_in_memory_datasource'
|
df_asset_name |
str
|
The name of the asset. |
'df_asset_name'
|
Source code in src/sdk/python/rtdip_sdk/pipelines/monitoring/spark/data_quality/great_expectations_data_quality.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
system_type()
staticmethod
Attributes:
Name | Type | Description |
---|---|---|
SystemType |
Environment
|
Requires PYSPARK |
Source code in src/sdk/python/rtdip_sdk/pipelines/monitoring/spark/data_quality/great_expectations_data_quality.py
119 120 121 122 123 124 125 |
|
check(checkpoint_name, run_name_template, action_list)
Validate your data against set expecations in the suite Args: checkpoint_name (str): The name of the checkpoint. run_name_template (str): The name of the run. action_list (list): The list of actions to be performed. Returns: checkpoint_result(dict)
Source code in src/sdk/python/rtdip_sdk/pipelines/monitoring/spark/data_quality/great_expectations_data_quality.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|