# I am currently working with Great Expectations Core to validate data from two different sources: a CSV file and a MongoDB data source. While I am able to create Expectations and generate local Data Docs, I am encountering the same issue in both cases. S

**URL:** <https://discourse.greatexpectations.io/t/i-am-currently-working-with-great-expectations-core-to-validate-data-from-two-different-sources-a-csv-file-and-a-mongodb-data-source-while-i-am-able-to-create-expectations-and-generate-local-data-docs-i-am-encountering-the-same-issue-in-both-cases-s/1975>\
**Category:** GX Core Support\
**Tags:** how-to\
**Created:** [November 2, 2024, 7:08am UTC](https://discourse.greatexpectations.io/t/i-am-currently-working-with-great-expectations-core-to-validate-data-from-two-different-sources-a-csv-file-and-a-mongodb-data-source-while-i-am-able-to-create-expectations-and-generate-local-data-docs-i-am-encountering-the-same-issue-in-both-cases-s/1975 "2024-11-02T07:08:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BHAVYA](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@BHAVYA](https://discourse.greatexpectations.io/u/BHAVYA)\
**Post date:** [November 2, 2024, 7:08am UTC](https://discourse.greatexpectations.io/t/i-am-currently-working-with-great-expectations-core-to-validate-data-from-two-different-sources-a-csv-file-and-a-mongodb-data-source-while-i-am-able-to-create-expectations-and-generate-local-data-docs-i-am-encountering-the-same-issue-in-both-cases-s/1975/1 "2024-11-02T07:08:13Z")

</div>

code ------

import pandas as pd  
import great\_expectations as ge  
from great\_expectations.core.batch import RuntimeBatchRequest  
import json

# Load sample data into a Pandas DataFrame

try:  
df = ge.read\_csv(“sample\_data.csv”)  
print(“Data loaded successfully.”)  
except Exception as e:  
print(f"Error loading data: {e}")  
raise

# Initialize Great Expectations Data Context

try:  
context = ge.data\_context.DataContext()  
print(“Data context initialized successfully.”)

```
# Build data docs after validation
context.build_data_docs()

# Open the data docs in a browser
context.open_data_docs()

```

except Exception as e:  
print(f"Error initializing Data Context: {e}")  
raise

# Step 1: Add the pandas Datasource (in case it’s not already added)

datasource\_config = {  
“name”: “pandas\_datasource”,  
“class\_name”: “Datasource”,  
“execution\_engine”: {  
“class\_name”: “PandasExecutionEngine”,  
},  
“data\_connectors”: {  
“default\_runtime\_data\_connector\_name”: {  
“class\_name”: “RuntimeDataConnector”,  
“batch\_identifiers”: [“default\_identifier\_name”],  
},  
},  
}

context.add\_datasource(\*\*datasource\_config)

# Create or update an expectation suite (a collection of validation expectations)

expectation\_suite\_name = “simple\_expectation\_suite5”  
try:  
context.add\_or\_update\_expectation\_suite(expectation\_suite\_name=expectation\_suite\_name)  
print(f"Added/updated expectation suite: {expectation\_suite\_name}“)  
except Exception as e:  
print(f"Error creating/updating expectation suite: {e}”)  
raise

# Step 2: Create a RuntimeBatchRequest for the DataFrame

batch\_request = RuntimeBatchRequest(  
datasource\_name=“pandas\_datasource”, # Name the datasource  
data\_connector\_name=“default\_runtime\_data\_connector\_name”, # Use runtime for in-memory data  
data\_asset\_name=“mongo\_dataframe\_asset”, # Name the asset  
runtime\_parameters={“batch\_data”: df}, # The DataFrame as batch data  
batch\_identifiers={“default\_identifier\_name”: “default\_identifier”}  
)

# Step 3: Create a Validator to Validate the DataFrame Against the Expectation Suite

try:  
validator = context.get\_validator(  
batch\_request=batch\_request,  
expectation\_suite\_name=expectation\_suite\_name  
)  
print(“Validator created successfully.”)  
except Exception as e:  
print(f"Error creating validator: {e}")  
raise

# Step 4: Add Expectations to the Validator

# Step 4: Add Expectations for Quantiles, Median, and Values

try:  
# Add expectations for basic validations  
validator.expect\_column\_to\_exist(“Designation”)  
validator.expect\_column\_values\_to\_not\_be\_null(“name”)  
validator.expect\_column\_values\_to\_be\_between(“age”, 40, 100)

```
# Add expectation for column quantiles (specify quantiles like 0.05, 0.25, 0.5, 0.75, and 0.95)
validator.expect_column_quantile_values_to_be_between(
    column="age",
    quantile_ranges={
        "quantiles": [0.05, 0.25, 0.5, 0.75, 0.95],
        "value_ranges": [
            [100, 500], # Range for 5th percentile
            [1000, 1500], # Range for 25th percentile (Q1)
            [2000, 2500], # Range for median (50th percentile)
            [3000, 3500], # Range for 75th percentile (Q3)
            [4000, 4500] # Range for 95th percentile
        ]
    }
)

# Expect the column median to fall between a specific range (optional, as median is the 50th quantile)
validator.expect_column_median_to_be_between(
    column="age", min_value=2000, max_value=2500
)
print("Expectations added to the validator successfully.")

# Save the expectation suite after adding expectations
validator.save_expectation_suite(discard_failed_expectations=False)
print("Expectation suite saved successfully.")

```

except Exception as e:  
print(f"Error adding expectations to validator or saving suite: {e}")  
raise

# Step 5: Validate the Data and capture detailed results

try:  
validation\_results = validator.validate()  
# Rebuild Data Docs to visualize the validation results  
context.build\_data\_docs()  
context.open\_data\_docs()

## except Exception as e: print(f"Error validating data: {e}") raise

csv data ------

| id | name | age |
| --- | --- | --- |
| 1 | John | |
| 2 | Alice | 32 |
| 3 | Bob | 45 |
| 4 | Eve | 26 |
| 5 | Frank | 23 |

* * *

output -----

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/greatexpectations/original/1X/b65677cc78c0a239ca7c52da7a69ea02c532ccd3.jpeg)

**Request:**

Could you please help me understand why the validation statistics/validation tat are not showing up and guide me on how to fix this? If any supporting documents or configuration details are required, please let me know.

---

<div class="post-metadata">

**Author:** ![adeola](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@adeola](https://discourse.greatexpectations.io/u/adeola)\
**Post date:** [November 7, 2024, 4:38pm UTC](https://discourse.greatexpectations.io/t/i-am-currently-working-with-great-expectations-core-to-validate-data-from-two-different-sources-a-csv-file-and-a-mongodb-data-source-while-i-am-able-to-create-expectations-and-generate-local-data-docs-i-am-encountering-the-same-issue-in-both-cases-s/1975/2 "2024-11-07T16:38:00Z")

</div>

hi there, what version of GX are you on? the issue here appears to be not having a checkpoint set up, however any version pre v1 is no longer supported.

I’d recommend following our [migration guide](https://docs.greatexpectations.io/docs/reference/learn/migration_guide/?utm_campaign=General%20Community%20Promotion&utm_source=GitHub&utm_medium=post&utm_content=migration-guide) and upgrading to v1.

A simple v1 script could look something like this:

```auto

context = gx.get_context(mode="file")

data = {
    "ID": [1, 2, 3, 4, None],
    "name": ["Alice", "Bob", "Charlie", "David", None],
    "age_when_joined": [25, 30, 35, 40, 28],
    "age_when_left": [26, 38, 38, 49, 30],
}

df = pd.DataFrame(data)

batch_parameters = {"dataframe": df}

data_source_name = "my_data_source"
data_source = context.data_sources.add_pandas(name=data_source_name)

data_asset_name = "my_dataframe_data_asset"
data_asset = data_source.add_dataframe_asset(name=data_asset_name)

batch_definition_name = "my_batch_definition"
batch_definition = data_asset.add_batch_definition_whole_dataframe(
    batch_definition_name
)

suite = context.suites.add(
    gx.core.expectation_suite.ExpectationSuite(name="my_expectations")
)

suite.add_expectation(
    gx.expectations.ExpectColumnPairValuesAToBeGreaterThanB(
        column_A="age_when_left", 
        column_B="age_when_joined", 
        or_equal=True
    )
)

validation_definition = context.validation_definitions.add(
    gx.core.validation_definition.ValidationDefinition(
        name="my_validation_definition",
        data=batch_definition,
        suite=suite,
    )
)

checkpoint = context.checkpoints.add(
    gx.Checkpoint(
        name="checkpoint",
        validation_definitions=[validation_definition],
        actions=[gx.checkpoint.actions.UpdateDataDocsAction(name="dda")],
        result_format={"result_format": "BASIC", "unexpected_index_column_names": ["ID", "name", "age_when_left", "age_when_joined"]},
    )
)

validation_results = checkpoint.run(batch_parameters=batch_parameters)
print(validation_results)

context.open_data_docs()

```
