Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour between np.arange and np.linspace #50

Open
dangom opened this issue Aug 15, 2018 · 7 comments
Open

Inconsistent behaviour between np.arange and np.linspace #50

dangom opened this issue Aug 15, 2018 · 7 comments

Comments

@dangom
Copy link

dangom commented Aug 15, 2018

  • unyt version: 1.0.6
  • Python version: 3.6.6
  • Operating System: MacOS 10.13.6

Description

When using np.arange on quantities, I'd expect the result to be a unyt_array, just like when using np.linspace. The result, however, is a standard numpy array.

What I Did

In [310]: type(np.linspace(5*s,6*s,100))
Out[310]: unyt.array.unyt_array
In [311]: type(np.arange(5*s,6*s,100*u.ms))
Out[311]: numpy.ndarray
@ngoldbaum
Copy link
Member

I doubt there’s anything we can do about this without defining a wrapper around arange that behaves as you’re expecting. It may be the case that in the future we could override this with __array_function__ which is being actively discussed on NumPy’s github.

@astrojuanlu
Copy link

@shoyer
Copy link

shoyer commented Oct 25, 2018

np.linspace is documented as accepting scalars for start/stop rather than arrays/array-like. So following the rule that __array_function__ is only called on array-like arguments, it currently (on master) it is not slated for __array_function__ support. But perhaps this is worth revisiting?

@ngoldbaum
Copy link
Member

Yet another case where arrays-with-units are special: we want scalars with units to work seamlessly too :)

@saulshanabrook
Copy link

saulshanabrook commented Apr 3, 2019

I am not sure if this is the right place to bring this up, but it would great to be able to define custom dispatching for function like np.arange or np.empty.

I guess one option would be for to NumPy to dispatch on scalars as well as arrays. Is this incompatible with the NEP? Would anything break with this change?

EDIT: Moved here numpy/numpy#12028 (comment)

@ngoldbaum
Copy link
Member

I'm pretty sure that's a question for the numpy issue tracker or mailing list, not for the unyt bug tracker :)

@saulshanabrook
Copy link

@ngoldbaum Sorry! I was clicking around on issues and didn't realize I had switched repos :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants