diff --git a/superset/connectors/druid/models.py b/superset/connectors/druid/models.py index 25c68acae1283..b9263129f2a94 100644 --- a/superset/connectors/druid/models.py +++ b/superset/connectors/druid/models.py @@ -1277,6 +1277,21 @@ def run_query( # noqa / druid client.query_builder.last_query.query_dict, indent=2) return query_str + @staticmethod + def homogenize_types(df, groupby_cols): + """Converting all GROUPBY columns to strings + + When grouping by a numeric (say FLOAT) column, pydruid returns + strings in the dataframe. This creates issues downstream related + to having mixed types in the dataframe + + Here we replace None with and make the whole series a + str instead of an object. + """ + for col in groupby_cols: + df[col] = df[col].fillna('').astype(str) + return df + def query(self, query_obj): qry_start_dttm = datetime.now() client = self.cluster.get_pydruid_client() @@ -1284,6 +1299,8 @@ def query(self, query_obj): client=client, query_obj=query_obj, phase=2) df = client.export_pandas() + df = self.homogenize_types(df, query_obj.get('groupby', [])) + if df is None or df.size == 0: raise Exception(_('No data was returned.')) df.columns = [