Skip to content
Snippets Groups Projects
Commit b538795d authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Adding handling for nan values in eff_distance

gstlal wants to set eff_distance to nan when they don't have a
meaningful value for it.  Unfortunately, we can't save that in the
database because MySQL numeric types can't deal with nans. So we
check for nans in this field and set it to NULL if it is nan,
before saving it in the database.
parent ce00f056
No related branches found
Tags gracedb-2.5.0
No related merge requests found
from math import isnan
from django.db import models, IntegrityError
from django.urls import reverse
......@@ -986,12 +988,17 @@ class SingleInspiral(models.Model):
#log.debug("Single/creating event")
for f in [cls._meta.get_field(f) for f in cls.field_names()]:
value = getattr(row, f.attname, f.default)
# Handle nan for eff_distance
if f.attname == 'eff_distance' and isnan(value):
value = None
# Only set value of class instance member if
# value is not None or if field is nullable.
# Otherwise we could overwrite non-nullable fields
# which have default values with None.
if value is not None or f.null:
#log.debug("Setting column '%s' with value '%s'" % (column, value))
#log.debug("Setting column '%s' with value '%s'" % (f.attname, value))
setattr(e, f.attname, value)
e.save()
created_events.append(e)
......
......@@ -93,7 +93,11 @@
<tr>
<th>Effective Distance</th>
{% for e in single_inspiral_events %}
<td>{{ e.eff_distance }}&nbsp;Mpc</td>
<td>
{% if e.eff_distance %}
{{ e.eff_distance }}&nbsp;Mpc
{% endif %}
</td>
{% endfor %}
</tr>
<tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment