add error catching

This commit is contained in:
Andy Eschbacher 2016-06-27 10:07:22 -04:00
parent a2b3733a1e
commit 3e01470aa0

View File

@ -40,17 +40,15 @@ def get_data(variable, feature_columns, query):
prepared data, packaged into NumPy arrays prepared data, packaged into NumPy arrays
""" """
columns = ','.join(['array_agg("{col}") As "{col}"'.format(col=col) for col in feature_columns]) columns = ','.join(['array_agg("{col}") As "{col}"'.format(col=col) for col in feature_columns])
data = plpy.execute(''' try:
SELECT array_agg("{variable}") As target, data = plpy.execute('''SELECT array_agg("{variable}") As target, {columns} FROM ({query}) As a'''.format(
{columns} variable=variable,
FROM ({query}) As a columns=columns,
'''.format( query=query))
variable = variable, except Exception, e:
columns = columns, plpy.error('failed to fetch data to construct model')
query = query
))
target = np.array(data[0]['target']) target = np.array(data[0]['target'])