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
No related tags found
No related merge requests found
from math import isnan
from django.db import models, IntegrityError from django.db import models, IntegrityError
from django.urls import reverse from django.urls import reverse
...@@ -986,12 +988,17 @@ class SingleInspiral(models.Model): ...@@ -986,12 +988,17 @@ class SingleInspiral(models.Model):
#log.debug("Single/creating event") #log.debug("Single/creating event")
for f in [cls._meta.get_field(f) for f in cls.field_names()]: for f in [cls._meta.get_field(f) for f in cls.field_names()]:
value = getattr(row, f.attname, f.default) 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 # Only set value of class instance member if
# value is not None or if field is nullable. # value is not None or if field is nullable.
# Otherwise we could overwrite non-nullable fields # Otherwise we could overwrite non-nullable fields
# which have default values with None. # which have default values with None.
if value is not None or f.null: 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) setattr(e, f.attname, value)
e.save() e.save()
created_events.append(e) created_events.append(e)
......
...@@ -93,7 +93,11 @@ ...@@ -93,7 +93,11 @@
<tr> <tr>
<th>Effective Distance</th> <th>Effective Distance</th>
{% for e in single_inspiral_events %} {% 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 %} {% endfor %}
</tr> </tr>
<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