Skip to content
Snippets Groups Projects
Commit 52e5a60b authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

RF: Change naninfrange approach to flattening structured arrays, avoid

copying data if possible, and avoid copydeprecation warnings.
parent 6e33e589
No related branches found
No related tags found
No related merge requests found
......@@ -24,10 +24,28 @@ def naninfrange(data):
"""
# For structured arrays, we assume that
# all fields are numeric, and we simply
# take the range across all fields
# all fields have the same dtype, and we
# simply take the range across all fields
if len(data.dtype) > 0:
data = np.concatenate([data[n] for n in data.dtype.names])
# Avoid inducing a data copy if
# at all possible. np.ndarray
# doesn't preserve the underlying
# order, so let's set that. Also,
# we're forced to make a copy if
# the array is not contiguous,
# otherwise ndarray will complain
if data.flags['C_CONTIGUOUS']: order = 'C'
elif data.flags['F_CONTIGUOUS']: order = 'F'
else:
data = np.ascontiguousarray(data)
order = 'C'
shape = [len(data.dtype)] + list(data.shape)
data = np.ndarray(buffer=data.data,
shape=shape,
order=order,
dtype=data.dtype[0])
if not np.issubdtype(data.dtype, np.floating):
return data.min(), data.max()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment