Untitled
unknown
plain_text
2 years ago
1.2 kB
7
Indexable
# Making Sure that only numbers are parsed through Data Frame
def _contains_nan(a, nan_policy='propagate', use_summation=True):
if not isinstance(a, np.ndarray):
use_summation = False # some array_likes ignore nans (e.g. pandas)
policies = ['propagate', 'raise', 'omit']
if nan_policy not in policies:
raise ValueError("nan_policy must be one of {%s}" %
', '.join("'%s'" % s for s in policies))
def _isconst(x):
y = x[~np.isnan(x)]
if y.size == 0:
return np.array([True])
else:
return (y[0] == y).all(keepdims=True)
def _quiet_nanmean(x):
y = x[~np.isnan(x)]
if y.size == 0:
return np.array([np.nan])
else:
return np.mean(y, keepdims=True)
def _quiet_nanstd(x, ddof=0):
y = x[~np.isnan(x)]
if y.size == 0:
return np.array([np.nan])
else:
return np.std(y, keepdims=True, ddof=ddof)
def _first(arr, axis):
return np.take_along_axis(arr, np.array(0, ndmin=arr.ndim), axis)
print("Function Generated to Handle NaN cases\n")Editor is loading...