Accounting For "No Rows Returned" Via Python
Summary: intapiuser inquired about handling situations in Python when querying a database returns no results.

So you've built a beautiful dashboard but your user decides to use a filter combination that returns no rows. Sometimes it's not even your users, it may just be that you have a structure where not all charts should have data returned. To account for the case when No Rows Returned, we can lean on Python to do our "error" handling for us. To check for the No Rows Returned condition, all you have to do is add look for the df to have nothing.You can then add meaningful values, such as a blank string to be passed. That's what we did for this object where we built a dashboard with a chart for each major possible line item and account for it not being a part of the data returned.
# extract important variables
def extract(df):
if df.size == 0:
return ['N/A', '', '']
else:
current = str(prettify_num(df.iloc[0,1]))
contract = str(prettify_num(df.iloc[0,0]))
return [percent_difference(df), current, contract]0 comments