コード例 #1
0
def test_render_profiling_results_column_section_renderer(
        titanic_profiled_evrs_1):
    # Group EVRs by column
    evrs = {}
    for evr in titanic_profiled_evrs_1.results:
        try:
            column = evr.expectation_config.kwargs["column"]
            if column not in evrs:
                evrs[column] = []
            evrs[column].append(evr)
        except KeyError:
            pass

    for column in evrs.keys():
        with open(
                file_relative_path(
                    __file__,
                    "./output/test_render_profiling_results_column_section_renderer__"
                    + column + ".json",
                ),
                "w",
        ) as outfile:
            json.dump(
                ProfilingResultsColumnSectionRenderer().render(
                    evrs[column]).to_json_dict(),
                outfile,
                indent=2,
            )
コード例 #2
0
def test_ProfilingResultsColumnSectionRenderer_render_bar_chart_table(
        titanic_profiled_evrs_1):

    print(titanic_profiled_evrs_1["results"][0])
    distinct_values_evrs = [
        evr for evr in titanic_profiled_evrs_1["results"]
        if evr["expectation_config"]["expectation_type"] ==
        "expect_column_distinct_values_to_be_in_set"
    ]

    assert len(distinct_values_evrs) == 4

    content_blocks = []
    for evr in distinct_values_evrs:
        ProfilingResultsColumnSectionRenderer()._render_bar_chart_table(
            distinct_values_evrs,
            content_blocks,
        )
    print(json.dumps(content_blocks, indent=2))

    assert len(content_blocks) == 4

    for content_block in content_blocks:
        assert content_block["content_block_type"] == "graph"
        assert set(content_block.keys()) == {
            "header", "content_block_type", "graph", "styling"
        }
        assert json.loads(content_block["graph"])
コード例 #3
0
def test_ProfilingResultsColumnSectionRenderer_render_header(titanic_profiled_name_column_evrs):
    content_block = ProfilingResultsColumnSectionRenderer()._render_header(
        evrs=titanic_profiled_name_column_evrs,
        column_type = None
    ).to_json_dict()

    assert content_block["content_block_type"] == "header"
    print(content_block["header"])
    assert content_block["header"] == {
        'content_block_type': 'string_template', 'string_template': {
            'template': 'Name',
            'tooltip': {
                'content': 'expect_column_to_exist',
                'placement': 'top'},
            'tag': 'h5',
            'styling': {
                'classes': [
                    'm-0',
                    'p-0']}}}
    print(content_block["subheader"])
    assert content_block["subheader"] == {
        'content_block_type': 'string_template',
        'string_template': {'template': 'Type: None', 'tooltip': {
            'content': 'expect_column_values_to_be_of_type <br>expect_column_values_to_be_in_type_list'},
                            'tag': 'h6', 'styling': {'classes': ['mt-1', 'mb-0']}}}
コード例 #4
0
def test_ProfilingResultsColumnSectionRenderer_render_bar_chart_table(
        titanic_profiled_evrs_1):
    print(titanic_profiled_evrs_1.results[0])
    distinct_values_evrs = [
        evr for evr in titanic_profiled_evrs_1.results
        if evr.expectation_config.expectation_type ==
        "expect_column_distinct_values_to_be_in_set"
    ]

    assert len(distinct_values_evrs) == 4

    content_blocks = []
    for evr in distinct_values_evrs:
        content_blocks.append(
            ProfilingResultsColumnSectionRenderer()._render_bar_chart_table(
                distinct_values_evrs).to_json_dict())

    assert len(content_blocks) == 4

    for content_block in content_blocks:
        assert content_block["content_block_type"] == "graph"
        assert set(content_block.keys()) == {
            "header", "content_block_type", "graph", "styling"
        }
        assert json.loads(content_block["graph"])
コード例 #5
0
def test_ProfilingResultsColumnSectionRenderer_render_header_with_unescaped_dollar_sign(
        titanic_profiled_name_column_evrs):
    evr_with_unescaped_dollar_sign = {
        "success": True,
        "result": {
            "observed_value": "float64"
        },
        "exception_info": {
            "raised_exception": False,
            "exception_message": None,
            "exception_traceback": None,
        },
        "expectation_config": {
            "expectation_type": "expect_column_values_to_be_in_type_list",
            "kwargs": {
                "column":
                "Car Insurance Premiums ($)",
                "type_list": [
                    "DOUBLE_PRECISION", "DoubleType", "FLOAT", "FLOAT4",
                    "FLOAT8", "FloatType", "NUMERIC", "float"
                ],
                "result_format":
                "SUMMARY"
            },
            "meta": {
                "BasicDatasetProfiler": {
                    "confidence": "very low"
                }
            }
        }
    }

    content_block = ProfilingResultsColumnSectionRenderer._render_header(
        [evr_with_unescaped_dollar_sign],
        column_type=[],
    )
    assert content_block == {
        'content_block_type': 'header',
        'header': {
            'template': 'Car Insurance Premiums ($$)',
            'tooltip': {
                'content': 'expect_column_to_exist',
                'placement': 'top'
            }
        },
        'subheader': {
            'template': 'Type: []',
            'tooltip': {
                'content':
                'expect_column_values_to_be_of_type <br>expect_column_values_to_be_in_type_list'
            }
        },
        'styling': {
            'classes': ['col-12'],
            'header': {
                'classes': ['alert', 'alert-secondary']
            }
        }
    }
コード例 #6
0
def test_ProfilingResultsColumnSectionRenderer_render(
        titanic_profiled_evrs_1, titanic_profiled_name_column_evrs):
    #Smoke test for titanic names
    document = ProfilingResultsColumnSectionRenderer().render(
        titanic_profiled_name_column_evrs)
    print(document)
    assert document != {}

    #Smoke test for titanic Ages

    #This is a janky way to fetch expectations matching a specific name from an EVR suite.
    #TODO: It will no longer be necessary once we implement ValidationResultSuite._group_evrs_by_column
    from great_expectations.render.renderer.renderer import (
        Renderer, )
    evrs_by_column = Renderer()._group_evrs_by_column(titanic_profiled_evrs_1)
    print(evrs_by_column.keys())

    age_column_evrs = evrs_by_column["Age"]
    print(json.dumps(age_column_evrs, indent=2))

    document = ProfilingResultsColumnSectionRenderer().render(age_column_evrs)
    print(document)
コード例 #7
0
def test_render_profiling_results_column_section_renderer(titanic_profiled_evrs_1):
    # Group EVRs by column
    evrs = {}
    for evr in titanic_profiled_evrs_1["results"]:
        try:
            column = evr["expectation_config"]["kwargs"]["column"]
            if column not in evrs:
                evrs[column] = []
            evrs[column].append(evr)
        except KeyError:
            pass

    for column in evrs.keys():
        with open('./tests/render/output/test_render_profiling_results_column_section_renderer__' + column + '.json', 'w') \
                as outfile:
            json.dump(ProfilingResultsColumnSectionRenderer().render(evrs[column]), outfile, indent=2)
コード例 #8
0
def display_profiled_column_evrs_as_section(
    evrs,
    column,
    include_styling=True,
    return_without_displaying=False,
):
    """This is a utility function to render all of the EVRs in an ExpectationSuite with the same column name as an HTML block.

    By default, the HTML block is rendered using ExpectationSuiteColumnSectionRenderer and the view is rendered using DefaultJinjaSectionView.
    Therefore, it should look exactly the same as the default renderer for build_docs.

    Example usage:
    display_column_evrs_as_section(exp, "my_column")

    WARNING: This method is experimental.
    """

    # TODO: replace this with a generic utility function, preferably a method on an ExpectationSuite class
    column_evr_list = [
        e
        for e in evrs.results
        if "column" in e.expectation_config.kwargs
        and e.expectation_config.kwargs["column"] == column
    ]

    # TODO: Handle the case where zero evrs match the column name

    document = (
        ProfilingResultsColumnSectionRenderer().render(column_evr_list).to_json_dict()
    )
    view = DefaultJinjaSectionView().render(
        {
            "section": document,
            "section_loop": {"index": 1},
        }
    )

    return _render_for_jupyter(
        view,
        include_styling,
        return_without_displaying,
    )
コード例 #9
0
def test_ProfilingResultsColumnSectionRenderer_render_header(
        titanic_profiled_name_column_evrs):
    content_block = ProfilingResultsColumnSectionRenderer()._render_header(
        evrs=titanic_profiled_name_column_evrs, column_type=None)

    assert content_block["content_block_type"] == "header"
    assert content_block["header"] == {
        "template": "Name",
        "tooltip": {
            "content": "expect_column_to_exist",
            "placement": "top"
        }
    }
    assert content_block["subheader"] == {
        "template": "Type: None",
        "tooltip": {
            "content":
            "expect_column_values_to_be_of_type <br>expect_column_values_to_be_in_type_list"
        }
    }