Skip to content

astropy.units.quantity_input does not work with numpy.vectorizing #6007

Open

Description

@maxnoe
import astropy.units as u
import numpy as np


@np.vectorize
@u.quantity_input(t0=u.s, t1=u.s)
def example(a, t0, t1):
    return a * (t0 / t1).si


example(0, 5*u.hour, 10 * u.hour)

Result in the exception:

TypeError: Argument 't0' to function 'example' has no 'unit' attribute. You may want to pass in an astropy Quantity instead.

If I switch the two decorators I get

AttributeError: 'vectorize' object has no attribute '__name__'

Activity

  1. mhvk commented on May 5, 2017

    @mhvk
    Contributor

    With the switch, I think it should have worked (though it is a pain that np.vectorize doesn't set a __name__). cc @Cadair.

  2. mhvk commented on May 5, 2017

    @mhvk
    Contributor

    p.s. Do you want to raise an issue with numpy for the wrapped function not having a __name__ set?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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