Skip to content

Commit b367e87

Browse files
committed
fix for numpy 2.0 wrapping
1 parent 1713ff9 commit b367e87

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

quantities/quantity.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,15 @@ def __array_prepare__(self, obj, context=None):
291291
return res
292292

293293
def __array_wrap__(self, obj, context=None, return_scalar=False):
294-
if not isinstance(obj, Quantity):
295-
if tuple(map(int, np.__version__.split('.'))) < (2, 0, 0):
296-
# backwards compatibility with numpy-1.3
294+
_np_version = tuple(map(int, np.__version__.split('.')))
295+
if _np_version < (2, 0, 0):
296+
if not isinstance(obj, Quantity):
297297
return self.__array_prepare__(obj, context)
298298
else:
299-
return super().__array_wrap__(obj, context, return_scalar)
299+
return obj
300300
else:
301-
return obj
301+
return super().__array_wrap__(obj, context, return_scalar)
302+
302303

303304
@with_doc(np.ndarray.__add__)
304305
@scale_other_units

0 commit comments

Comments
 (0)