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
"""
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('''
SELECT array_agg("{variable}") As target,
{columns}
FROM ({query}) As a
'''.format(
variable = variable,
columns = columns,
query = query
))
try:
data = plpy.execute('''SELECT array_agg("{variable}") As target, {columns} FROM ({query}) As a'''.format(
variable=variable,
columns=columns,
query=query))
except Exception, e:
plpy.error('failed to fetch data to construct model')
target = np.array(data[0]['target'])