What am I doing wrong?
import great_expectations as gx
from great_expectations.core.expectation_configuration import ExpectationConfiguration
context = gx.get_context()
suite = context.add_expectation_suite(expectation_suite_name="my_suite")
config1=ExpectationConfiguration(
expectation_type="expect_table_row_count_to_be_between",
kwargs={
"min_value":0,
"max_value":100,
},
)
suite.add_expectation_configuration(expectation_configuration=config1)
Error:
AttributeError: 'ExpectationSuite' object has no attribute 'add_expectation_configuration'
I belive I’ve followed the instructions here pretty closely.
1 Like
Update: The code below seems to work.
suite.expectations.append(config1)
Perhaps the documentation needs updating?
Huhta
April 10, 2024, 11:24am
3
The code should be
suite.add_expectation()
All the code blocks seem to use the wrong function but the actual text in some docs talk about the above command.
1 Like
ziero
April 10, 2024, 9:52pm
4
@nevintan have seen this as well – are docs out of date with api?
Just to note, suite.add_expectation()
and suite.expectations.append()
sometimes behave differently when adding the same expectation type more than once. suite.add_expectation()
will attempt to de-dupe, replacing existing expectations, whereas suite.expectations.append()
simply appends.
Examples here:
I am building an expectation suite in python, and am coming across a few different scenarios where adding another expectation of the same type seems to overwrite an existing one.
Example 1: expect_column_values_to_be_in_set (different value_sets for same column)
cohorts = ["Cohort1","Cohort2","Cohort3"]
validator.expect_column_values_to_be_in_set(
"Cohort",
value_set=cohorts,
meta={ "profiler_details": { "metric_configuration": { "metric_name": "cohort_in_approved_set" } } }
)
val…
Hi all! Thank you for flagging this. I’ll notify our docs team to make sure everything is correct and up to date on our side.
2 Likes