Skip to content

Should numpy function automatically use .simplified? #152

Open

Description

@bjodah

Consider this example:

>>> import numpy as np
>>> import quantities as pq
>>> np.exp(3*pq.joule/(2*pq.cal))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/py36/lib/python3.6/site-packages/quantities/quantity.py", line 247, in __array_prepare__
    res._dimensionality = p_dict[uf](*objs)
  File "/opt/py36/lib/python3.6/site-packages/quantities/dimensionality.py", line 358, in _d_dimensionless
    raise ValueError("quantity must be dimensionless")
ValueError: quantity must be dimensionless
>>> patched_exp = lambda x: np.exp(x.simplified if hasattr(x, 'simplified') else x)
>>> patched_exp(3*pq.joule/(2*pq.cal))
array(1.43119335) * dimensionless

I would like to see this working automatically (I haven't looked into whether this can be fixed easily or if we need to wait for __array_function__ in NumPy)

Activity

  1. changed the title [-]Should numpy function automatically use `.simplified`?[/-] [+]Should numpy function automatically use .simplified?[/+] on Feb 1, 2019
  2. added this to the 0.17.0 milestone on Nov 17, 2026
  3. added
    bug
    numpy-integration
    on Nov 17, 2026
  4. modified the milestones: 0.17.0, 0.18.0 on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnumpy-integration

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions