Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling NULL values in Filters #825

Closed
wants to merge 12 commits into from
5 changes: 5 additions & 0 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,14 @@ def get_filters(raw_filters):
if len(splitted) > 1:
for s in eq.split(','):
s = s.strip()
if s == 'NULL':
s = None
fields.append(Dimension(col) == s)
cond = Filter(type="or", fields=fields)
else:
#allows setting filter to query that value of dimension is NULL
if eq == 'NULL':
eq = None
cond = Dimension(col) == eq
if op == 'not in':
cond = ~cond
Expand Down
2 changes: 1 addition & 1 deletion caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def get_df(self, query_obj=None):
if self.datasource.offset:
df.timestamp += timedelta(hours=self.datasource.offset)
df.replace([np.inf, -np.inf], np.nan)
df = df.fillna(0)
df = df.fillna('NULL')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this main create some problems where there's missing data expected to be numeric. Ultimately we want javascript's reserved null in the json. Would df.fillna(None) work?

Copy link
Contributor Author

@kkalyan kkalyan Jul 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df.fillna(None) threw an error 'must specify a fill method or value'
But I get your point - if ('NULL') is treated as true in javascript. we may need some similar handling in javascript (like value=='NULL'?value:null).

Side note - should this fillna be done only for Dimensions and skip Metrics ?

return df

@property
Expand Down