Skip to content

Commit b6efa33

Browse files
committed
full separate numpy > 2.0 array wrap
1 parent b367e87 commit b6efa33

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

quantities/quantity.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,18 @@ def __array_prepare__(self, obj, context=None):
292292

293293
def __array_wrap__(self, obj, context=None, return_scalar=False):
294294
_np_version = tuple(map(int, np.__version__.split('.')))
295+
# For NumPy < 2.0 we do old behavior
295296
if _np_version < (2, 0, 0):
296297
if not isinstance(obj, Quantity):
297298
return self.__array_prepare__(obj, context)
298299
else:
299300
return obj
301+
# For NumPy > 2.0 we either do the prepare or the wrap
300302
else:
301-
return super().__array_wrap__(obj, context, return_scalar)
303+
if not isinstance(obj, Quantity):
304+
return self.__array_prepare__(obj, context)
305+
else:
306+
return super().__array_wrap__(obj, context, return_scalar)
302307

303308

304309
@with_doc(np.ndarray.__add__)

0 commit comments

Comments
 (0)