Skip to main content
Version: 0.18.9

Validator

class great_expectations.validator.validator.Validator(execution_engine: ExecutionEngine, interactive_evaluation: bool = True, expectation_suite: ExpectationSuite | None = None, expectation_suite_name: Optional[str] = None, data_context: Optional[AbstractDataContext] = None, batches: List[Batch] | Sequence[Batch | FluentBatch] = (), include_rendered_content: Optional[bool] = None, **kwargs)#

Validator is the key object used to create Expectations, validate Expectations, and get Metrics for Expectations.

Validators are used by Checkpoints to validate Expectations.

Parameters
  • execution_engine – The Execution Engine to be used to perform validation.

  • interactive_evaluation – If True, the Validator will perform evaluation when Expectations are added.

  • expectation_suite – The Expectation Suite to validate.

  • expectation_suite_name – The name of the Expectation Suite to validate.

  • data_context – The Data Context associated with this Validator.

  • batches – The Batches for which to validate.

  • include_rendered_content – If True, the Rendered Content will be included in the ExpectationValidationResult.

columns(domain_kwargs: Optional[Dict[str, Any]] = None) List[str]#

Convenience method to obtain Batch columns.

Parameters

domain_kwargs – Optional dictionary of domain kwargs (e.g., containing “batch_id”).

Returns

The list of Batch columns.

get_expectation_suite(discard_failed_expectations: bool = True, discard_result_format_kwargs: bool = True, discard_include_config_kwargs: bool = True, discard_catch_exceptions_kwargs: bool = True, suppress_warnings: bool = False, suppress_logging: bool = False) great_expectations.core.expectation_suite.ExpectationSuite#

Get a copy of the Expectation Suite from the Validator object.

Parameters
  • discard_failed_expectations – Omit Expectations which failed on their last run.

  • discard_result_format_kwargs – Omit result_format from each Expectation.

  • discard_include_config_kwargs – Omit include_config from each Expectation.

  • discard_catch_exceptions_kwargs – Omit catch_exceptions from each Expectation.

  • suppress_warnings – Do not log warnings.

  • suppress_logging – Do not log anything.

Returns

ExpectationSuite object.

get_metric(metric: MetricConfiguration) Any#

Convenience method, return the value of the requested metric.

Parameters

metric – MetricConfiguration

Returns

The value of the requested metric.

head(n_rows: int = 5, domain_kwargs: Optional[Dict[str, Any]] = None, fetch_all: bool = False) pandas.core.frame.DataFrame#

Convenience method to return the first several rows or records from a Batch of data.

Parameters
  • n_rows – The number of rows to return.

  • domain_kwargs – If provided, the domain for which to return records.

  • fetch_all – If True, ignore n_rows and return the entire batch.

Returns

A Pandas DataFrame containing the records’ data.

remove_expectation(expectation_configuration: great_expectations.core.expectation_configuration.ExpectationConfiguration, match_type: str = 'domain', remove_multiple_matches: bool = False, ge_cloud_id: Optional[str] = None) List[great_expectations.core.expectation_configuration.ExpectationConfiguration]#

Remove an ExpectationConfiguration from the ExpectationSuite associated with the Validator.

Parameters
  • expectation_configuration – A potentially incomplete (partial) Expectation Configuration to match against.

  • match_type – This determines what kwargs to use when matching. Options are:

  • - ‘domain’ to match based on the data evaluated by that expectation - ‘success’ to match based on all configuration parameters that influence whether an expectation succeeds on a given batch of data - ‘runtime’ to match based on all configuration parameters.
  • remove_multiple_matches – If True, will remove multiple matching expectations.

  • ge_cloud_id – Great Expectations Cloud id for an Expectation.

Returns

The list of deleted ExpectationConfigurations.

Raises
  • TypeError – Must provide either expectation_configuration or ge_cloud_id.

  • ValueError – No match or multiple matches found (and remove_multiple_matches=False).

save_expectation_suite(filepath: Optional[str] = None, discard_failed_expectations: bool = True, discard_result_format_kwargs: bool = True, discard_include_config_kwargs: bool = True, discard_catch_exceptions_kwargs: bool = True, suppress_warnings: bool = False) None#

Write the Expectation Suite (e.g. from interactive evaluation) to the Expectation Store associated with the Validator’s Data Context.

If filepath is provided, the Data Context configuration will be ignored and the configuration will be written, as JSON, to the specified file.

Parameters
  • filepath – The location and name to write the JSON config file to. This parameter overrides the Data Context configuration.

  • discard_failed_expectations – If True, excludes expectations that do not return success = True. If False, all expectations are saved.

  • discard_result_format_kwargs – If True, the result_format attribute for each expectation is not included in the saved configuration.

  • discard_include_config_kwargs – If True, the include_config attribute for each expectation is not included in the saved configuration.

  • discard_catch_exceptions_kwargs – If True, the catch_exceptions attribute for each expectation is not included in the saved configuration.

  • suppress_warnings – If True, all warnings raised by Great Expectations, as a result of dropped expectations, are suppressed.

Raises

ValueError – Must configure a Data Context when instantiating the Validator or pass in filepath.

validate(expectation_suite: Optional[Union[str, great_expectations.core.expectation_suite.ExpectationSuite]] = None, run_id: Optional[Union[str, great_expectations.core.run_identifier.RunIdentifier, Dict[str, str]]] = None, data_context: Optional[Any] = None, evaluation_parameters: Optional[dict] = None, catch_exceptions: bool = True, result_format: Optional[str] = None, only_return_failures: bool = False, run_name: Optional[str] = None, run_time: Optional[str] = None, checkpoint_name: Optional[str] = None) Union[great_expectations.core.expectation_validation_result.ExpectationValidationResult, great_expectations.core.expectation_validation_result.ExpectationSuiteValidationResult]#

Run all expectations and return the outcome of the run.

Parameters
  • expectation_suite – If None, uses the Expectation Suite configuration generated during the current Validator session. If an ExpectationSuite object, uses it as the configuration. If a string, assumes it is a path to a JSON file, and loads it as the Expectation Sutie configuration.

  • run_id – Used to identify this validation result as part of a collection of validations.

  • Deprecated since version 0.13.0: Only the str version of this argument is deprecated. run_id should be a RunIdentifier or dict. Support will be removed in 0.16.0.

  • run_name – Used to identify this validation result as part of a collection of validations. Only used if a run_id is not passed. See DataContext for more information.

  • run_time – Used to identify this validation result as part of a collection of validations. Only used if a run_id is not passed. See DataContext for more information.

  • data_context – A datacontext object to use as part of validation for binding evaluation parameters and registering validation results. Overrides the Data Context configured when the Validator is instantiated.

  • evaluation_parameters – If None, uses the evaluation_paramters from the Expectation Suite provided or as part of the Data Asset. If a dict, uses the evaluation parameters in the dictionary.

  • catch_exceptions – If True, exceptions raised by tests will not end validation and will be described in the returned report.

  • result_format – If None, uses the default value (‘BASIC’ or as specified). If string, the returned expectation output follows the specified format (‘BOOLEAN_ONLY’,’BASIC’, etc.).

  • only_return_failures – If True, expectation results are only returned when success = False.

  • checkpoint_name – Name of the Checkpoint which invoked this Validator.validate() call against an Expectation Suite. It will be added to meta field of the returned ExpectationSuiteValidationResult.

Returns

Object containg the results.

Raises
  • Exception – Depending on the Data Context configuration and arguments, there are numerous possible exceptions that may be raised.

  • GreatExpectationsError – If expectation_suite is a string it must point to an existing and readable file.

  • ValidationError – If expectation_suite is a string, the file it points to must be valid JSON.