Skip to main content
Version: 0.17.19

util.py

Rendering utility

great_expectations.render.util.handle_strict_min_max(params: dict) tuple[str, str]

Utility function for the at least and at most conditions based on strictness.

Parameters:

params – Dictionary containing "strict_min" and "strict_max" booleans.

Returns:

Tuple of strings to use for the at least condition and the at most condition.

great_expectations.render.util.num_to_str(f: float, precision: int = 15, use_locale: bool = False, no_scientific: bool = False) str

Convert the given float to a string, centralizing standards for precision and decisions about scientific notation. Adds an approximately equal sign in the event precision loss (e.g. rounding) has occurred.

For more context, please review the following:

Convert-Float-To-String-In-Positional-Format-Without-Scientific-Notation-And-Fa

Parameters:
  • f – The number to format.

  • precision – The number of digits of precision to display (defaults to 4).

  • use_locale – If True, use locale-specific formatting (e.g. adding thousands separators).

  • no_scientific – If True, print all available digits of precision without scientific notation. This may insert leading zeros before very small numbers, causing the resulting string to be longer than precisioncharacters.

Returns:

A string representation of the input float f, according to the desired parameters.

great_expectations.render.util.parse_row_condition_string_pandas_engine(condition_string: str, with_schema: bool = False) tuple[str, dict]

Parses the row condition string into a pandas engine compatible format.

Parameters:
  • condition_string – A pandas row condition string.

  • with_schema – Return results in json schema format. Defaults to False.

Returns:

A tuple containing the template string and a dict of parameters.

>>> template_str, params = parse_row_condition_string_pandas_engine("Age in [0, 42]")
>>> print(template_str)
"if $row_condition__0"
>>> params
{"row_condition__0": "Age in [0, 42]"}

great_expectations.render.util.substitute_none_for_missing(kwargs: dict[str, Any], kwarg_list: Sequence[str]) dict[str, Any]

Utility function to plug Nones in when optional parameters are not specified in expectation kwargs.

Parameters:
  • kwargs – A dictionary of keyword arguments.

  • kwargs_list – A list or sequence of strings representing all possible keyword parameters to a function.

Returns:

A copy of the original kwargs with missing keys from kwarg_list defaulted to None.

>>> result = substitute_none_for_missing(
… kwargs={"a":1, "b":2},
… kwarg_list=["c", "d"]
)
print(result)
{"a":1, "b":2, "c": None, "d": None}

This is helpful for standardizing the input objects for rendering functions. The alternative is lots of awkward if "some_param" not in kwargs or kwargs["some_param"] == None: clauses in renderers.