Skip to content

Commit

Permalink
[druid] fix bug around handling NULLs
Browse files Browse the repository at this point in the history
fillna would miss out on identifying STRING columns for Druid and
replace None in string columns with a numeric `0`. This
mixed type column would confuse
pandas down the line on some operations like `df.pivot_table`.
  • Loading branch information
mistercrunch committed Feb 6, 2018
1 parent 2d8a0cc commit ae4ca3a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,22 @@ def __init__(self, datasource, form_data):
self.status = None
self.error_message = None

def get_fillna_for_type(self, col_type):
def get_fillna_for_col(self, col):
"""Returns the value for use as filler for a specific Column.type"""
if col_type:
if col_type == 'TEXT' or col_type.startswith('VARCHAR'):
if col:
if col.is_string:
return ' NULL'
return self.default_fillna

def get_fillna_for_columns(self, columns=None):
"""Returns a dict or scalar that can be passed to DataFrame.fillna"""
if columns is None:
return self.default_fillna
columns_types = self.datasource.columns_types
fillna = {c: self.get_fillna_for_type(columns_types.get(c)) for c in columns}
columns_dict = {col.column_name: col for col in self.datasource.columns}
fillna = {
c: self.get_fillna_for_col(columns_dict.get(c))
for c in columns
}
return fillna

def get_df(self, query_obj=None):
Expand Down

0 comments on commit ae4ca3a

Please sign in to comment.