Skip to content

Commit ad11d3a

Browse files
Avoid looping on large numpy arrays (#1987)
1 parent 9a93a68 commit ad11d3a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pint/facets/numpy/numpy_func.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def _is_sequence_with_quantity_elements(obj):
5252
-------
5353
True if obj is a sequence and at least one element is a Quantity; False otherwise
5454
"""
55+
if np is not None and isinstance(obj, np.ndarray) and not obj.dtype.hasobject:
56+
# If obj is a numpy array, avoid looping on all elements
57+
# if dtype does not have objects
58+
return False
5559
return (
5660
iterable(obj)
5761
and sized(obj)

0 commit comments

Comments
 (0)