Skip to content

Commit

Permalink
Visualization Unicode bug fix (apache#5387)
Browse files Browse the repository at this point in the history
* Visualization Unicode bug fix

* Fix the build (apache#5403)

The travis build has been failing for 2 reasons recently
* pylint takes > 10 minutes without outputing
* bad merge confict auto resolve in controls.jsx

* Visualization Unicode bug fix
  • Loading branch information
JamshedRahman authored and mistercrunch committed Jul 26, 2018
1 parent deb3564 commit ccf3c91
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 @@ -125,7 +125,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 @@ -770,7 +770,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 @@ -1530,7 +1530,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 @@ -976,3 +976,39 @@ def test_parse_coordinates_raises(self):

with self.assertRaises(SpatialException):
test_viz_deckgl.parse_coordinates('fldkjsalkj,fdlaskjfjadlksj')


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 ccf3c91

Please sign in to comment.