From a63afa58aa471b012161c7499bb6cbe489f62ce1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 5 Feb 2019 08:11:22 +0100 Subject: move float_or_nan to utils --- lib/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/utils.py') 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. -- cgit v1.2.3