great_expectations.data_context.util

Module Contents

Functions

instantiate_class_from_config(config, runtime_environment, config_defaults=None)

Build a GE class from configuration dictionaries.

format_dict_for_error_message(dict_)

substitute_config_variable(template_str, config_variables_dict, dollar_sign_escape_string: str = ‘\$’)

This method takes a string, and if it contains a pattern ${SOME_VARIABLE} or $SOME_VARIABLE,

substitute_all_config_variables(data, replace_variables_dict, dollar_sign_escape_string: str = ‘\$’)

Substitute all config variables of the form ${SOME_VARIABLE} in a dictionary-like

file_relative_path(dunderfile, relative_path)

This function is useful when one needs to load a file that is

great_expectations.data_context.util.logger
great_expectations.data_context.util.instantiate_class_from_config(config, runtime_environment, config_defaults=None)

Build a GE class from configuration dictionaries.

great_expectations.data_context.util.format_dict_for_error_message(dict_)
great_expectations.data_context.util.substitute_config_variable(template_str, config_variables_dict, dollar_sign_escape_string: str = '\$')

This method takes a string, and if it contains a pattern ${SOME_VARIABLE} or $SOME_VARIABLE, returns a string where the pattern is replaced with the value of SOME_VARIABLE, otherwise returns the string unchanged. These patterns are case sensitive. There can be multiple patterns in a string, e.g. all 3 will be substituted in the following: $SOME_VARIABLE${some_OTHER_variable}$another_variable

If the environment variable SOME_VARIABLE is set, the method uses its value for substitution. If it is not set, the value of SOME_VARIABLE is looked up in the config variables store (file). If it is not found there, the input string is returned as is.

If the value to substitute is not a string, it is returned as-is.

If the value to substitute begins with dollar_sign_escape_string it is not substituted.

Parameters
  • template_str – a string that might or might not be of the form ${SOME_VARIABLE} or $SOME_VARIABLE

  • config_variables_dict – a dictionary of config variables. It is loaded from the config variables store (by default, “uncommitted/config_variables.yml file)

  • dollar_sign_escape_string – a string that will be used in place of a $ when substitution is not desired.

Returns

a string with values substituted, or the same object if template_str is not a string.

great_expectations.data_context.util.substitute_all_config_variables(data, replace_variables_dict, dollar_sign_escape_string: str = '\$')

Substitute all config variables of the form ${SOME_VARIABLE} in a dictionary-like config object for their values.

The method traverses the dictionary recursively.

Parameters
  • data

  • replace_variables_dict

Returns

a dictionary with all the variables replaced with their values

great_expectations.data_context.util.file_relative_path(dunderfile, relative_path)

This function is useful when one needs to load a file that is relative to the position of the current file. (Such as when you encode a configuration file path in source file and want in runnable in any current working directory)

It is meant to be used like the following: file_relative_path(__file__, ‘path/relative/to/file’)

H/T https://github.com/dagster-io/dagster/blob/8a250e9619a49e8bff8e9aa7435df89c2d2ea039/python_modules/dagster/dagster/utils/__init__.py#L34