Skip to content

Commit

Permalink
Add display_column_evrs_as_section with snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
abegong committed Jul 18, 2019
1 parent a6453d9 commit 89a3173
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
40 changes: 40 additions & 0 deletions great_expectations/jupyter_ux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def display_column_expectations_as_section(
#TODO: replace this with a generic utility function, preferably a method on an ExpectationSuite class
column_expectation_list = [ e for e in expectation_suite["expectations"] if "column" in e["kwargs"] and e["kwargs"]["column"] == column ]

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

document = render.renderer.PrescriptiveColumnSectionRenderer.render(column_expectation_list)
view = render.view.DefaultJinjaSectionView.render({
"section": document,
Expand All @@ -232,3 +234,41 @@ def display_column_expectations_as_section(
return html_to_display
else:
display(HTML(html_to_display))

def display_column_evrs_as_section(
evrs,
column,
section_renderer=render.renderer.column_section_renderer.DescriptiveColumnSectionRenderer,
view_renderer=render.view.view.DefaultJinjaSectionView,
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 PrescriptiveColumnSectionRenderer 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")
"""

#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 = render.renderer.DescriptiveColumnSectionRenderer.render(column_evr_list)
view = render.view.DefaultJinjaSectionView.render({
"section": document,
"section_loop": {"index": 1},
})

if include_styling:
html_to_display = bootstrap_link_element+cooltip_style_element+view
else:
html_to_display = view

if return_without_displaying:
return html_to_display
else:
display(HTML(html_to_display))
84 changes: 84 additions & 0 deletions tests/test_jupyter_ux.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import great_expectations as ge
import great_expectations.jupyter_ux as jux
from great_expectations.profile.basic_dataset_profiler import BasicDatasetProfiler

def test_styling_elements_exist():
assert "<link" in jux.bootstrap_link_element
Expand Down Expand Up @@ -112,3 +114,85 @@ def test_display_column_expectations_as_section(basic_expectation_suite):
</div>
</div>"""

def test_display_column_evrs_as_section():
#TODO: We should add a fixture that contains EVRs

df = ge.read_csv("./tests/test_sets/Titanic.csv")
df.profile(BasicDatasetProfiler)
evrs = df.validate(result_format="SUMMARY") # ["results"]

html_to_display = jux.display_column_evrs_as_section(
evrs,
"Name",
include_styling=False,
return_without_displaying=True
)
print(html_to_display)
assert html_to_display == """\
<div id="section-1" class="ge-section container-fluid">
<div class="row">
<div id="content-block-1" class="col-12" >
<h3 id="content-block-1-header" class="alert alert-secondary" >
Name
</h3>
</div>
<div id="content-block-2" class="col-4" style="margin-top:20px;" >
<h4 id="content-block-2-header" >
Properties
</h4>
<table id="content-block-2-body" class="table table-sm table-unbordered" style="width:100%;" >
<tr>
<td id="content-block-2-cell-1-1" >Distinct (n)</td><td id="content-block-2-cell-1-2" >1310</td></tr><tr>
<td id="content-block-2-cell-2-1" >Distinct (%)</td><td id="content-block-2-cell-2-2" >99.8%</td></tr><tr>
<td id="content-block-2-cell-3-1" >Missing (n)</td><td id="content-block-2-cell-3-2" >0</td></tr><tr>
<td id="content-block-2-cell-4-1" >Missing (%)</td><td id="content-block-2-cell-4-2" >0.0%</td></tr></table>
</div>
<div id="content-block-3" class="col-12" style="margin-top:20px;" >
<h4 id="content-block-3-header" >
Example values
</h4>
<p id="content-block-3-body" >
<span class="badge badge-info" >Carlsson, Mr Frans Olof</span>
<span class="badge badge-info" >Connolly, Miss Kate</span>
<span class="badge badge-info" >Kelly, Mr James</span>
<span class="badge badge-info" >Allen, Miss Elisabeth Walton</span>
<span class="badge badge-info" >Allison, Master Hudson Trevor</span>
<span class="badge badge-info" >Allison, Miss Helen Loraine</span>
<span class="badge badge-info" >Allison, Mr Hudson Joshua Creighton</span>
<span class="badge badge-info" >Allison, Mrs Hudson JC (Bessie Waldo Daniels)</span>
<span class="badge badge-info" >Anderson, Mr Harry</span>
<span class="badge badge-info" >Andrews, Miss Kornelia Theodosia</span>
<span class="badge badge-info" >Andrews, Mr Thomas, jr</span>
<span class="badge badge-info" >Appleton, Mrs Edward Dale (Charlotte Lamson)</span>
<span class="badge badge-info" >Artagaveytia, Mr Ramon</span>
<span class="badge badge-info" >Astor, Colonel John Jacob</span>
<span class="badge badge-info" >Astor, Mrs John Jacob (Madeleine Talmadge Force)</span>
<span class="badge badge-info" >Aubert, Mrs Leontine Pauline</span>
<span class="badge badge-info" >Barkworth, Mr Algernon H</span>
<span class="badge badge-info" >Baumann, Mr John D</span>
<span class="badge badge-info" >Baxter, Mr Quigg Edmond</span>
<span class="badge badge-info" >Baxter, Mrs James (Helene DeLaudeniere Chaput)</span>
</p>
</div>
<div id="content-block-4" class="col-12" style="margin-top:20px;" >
<h4 id="content-block-4-header" class="collapsed" data-toggle="collapse" href="#content-block-4-body" role="button" aria-expanded="true" aria-controls="collapseExample" style="cursor:pointer;" >
Expectation types <span class="mr-3 triangle"></span>
</h4>
<ul id="content-block-4-body" class="list-group collapse" >
<li class="list-group-item d-flex justify-content-between align-items-center" >expect_column_values_to_be_in_type_list <span class="badge badge-secondary badge-pill" >True</span></li>
<li class="list-group-item d-flex justify-content-between align-items-center" >expect_column_unique_value_count_to_be_between <span class="badge badge-secondary badge-pill" >True</span></li>
<li class="list-group-item d-flex justify-content-between align-items-center" >expect_column_proportion_of_unique_values_to_be_between <span class="badge badge-secondary badge-pill" >True</span></li>
<li class="list-group-item d-flex justify-content-between align-items-center" >expect_column_values_to_not_be_null <span class="badge badge-secondary badge-pill" >True</span></li>
<li class="list-group-item d-flex justify-content-between align-items-center" >expect_column_values_to_be_in_set <span class="badge badge-secondary badge-pill" >False</span></li>
<li class="list-group-item d-flex justify-content-between align-items-center" >expect_column_values_to_not_match_regex <span class="badge badge-secondary badge-pill" >False</span></li>
</ul>
</div>
</div>
</div>"""

0 comments on commit 89a3173

Please sign in to comment.