Skip to content

Commit

Permalink
Merge 66fc0fe into 5f6017c
Browse files Browse the repository at this point in the history
  • Loading branch information
abegong committed Aug 10, 2019
2 parents 5f6017c + 66fc0fe commit 839b338
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 7 deletions.
15 changes: 9 additions & 6 deletions great_expectations/render/renderer/column_section_renderer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import altair as alt
import json
import pandas as pd
from string import Template
import re

import altair as alt
import pandas as pd

from .renderer import Renderer
from .content_block import ValueListContentBlockRenderer
Expand All @@ -16,6 +18,8 @@
RenderedComponentContent,
)

def convert_to_string_and_escape(var):
return re.sub("\$", "$$", str(var))

class ColumnSectionRenderer(Renderer):
@classmethod
Expand Down Expand Up @@ -79,7 +83,6 @@ def render(cls, evrs, section_name=None, column_type=None):

@classmethod
def _render_header(cls, evrs, content_blocks, column_type=None):

# NOTE: This logic is brittle
try:
column_name = evrs[0]["expectation_config"]["kwargs"]["column"]
Expand All @@ -100,7 +103,7 @@ def _render_header(cls, evrs, content_blocks, column_type=None):
content_blocks.append(RenderedComponentContent(**{
"content_block_type": "header",
"header": {
"template": column_name,
"template": convert_to_string_and_escape(column_name),
"tooltip": {
"content": "expect_column_to_exist",
"placement": "top"
Expand Down Expand Up @@ -574,7 +577,7 @@ def _render_header(cls, validation_results, content_blocks):

content_blocks.append(RenderedComponentContent(**{
"content_block_type": "header",
"header": column,
"header": convert_to_string_and_escape(column),
"styling": {
"classes": ["col-12"],
"header": {
Expand Down Expand Up @@ -619,7 +622,7 @@ def _render_header(cls, expectations, content_blocks):

content_blocks.append(RenderedComponentContent(**{
"content_block_type": "header",
"header": column,
"header": convert_to_string_and_escape(column),
"styling": {
"classes": ["col-12"],
"header": {
Expand Down
3 changes: 3 additions & 0 deletions great_expectations/render/view/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def render_styling_from_string_template(cls, template):

@classmethod
def render_string_template(cls, template):
#NOTE: Using this line for debugging. This should probably be logged...?
# print(template)

# NOTE: We should add some kind of type-checking to template
if not isinstance(template, (dict, OrderedDict)):
return template
Expand Down
92 changes: 91 additions & 1 deletion tests/render/test_column_section_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ def test_ProfilingResultsColumnSectionRenderer_render(titanic_profiled_evrs_1, t

def test_ProfilingResultsColumnSectionRenderer_render_header(titanic_profiled_name_column_evrs):
content_blocks = []
# print(titanic_profiled_name_column_evrs)
ProfilingResultsColumnSectionRenderer()._render_header(
titanic_profiled_name_column_evrs,
content_blocks,
column_type = None
)
print(json.dumps(content_blocks, indent=2))
# print(json.dumps(content_blocks, indent=2))

assert len(content_blocks) == 1
content_block = content_blocks[0]
Expand All @@ -120,6 +121,59 @@ def test_ProfilingResultsColumnSectionRenderer_render_header(titanic_profiled_na
}
}

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_blocks = []
ProfilingResultsColumnSectionRenderer._render_header(
[evr_with_unescaped_dollar_sign],
content_blocks=content_blocks,
column_type=[],
)
print(content_blocks)
assert content_blocks[0] == {
'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']}}
}


# def test_ProfilingResultsColumnSectionRenderer_render_overview_table():
# evrs = {}
Expand Down Expand Up @@ -218,6 +272,42 @@ def test_ExpectationSuiteColumnSectionRenderer_render_header(titanic_profiled_na
})
]

expectation_with_unescaped_dollar_sign = {
"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"
}
}
}
remaining_expectations, content_blocks = ExpectationSuiteColumnSectionRenderer._render_header(
[expectation_with_unescaped_dollar_sign],
[]
)
print(content_blocks)
assert content_blocks[0] == {
'content_block_type': 'header',
'header': 'Car Insurance Premiums ($$)',
'styling': {'classes': ['col-12'], 'header': {'classes': ['alert', 'alert-secondary']}}
}





def test_ExpectationSuiteColumnSectionRenderer_render_bullet_list(titanic_profiled_name_column_expectations):
remaining_expectations, content_blocks = ExpectationSuiteColumnSectionRenderer._render_bullet_list(
Expand Down
6 changes: 6 additions & 0 deletions tests/render/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,9 @@ def test_render_string_template():
</span>""".replace(" ", "").replace("\t", "").replace("\n", "")

assert res == expected

def test_render_string_template_bug_1():
#Looks like string templates can't contain dollar signs. We need some kind of escaping
with pytest.raises(ValueError):
template = {'template': 'Car Insurance Premiums ($)', 'tooltip': {'content': 'expect_column_to_exist', 'placement': 'top'}}
DefaultJinjaPageView.render_string_template(template)

0 comments on commit 839b338

Please sign in to comment.