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

numpy.linspace broken with Quantities #4543

Merged
merged 1 commit into from
Mar 8, 2016

Conversation

mhvk
Copy link
Contributor

@mhvk mhvk commented Mar 2, 2016

Numpy's linspace used to work nicely with quantities:

Numpy 1.9.3

>>> np.linspace(-1 * u.m, 1 * u.m, 10)
<Quantity [-1.        ,-0.77777778,-0.55555556,-0.33333333,-0.11111111,
            0.11111111, 0.33333333, 0.55555556, 0.77777778, 1.        ] m>

Numpy 1.10

>>> np.linspace(-1 * u.m, 1 * u.m, 10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tom/miniconda3/envs/np110/lib/python2.7/site-packages/numpy/core/function_base.py", line 115, in linspace
    y[-1] = stop
ValueError: setting an array element with a sequence.

@mhvk - is this a bug in Astropy, or a bug introduced in Numpy?

A lot of user code might rely on this, so we should get a workaround out soon unless it has to be fixed in Numpy.

@mhvk
Copy link
Contributor

mhvk commented Jan 29, 2016

It is a numpy regression: see numpy/numpy#7142

@eteq
Copy link
Member

eteq commented Feb 8, 2016

@mhvk - is this now fixed post- numpy/numpy#7156 ? If so, how should we proceed on this issue - should we mention this as a "known issue" in numpy 1.10.x<1.10.5 ? (do you know how far back it goes?)

@mhvk
Copy link
Contributor

mhvk commented Feb 9, 2016

@eteq - yes, it would be a known issue in numpy 1.10, up to 1.10.5. If anywhere, it would probably be part of http://docs.astropy.org/en/latest/known_issues.html#quantity-issues

@mhvk
Copy link
Contributor

mhvk commented Mar 2, 2016

@eteq - I went ahead and made this into a PR with a small documentation update. Only thing I'm not quite sure about is whether I set the labels right...

Quantities in np.linspace failure on numpy 1.10
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In numpy 1.10, `~numpy.linspace` initially failed to work with quantities.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhvk - I would rephrase to say 'linspace does not work correctly with quantities when using Numpy 1.10.0 to 1.10.5 due to a bug in Numpy. The solution is to upgrade to Numpy 1.10.6, in which the bug was fixed'

@mhvk mhvk force-pushed the linspace-not-working-with-numpy-1.10 branch from a6773a3 to 4e45aad Compare March 4, 2016 14:52
@mhvk
Copy link
Contributor

mhvk commented Mar 4, 2016

@astrofrog - agreed, might as well be clear about where the problem was. Now changed the text.

@mhvk
Copy link
Contributor

mhvk commented Mar 8, 2016

I'm going ahead and merge this small documentation update -- there's a bit of a cost to leaving things like this open, if only that they keep popping up any time I look at my open issues/PRs.

mhvk added a commit that referenced this pull request Mar 8, 2016
numpy.linspace broken with Quantities with early numpy 1.10 -- documentation update
@mhvk mhvk merged commit b824752 into astropy:master Mar 8, 2016
eteq pushed a commit that referenced this pull request Mar 8, 2016
numpy.linspace broken with Quantities with early numpy 1.10 -- documentation update

[ci skip]
eteq pushed a commit that referenced this pull request Mar 8, 2016
numpy.linspace broken with Quantities with early numpy 1.10 -- documentation update

[ci skip]
@eteq
Copy link
Member

eteq commented Mar 8, 2016

Backported to v1.0.x in 542f8c3 and v1.1.x in 12cbe2f

@mhvk mhvk deleted the linspace-not-working-with-numpy-1.10 branch March 18, 2016 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants