diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/db.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/python/db.py b/python/db.py index 08b65b37..32c4ea38 100644 --- a/python/db.py +++ b/python/db.py @@ -2,6 +2,7 @@ import psycopg2 from psycopg2.extras import DictCursor from psycopg2 import IntegrityError from sqlalchemy import create_engine +import numpy as np def dbconn(dbname): if dbname == 'etdb': @@ -14,6 +15,13 @@ def dbconn(dbname): host="debian", cursor_factory=DictCursor) + +def nan_to_null(f, _NULL=psycopg2.extensions.AsIs('NULL'), + _Float=psycopg2.extensions.Float): + if not np.isnan(f): + return _Float(f) + return _NULL + def dbengine(dbname): uri = "postgresql://{0}@debian/{1}".format(dbname[:-2] + '_user', dbname) |
