Skip to content

Quantity.__array_function__ follow up for Quantity #8825

@mhvk

Description

@mhvk

EDIT: non-Quantity discussion of __array_function__ is in #8610

In the non-yet-merged but ready-for-review #8808, support for numpy's __array_function__ is introduced. For a number of functions, a decision still needs to be made, mostly on whether to stick exactly to the numpy docstring or to make adjustments to parameter defaults that make the function more useful for Quantity

  • np.isclose, np.allclose: these were never all that useful since internally they calculate abs(a - b) < atol + rtol * abs(a) and atol is given as a small number, which is interpreted as dimensionless. For Quantity, we could either set it to 0 or assume the units of a, but in either case it would become inconsistent with the docstring that users actually see. (Decision: units of a - Quantity behaviour for np.isclose, np.allclose; some others #9463)
  • np.broadcast_arrays and np.broadcast_to by default return plain arrays, needing subok=True to work for Quantity. We could change the default if a Quantity is present. Again, the possible issue is that the docstring will no longer be correct. (Decision: leave as is, since old code could cease working; Quantity behaviour for np.isclose, np.allclose; some others #9463)

Furthermore, a few top-level functions need an actual implementation and/or better test cases:

And finally we should also cover the numpy submodules that have routines not exported to the top level. In particular:

EDIT: And it would probably be good to add tests for Quantity subclasses:

  • LogQuantity such as Magnitude
  • Angles such as Longitude

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions