Skip to content

Commit

Permalink
Visualization Unicode bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamshed Rahman committed Jul 13, 2018
1 parent f9352af commit 24cc20b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def handle_js_int_overflow(data):
# if an int is too big for Java Script to handle
# convert it to a string
if abs(v) > JS_MAX_INTEGER:
d[k] = str(v)
d[k] = text_type(v)
return data

def run_extra_queries(self):
Expand Down Expand Up @@ -779,7 +779,7 @@ def get_data(self, df):
records = df.to_dict('records')
for metric in self.metric_labels:
data[metric] = {
str(obj[DTTM_ALIAS].value / 10**9): obj.get(metric)
text_type(obj[DTTM_ALIAS].value / 10**9): obj.get(metric)
for obj in records
}

Expand Down Expand Up @@ -1528,7 +1528,7 @@ def get_data(self, df):
elif len(metrics) > 1:
series_title = ', '.join(name)
else:
l = [str(s) for s in name[1:]] # noqa: E741
l = [text_type(s) for s in name[1:]] # noqa: E741
series_title = ', '.join(l)
values = []
for i, v in ys.items():
Expand Down
36 changes: 36 additions & 0 deletions tests/viz_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,3 +949,39 @@ def test_geojson_query_obj(self):
assert results['metrics'] == []
assert results['groupby'] == []
assert results['columns'] == ['test_col']


class TimeSeriesVizTestCase(unittest.TestCase):

def test_timeseries_unicode_data(self):
datasource = Mock()
form_data = {
'groupby': ['name'],
'metrics': ['sum__payout'],
}
raw = {}
raw['name'] = [
'Real Madrid C.F.🇺🇸🇬🇧', 'Real Madrid C.F.🇺🇸🇬🇧',
'Real Madrid Basket', 'Real Madrid Basket',
]
raw['__timestamp'] = [
'2018-02-20T00:00:00', '2018-03-09T00:00:00',
'2018-02-20T00:00:00', '2018-03-09T00:00:00',
]
raw['sum__payout'] = [2, 2, 4, 4]
df = pd.DataFrame(raw)

test_viz = viz.NVD3TimeSeriesViz(datasource, form_data)
viz_data = {}
viz_data = test_viz.get_data(df)
expected = [
{u'values': [
{u'y': 4, u'x': u'2018-02-20T00:00:00'},
{u'y': 4, u'x': u'2018-03-09T00:00:00'}],
u'key': (u'Real Madrid Basket',)},
{u'values': [
{u'y': 2, u'x': u'2018-02-20T00:00:00'},
{u'y': 2, u'x': u'2018-03-09T00:00:00'}],
u'key': (u'Real Madrid C.F.\U0001f1fa\U0001f1f8\U0001f1ec\U0001f1e7',)},
]
self.assertEqual(expected, viz_data)

0 comments on commit 24cc20b

Please sign in to comment.