azureazure-databricks

Great Expectation: Databricks-cannot import name 'get_context' from 'great_expectations.util'


I am following article from Great Expectations to try test cases. However, I am getting exception regarding get_context.

When I try to execute command

from great_expectations.util import get_context

It throws exception. Exception detail are

ImportError: cannot import name 'get_context' from 'great_expectations.util' (/local_disk0/.ephemeral_nfs/envs/pythonEnv-e053b0a2-5a41-4a6b-9156-547a7ba12dfb/lib/python3.11/site-packages/great_expectations/util.py)


Solution

  • In this case, the document you are referring is outdated.

    In older versions of Great Expectations (before v0.16), get_context was accessed differently.

    In latest versions, get_context() is provided under great_expectations, and not under great_expectations.util .

    Below I have used the code from latest document of Great Expectation and It ran successfully without any error:

    enter image description here

    Code:

    import datetime
    
    import pandas as pd
    from ruamel import yaml
    
    from great_expectations.core.batch import RuntimeBatchRequest
    from great_expectations import get_context
    from great_expectations.data_context.types.base import (
        DataContextConfig,
        FilesystemStoreBackendDefaults,
    )
    

    Kindly go through the latest document of Greatest Expectations:

    Great Expectations