From 54fba0f39ccc434f0cf9235d88c4a1b3b7d13054 Mon Sep 17 00:00:00 2001 From: JamshedRahman <31935303+JamshedRahman@users.noreply.github.com> Date: Thu, 26 Jul 2018 13:18:35 -0700 Subject: [PATCH] Visualization Unicode bug fix (#5387) * Visualization Unicode bug fix * Fix the build (#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 --- superset/viz.py | 6 +++--- tests/viz_tests.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/superset/viz.py b/superset/viz.py index d1732fa7559eb..59acb9f7fe234 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -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): @@ -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 } @@ -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(): diff --git a/tests/viz_tests.py b/tests/viz_tests.py index 0602c0aa5b890..95a69fcac4851 100644 --- a/tests/viz_tests.py +++ b/tests/viz_tests.py @@ -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)