MCPcopy Index your code
hub / github.com/pydata/xarray / maybe_wrap_array

Function maybe_wrap_array

xarray/core/utils.py:225–235  ·  view source on GitHub ↗

Wrap a transformed array with __array_wrap__ if it can be done safely. This lets us treat arbitrary functions that take and return ndarray objects like ufuncs, as long as they return an array with the same shape.

(original, new_array)

Source from the content-addressed store, hash-verified

223
224
225def maybe_wrap_array(original, new_array):
226 """Wrap a transformed array with __array_wrap__ if it can be done safely.
227
228 This lets us treat arbitrary functions that take and return ndarray objects
229 like ufuncs, as long as they return an array with the same shape.
230 """
231 # in case func lost array's metadata
232 if isinstance(new_array, np.ndarray) and new_array.shape == original.shape:
233 return original.__array_wrap__(new_array)
234 else:
235 return new_array
236
237
238def equivalent(first: T, second: T) -> bool:

Callers 3

mapMethod · 0.90
mapMethod · 0.90
mapMethod · 0.90

Calls 1

__array_wrap__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…