diff --git a/great_expectations/jupyter_ux/__init__.py b/great_expectations/jupyter_ux/__init__.py index a8e457f882bf..20cf20f48286 100755 --- a/great_expectations/jupyter_ux/__init__.py +++ b/great_expectations/jupyter_ux/__init__.py @@ -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, @@ -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)) diff --git a/tests/test_jupyter_ux.py b/tests/test_jupyter_ux.py index 56046415e570..484a0ffbcfee 100644 --- a/tests/test_jupyter_ux.py +++ b/tests/test_jupyter_ux.py @@ -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 " """ + +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 == """\ +
+
+ +
+

+ Name +

+
+ +
+

+ Properties +

+ + + + + +
Distinct (n)1310
Distinct (%)99.8%
Missing (n)0
Missing (%)0.0%
+
+ +
+

+ Example values +

+

+ Carlsson, Mr Frans Olof + Connolly, Miss Kate + Kelly, Mr James + Allen, Miss Elisabeth Walton + Allison, Master Hudson Trevor + Allison, Miss Helen Loraine + Allison, Mr Hudson Joshua Creighton + Allison, Mrs Hudson JC (Bessie Waldo Daniels) + Anderson, Mr Harry + Andrews, Miss Kornelia Theodosia + Andrews, Mr Thomas, jr + Appleton, Mrs Edward Dale (Charlotte Lamson) + Artagaveytia, Mr Ramon + Astor, Colonel John Jacob + Astor, Mrs John Jacob (Madeleine Talmadge Force) + Aubert, Mrs Leontine Pauline + Barkworth, Mr Algernon H + Baumann, Mr John D + Baxter, Mr Quigg Edmond + Baxter, Mrs James (Helene DeLaudeniere Chaput) +

+
+ +
+ +
    +
  • expect_column_values_to_be_in_type_list True
  • +
  • expect_column_unique_value_count_to_be_between True
  • +
  • expect_column_proportion_of_unique_values_to_be_between True
  • +
  • expect_column_values_to_not_be_null True
  • +
  • expect_column_values_to_be_in_set False
  • +
  • expect_column_values_to_not_match_regex False
  • + +
+
+ +
+
""" \ No newline at end of file