Skip to content

Commit b307d6b

Browse files
committed
ENH: ensure yt.utils.funcs.ensure_numpy_array consistently returns a copy
1 parent e962538 commit b307d6b

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

yt/funcs.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,7 @@ def ensure_numpy_array(obj):
8686
This function ensures that *obj* is a numpy array. Typically used to
8787
convert scalar, list or tuple argument passed to functions using Cython.
8888
"""
89-
if isinstance(obj, np.ndarray):
90-
if obj.shape == ():
91-
return np.array([obj])
92-
# We cast to ndarray to catch ndarray subclasses
93-
return np.array(obj)
94-
elif isinstance(obj, (list, tuple)):
95-
return np.asarray(obj)
96-
else:
97-
return np.asarray([obj])
89+
return np.atleast_1d(np.asarray(obj, copy=True))
9890

9991

10092
def read_struct(f, fmt):

0 commit comments

Comments
 (0)