def _profile(self, schema: Dict, suite_name: str = None) -> ExpectationSuite: if not suite_name: raise ValueError( "Please provide a suite name when using this profiler.") expectations = [] # TODO add recursion to allow creation of suites for nested schema files if schema["type"] == JsonSchemaTypes.OBJECT.value: for key, details in schema["properties"].items(): expectations.append( self._create_existence_expectation(key, details)) type_expectation = self._create_type_expectation(key, details) if type_expectation: expectations.append(type_expectation) range_expectation = self._create_range_expectation( key, details) if range_expectation: expectations.append(range_expectation) boolean_expectation = self._create_boolean_expectation( key, details) if boolean_expectation: expectations.append(boolean_expectation) set_expectation = self._create_set_expectation(key, details) if set_expectation: expectations.append(set_expectation) string_len_expectation = self._create_string_length_expectation( key, details) if string_len_expectation: expectations.append(string_len_expectation) null_or_not_null_expectation = self._create_null_or_not_null_column_expectation( key, details) if null_or_not_null_expectation: expectations.append(null_or_not_null_expectation) description = schema.get("description", None) meta = None if description: meta = { "notes": { "format": "markdown", "content": [f"### Description:\n{description}"], } } suite = ExpectationSuite(suite_name, expectations=expectations, meta=meta) suite.add_citation( comment=f"This suite was built by the {self.__class__.__name__}", ) return suite
def add_citation_with_batch_request( data_context: DataContext, expectation_suite: ExpectationSuite, batch_request: Optional[Dict[str, Union[str, int, Dict[str, Any]]]] = None, ) -> None: if (expectation_suite is not None and batch_request and isinstance(batch_request, dict) and BatchRequest(**batch_request)): expectation_suite.add_citation( comment="Created suite added via CLI", batch_request=batch_request, ) data_context.save_expectation_suite( expectation_suite=expectation_suite)