def exception_to_nan(func):
 def wrap(*a, **kw):
  try:
   return func(*a, **kw)
  except Exception:
   return np.nan
 return wrap

def exception_to_nan ( func ) : def wrap ( * a , ** kw ) : try : return func ( * a , ** kw ) except Exception : return np . nan return wrap
decorate function to return nan if it raises an exception .