From 5c98f5642b0928f0f496e957b584d97d1d3e7385 Mon Sep 17 00:00:00 2001 From: michellethomas Date: Mon, 19 Mar 2018 11:43:04 -0700 Subject: [PATCH] Fix sqllab numpy array (#4629) * Fixing error with sqllab numpy array * Adding tests for failing sqllab data type --- superset/sql_lab.py | 2 +- tests/sqllab_tests.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/superset/sql_lab.py b/superset/sql_lab.py index f98231ed775c9..12644fcf808c1 100644 --- a/superset/sql_lab.py +++ b/superset/sql_lab.py @@ -97,7 +97,7 @@ def convert_results_to_df(cursor_description, data): if data: first_row = data[0] has_dict_col = any([isinstance(c, dict) for c in first_row]) - df_data = list(data) if has_dict_col else np.array(data) + df_data = list(data) if has_dict_col else np.array(data, dtype=object) else: df_data = [] diff --git a/tests/sqllab_tests.py b/tests/sqllab_tests.py index 01b10b262681f..977bbe0d35554 100644 --- a/tests/sqllab_tests.py +++ b/tests/sqllab_tests.py @@ -203,8 +203,16 @@ def test_alias_duplicate(self): raise_on_error=True) def test_df_conversion_no_dict(self): - cols = [['string_col'], ['int_col']] - data = [['a', 4]] + cols = [['string_col'], ['int_col'], ['float_col']] + data = [['a', 4, 4.0]] + cdf = convert_results_to_df(cols, data) + + self.assertEquals(len(data), cdf.size) + self.assertEquals(len(cols), len(cdf.columns)) + + def test_df_conversion_tuple(self): + cols = [['string_col'], ['int_col'], ['list_col'], ['float_col']] + data = [(u'Text', 111, [123], 1.0)] cdf = convert_results_to_df(cols, data) self.assertEquals(len(data), cdf.size)