Skip to content

Commit 43feb23

Browse files
committed
fix broadcast arrays
1 parent 69becc7 commit 43feb23

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/pint_array/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def _call_super_method(self, method_name, *args, **kwargs):
9797
# self.mask[key] = getattr(other, 'mask', False)
9898
# return self.data.__setitem__(key, getattr(other, 'data', other))
9999

100+
def __iter__(self):
101+
return iter(self.magnitude)
102+
100103
## Visualization ##
101104
def __repr__(self):
102105
return (
@@ -293,11 +296,15 @@ def get_manip_fun(func_str):
293296
def manip_fun(x, *args, **kwargs):
294297
xp_func = getattr(xp, func_str)
295298

299+
one_array = False
296300
if func_str not in first_arg_arrays:
297301
x = asarray(x)
298302
magnitude = xp.asarray(x.magnitude, copy=True)
299303
units = x.units
300-
304+
elif hasattr(x, "__array_namespace__"):
305+
magnitude = x
306+
units = None
307+
one_array = True
301308
else:
302309
x = [asarray(x_i) for x_i in x]
303310
if len(x) == 0:
@@ -314,7 +321,7 @@ def manip_fun(x, *args, **kwargs):
314321
):
315322
args[0] = repeats.magnitude
316323

317-
if func_str in arbitrary_num_arrays:
324+
if func_str in arbitrary_num_arrays and not one_array:
318325
magnitude = xp_func(*magnitude, *args, **kwargs)
319326
else:
320327
magnitude = xp_func(magnitude, *args, **kwargs)

0 commit comments

Comments
 (0)