Skip to content

Commit ade7357

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

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

yt/funcs.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,9 @@ def ensure_numpy_array(obj):
8585
"""
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.
88+
Always return a copy of the input data.
8889
"""
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])
90+
return np.atleast_1d(np.array(obj))
9891

9992

10093
def read_struct(f, fmt):

0 commit comments

Comments
 (0)