Skip to content

Commit 06111bb

Browse files
committed
clean up
1 parent 7f9f932 commit 06111bb

File tree

1 file changed

+18
-72
lines changed

1 file changed

+18
-72
lines changed

src/pint_array/__init__.py

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -349,45 +349,6 @@ def fun(x, /, *args, func_str=func_str, **kwargs):
349349

350350
setattr(mod, func_str, fun)
351351

352-
def _is_quantity(obj):
353-
"""Test for _units and _magnitude attrs.
354-
355-
This is done in place of isinstance(Quantity, arg),
356-
which would cause a circular import.
357-
358-
Parameters
359-
----------
360-
obj : Object
361-
362-
Returns
363-
-------
364-
bool
365-
"""
366-
return hasattr(obj, "_units") and hasattr(obj, "_magnitude")
367-
368-
def _is_sequence_with_quantity_elements(obj):
369-
"""Test for sequences of quantities.
370-
371-
Parameters
372-
----------
373-
obj : object
374-
375-
Returns
376-
-------
377-
True if obj is a sequence and at least one element is a Quantity;
378-
False otherwise
379-
"""
380-
if is_array_api_obj(obj) and not obj.dtype.hasobject:
381-
# If obj is an array, avoid looping on all elements
382-
# if dtype does not have objects
383-
return False
384-
return (
385-
iterable(obj)
386-
and sized(obj)
387-
and not isinstance(obj, str)
388-
and any(_is_quantity(item) for item in obj)
389-
)
390-
391352
elementwise_two_arrays = [
392353
"add",
393354
"atan2",
@@ -455,6 +416,24 @@ def func(x, /, *args, func_str=func_str, **kwargs):
455416

456417
setattr(mod, func_str, func)
457418

419+
for func_str in (
420+
"any",
421+
"all",
422+
):
423+
424+
def func(x, /, *args, func_str=func_str, **kwargs):
425+
x = asarray(x)
426+
magnitude = xp.asarray(x.magnitude, copy=True)
427+
if x._is_multiplicative:
428+
xp_func = getattr(xp, func_str)
429+
magnitude = xp_func(magnitude, *args, **kwargs)
430+
return ArrayUnitQuantity(magnitude, None)
431+
432+
msg = "Boolean value of Quantity with offset unit is ambiguous."
433+
raise ValueError(msg)
434+
435+
setattr(mod, func_str, func)
436+
458437
# output_unit="variance":
459438
# square of `x.units`,
460439
# unless non-multiplicative, which raises `OffsetUnitCalculusError`
@@ -480,37 +459,4 @@ def prod(x, /, *args, axis=None, **kwargs):
480459

481460
mod.prod = prod
482461

483-
for func_str in (
484-
"any",
485-
"all",
486-
):
487-
488-
def func(x, /, *args, func_str=func_str, **kwargs):
489-
x = asarray(x)
490-
magnitude = xp.asarray(x.magnitude, copy=True)
491-
if x._is_multiplicative:
492-
xp_func = getattr(xp, func_str)
493-
magnitude = xp_func(magnitude, *args, **kwargs)
494-
return ArrayUnitQuantity(magnitude, None)
495-
496-
msg = "Boolean value of Quantity with offset unit is ambiguous."
497-
raise ValueError(msg)
498-
499-
setattr(mod, func_str, func)
500-
501-
# "mul": product of all units in `all_args`
502-
# - "delta": `first_input_units`, unless non-multiplicative,
503-
# which uses delta version
504-
# - "delta,div": like "delta",
505-
# but divided by all units in `all_args` except the first
506-
# - "div": unit of first argument in `all_args`
507-
# (or dimensionless if not a Quantity) divided
508-
# by all following units
509-
# - "square": square of `first_input_units`
510-
# - "sqrt": square root of `first_input_units`
511-
# - "reciprocal": reciprocal of `first_input_units`
512-
# - "size": `first_input_units` raised to the power of `size`
513-
# - "invdiv": inverse of `div`,
514-
# product of all following units divided by first argument unit
515-
516462
return mod

0 commit comments

Comments
 (0)