def safe_as_int(val, atol=0.001):
 mod = (np.asarray(val) % 1)
 if (mod.ndim == 0):
  if (mod > 0.5):
   mod = (1 - mod)
 else:
  mod[(mod > 0.5)] = (1 - mod[(mod > 0.5)])
 try:
  np.testing.assert_allclose(mod, 0, atol=atol)
 except AssertionError:
  raise ValueError('Integer argument required but received {0}, check inputs.'.format(val))
 return np.round(val).astype(np.int64)

def safe_as_int ( val , atol = 0.001 ) : mod = ( np . asarray ( val ) % 1 ) if ( mod . ndim == 0 ) : if ( mod > 0.5 ) : mod = ( 1 - mod ) else : mod [ ( mod > 0.5 ) ] = ( 1 - mod [ ( mod > 0.5 ) ] ) try : np . testing . assert_allclose ( mod , 0 , atol = atol ) except AssertionError : raise ValueError ( 'Integer argument required but received {0}, check inputs.' . format ( val ) ) return np . round ( val ) . astype ( np . int64 )
attempt to safely cast values to integer format .