summaryrefslogtreecommitdiff
path: root/lib/utils.py
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-02-05 08:11:22 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-02-05 08:11:22 +0100
commita63afa58aa471b012161c7499bb6cbe489f62ce1 (patch)
tree7b1f463166c3b8d895fe3f704ba63e32f1102291 /lib/utils.py
parentdca12474ab70843e4fc77c9e9cd3db57ad2ce364 (diff)
move float_or_nan to utils
Diffstat (limited to 'lib/utils.py')
-rw-r--r--lib/utils.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py
index 7c28c91..f6a34e3 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -12,6 +12,15 @@ def is_numeric(n):
except ValueError:
return False
+def float_or_nan(n):
+ """Convert to float (if numeric) or NaN."""
+ if n == None:
+ return np.nan
+ try:
+ return float(n)
+ except ValueError:
+ return np.nan
+
def param_slice_eq(a, b, index):
"""
Check if by_param keys a and b are identical, ignoring the parameter at index.