예제 #1
0
def json_config_expectation(name, file_path):
    def _file_passes(_info, df):
        with open(file_path) as ff:
            expt_config = json.load(ff)
            # This is necessary because ge ends up coercing a type change
            # on the same dataframe instance, changing the type. But a
            # ge can't be copied, because it causes an error.
            # The error is
            #  AttributeError: 'PandasDataset' object has no attribute
            #  'discard_subset_failing_expectations'
            # See https://github.com/great-expectations/great_expectations/issues/342
            df_copy = copy.deepcopy(df)
            ge_df = ge.from_pandas(df_copy, expectations_config=expt_config)
            validate_result = ge_df.validate()
            check.invariant('success' in validate_result)
            check.invariant('results' in validate_result)
            return ExpectationResult(
                success=validate_result['success'],
                metadata_entries=[
                    EventMetadataEntry.json(label='result',
                                            data=validate_result)
                ],
            )

    return ExpectationDefinition(name, expectation_fn=_file_passes)
예제 #2
0
def ge_expectation(name, ge_callback):
    def _do_expectation(_info, df):
        ge_df = ge.from_pandas(df)
        ge_result = ge_callback(ge_df)
        check.invariant('success' in ge_result)
        return ExpectationResult(success=ge_result['success'],
                                 result_context=ge_result)

    return ExpectationDefinition(name, expectation_fn=_do_expectation)
예제 #3
0
def ge_expectation(name, ge_callback):
    def _do_expectation(_info, df):
        ge_df = ge.from_pandas(df)
        ge_result = ge_callback(ge_df)
        check.invariant('success' in ge_result)
        return ExpectationResult(
            success=ge_result['success'],
            metadata_entries=[
                EventMetadataEntry.json(label='result', data=ge_result)
            ],
        )

    return ExpectationDefinition(name, expectation_fn=_do_expectation)