# Similar expecations overwriting one another

**URL:** <https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695>\
**Category:** GX Core Support\
**Created:** [April 9, 2024, 2:23pm UTC](https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695 "2024-04-09T14:23:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_f50](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/mike_f50/32/169_2.png) [@mike\_f50](https://discourse.greatexpectations.io/u/mike_f50)\
**Post date:** [April 9, 2024, 2:23pm UTC](https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695/1 "2024-04-09T14:23:09Z")

</div>

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)

```py
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" } } }
)
validator.expect_column_values_to_be_in_set(
    "Cohort",
    value_set={ "$PARAMETER": "urn:great_expectations:stores:sql_data_store:lookup_cohort_list" },
    meta={ "profiler_details": { "metric_configuration": { "metric_name": "cohort_configured_in_platform" } } }
)

```

In this example, the second expectation runs but not the first.

**Example 2:** `expect_table_row_count_to_be_between` (different row\_conditions)

```py
for cohort in cohorts:
    validator.expect_table_row_count_to_be_between(
        row_condition=f"Cohort==\"{cohort}\"",
        condition_parser='spark',
        min_value=get_min_expected_rows_for_cohort(cohort),
        max_value=get_max_expected_rows_for_cohort(cohort),
        meta={ "profiler_details": { "metric_configuration": { "metric_name": f"{cohort}_row_count" } } }
    )

```

In this example, the expecataion for `Cohort3` runs, but not the expectations for `Cohort1` or `Cohort2`.

Note that there doesn’t seem to be a fundamental issue with utilising the same expectation type multiple times, as demonstated below.

**Example 3:** `expect_column_values_to_be_in_set` (different row\_conditions and value\_sets)

```py
for cohort in cohorts:
    validator.expect_column_values_to_be_in_set(
        "Active",
        row_condition=f"Cohort==\"{cohort}\"",
        condition_parser='spark',
        value_set=[False],
        mostly=get_min_expected_inactive_for_cohort(cohort),
        meta={ "profiler_details": { "metric_configuration": { "metric_name": f"{cohort}_inactive" } } }
    )
    validator.expect_column_values_to_be_in_set(
        "Active",
        row_condition=f"Cohort==\"{cohort}\"",
        condition_parser='spark',
        value_set=[True],
        mostly=get_min_expected_active_for_cohort(cohort),
        meta={ "profiler_details": { "metric_configuration": { "metric_name": f"{cohort}_active" } } } )

```

Here, the second expectation runs _for each cohort_, but not the first - so I get 3 of the 6 expectations I was hoping for.

Perhaps what I’m trying to achieve is not possible (I know Conditional Expectations are experimental), but I’m hoping someone may be able to point me in the right direction.

---

<div class="post-metadata">

**Author:** ![mike\_f50](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/mike_f50/32/169_2.png) [@mike\_f50](https://discourse.greatexpectations.io/u/mike_f50)\
**Post date:** [April 9, 2024, 2:57pm UTC](https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695/2 "2024-04-09T14:57:02Z")

</div>

In the interests of attempting to answer my own question, I have now come across some relevant documentation, which suggests GE may be being cleverer than I want and editing my expecations rather than adding additional ones, since I’m creating them in the “interactive” mode: [Create Expectations interactively with Python | Great Expectations](https://docs.greatexpectations.io/docs/oss/guides/expectations/how_to_create_and_edit_expectations_with_instant_feedback_from_a_sample_batch_of_data#edit-expectations-or-create-additional-expectations-optional)

Since I am coding up my production system rather than interactively interrogating the data, I am going to explore using this alternative method for creating my expectations:

> **[Create and edit Expectations based on domain knowledge, without inspecting...](https://docs.greatexpectations.io/docs/oss/guides/expectations/how_to_create_and_edit_expectations_based_on_domain_knowledge_without_inspecting_data_directly/)**
>
> Create ExpectationConfigurations based on domain knowledge.

---

<div class="post-metadata">

**Author:** ![ToivoMattila](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/toivomattila/32/254_2.png) [@ToivoMattila](https://discourse.greatexpectations.io/u/ToivoMattila)\
**Post date:** [April 9, 2024, 3:31pm UTC](https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695/3 "2024-04-09T15:31:08Z")

</div>

This looks interesting.  
Yeah, writing the expectations with Python overwrites the existing expectation if it targets the same column. I have no idea if GX allows having multiple expectations like this if you write them directly to YAML. I’m interested in how this works, please do update the thread with what you find out!

Besides that, to me, this sounds like you might want to have multiple versions of something, maybe Assets or Expectations Suites. Granted, this is without knowing the specifics, i.e. what data you are validating.

---

<div class="post-metadata">

**Author:** ![ToivoMattila](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/toivomattila/32/254_2.png) [@ToivoMattila](https://discourse.greatexpectations.io/u/ToivoMattila)\
**Post date:** [April 9, 2024, 4:02pm UTC](https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695/4 "2024-04-09T16:02:53Z")

</div>

Took a look at this and apparently it’s possible to just directly add the same Expectation multiple times into the YAML/JSON files and it works just fine!

---

<div class="post-metadata">

**Author:** ![mike\_f50](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/mike_f50/32/169_2.png) [@mike\_f50](https://discourse.greatexpectations.io/u/mike_f50)\
**Post date:** [April 9, 2024, 4:17pm UTC](https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695/5 "2024-04-09T16:17:15Z")

</div>

Thanks Tovio. Yes, appending expectations to a suite using Python seems to be doing the trick too.

---

<div class="post-metadata">

**Author:** ![mike\_f50](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/mike_f50/32/169_2.png) [@mike\_f50](https://discourse.greatexpectations.io/u/mike_f50)\
**Post date:** [April 11, 2024, 10:28am UTC](https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695/6 "2024-04-11T10:28:13Z")

</div>

The specific syntax that works for me is:

```py
suite.expectations.append()

```

Note that `suite.add_expectation_configuration()` (as currently stated in the documentation) is invalid, and `suite.add_expectation()` seems to apply the same de-duplication logic which I am trying to avoid.

See here for fuller examples, but swap in `suite.expectations.append()` at the point of adding the expectation to the suite:

> **[Create and edit Expectations based on domain knowledge, without inspecting...](https://docs.greatexpectations.io/docs/oss/guides/expectations/how_to_create_and_edit_expectations_based_on_domain_knowledge_without_inspecting_data_directly/)**
>
> Create ExpectationConfigurations based on domain knowledge.

---

<div class="post-metadata">

**Author:** ![chandru.kdj](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@chandru.kdj](https://discourse.greatexpectations.io/u/chandru.kdj)\
**Post date:** [June 9, 2025, 5:17am UTC](https://discourse.greatexpectations.io/t/similar-expecations-overwriting-one-another/1695/7 "2025-06-09T05:17:02Z")

</div>

I just tried today swapping in suite.expectations.append() in 1.4.6 version. It doesn’t seem to work. The expectation suite validation result says zero expectations added.
