Skip to content

Numpy dev array printing - update all tests to new numpy style - #5423

Merged
mhvk merged 5 commits into
astropy:masterfrom
mhvk:numpy_dev_array_printing
Oct 28, 2016
Merged

mhvk merged 5 commits into
astropy:masterfrom
mhvk:numpy_dev_array_printing

Conversation

@mhvk

@mhvk mhvk commented Oct 20, 2016

Copy link
Copy Markdown
Contributor

This PR changes how representations are represented on the screen, by backporting the new array2string style for structured arrays. This should solve the remaining bugs with numpy-dev reported in #5419. The first commit changes all tests that failed with the new numpy 1.12 development candidate to match the new style, and the second contains the backport.

Obviously, there is a bit of a question what to do anytime a code change leads to a different "visual appearance". Ideally, we wouldn't test for it at all: the only thing that matters should be whether numbers are correct. But there were so many doctests that failed that I felt it was better to bite the bullet...

@mhvk

mhvk commented Oct 21, 2016

Copy link
Copy Markdown
Contributor Author

@taldcroft, @astrofrog, @adrn: this PR makes tests pass on numpy-dev, but at the price of changing how coordinate output looks, to match what the new numpy array2print does for structured arrays. I think it it the right way forward, but would like to be sure there is agreement.

Just to be a bit clearer about the situation: With current master, you'll get different-looking output depending on whether you use a numpy release or the development version; with this PR, the output is always like that with the development version. To get a sense of how things change:

import astropy.units as u
from astropy.coordinates import SphericalRepresentation
r1 = SphericalRepresentation(lon=1 * u.deg, lat=2.5 * u.deg, distance=1 * u.kpc)
r2 = SphericalRepresentation(lon=[1,20,-3, -3, 2, 1] * u.deg, lat=[2.5,0,-2.5, -2.5, 1, 1] * u.deg, distance=1 * u.kpc)
r1
# numpy <1.12, current master
<SphericalRepresentation (lon, lat, distance) in (deg, deg, kpc)
    (1.0, 2.5, 1.0)>
# numpy dev current master/this PR any numpy
<SphericalRepresentation (lon, lat, distance) in (deg, deg, kpc)
    ( 1.,  2.5,  1.)>
#
r2
# numpy <1.12, current master
<SphericalRepresentation (lon, lat, distance) in (deg, deg, kpc)
    [(1.0, 2.5, 1.0), (20.0, 0.0, 1.0), (357.0, -2.5, 1.0),
     (357.0, -2.5, 1.0), (2.0, 1.0, 1.0), (1.0, 1.0, 1.0)]>
# numpy-dev, current master/this PR, any numpy
<SphericalRepresentation (lon, lat, distance) in (deg, deg, kpc)
    [(   1.,  2.5,  1.), (  20.,  0. ,  1.), ( 357., -2.5,  1.),
     ( 357., -2.5,  1.), (   2.,  1. ,  1.), (   1.,  1. ,  1.)]>

You see that three things happened: trailing 0 are omitted; there is always either a space or - sign; numbers are aligned nicely vertically.

What do you think? Is the change for the better? If you look at representation.py, you'll see that there was some code there in __repr__ to try to mimic numpy array printing, but it was incomplete. So, in that sense, I think this PR just does what was originally intended.

Now there is an alternative that is worth considering: should we really care how output looks at all, as long as numbers are actually present (and correct, of course)? If so, we should remove or rewrite the tests that fail with current master and numpy-dev, and also find a way for doctests to work irrespective of formatting. Overall, I felt changing the tests made more sense, since I do not think this is going to change again soon...

@taldcroft

Copy link
Copy Markdown
Member

@mhvk - I prefer the new-style formatting overall and definitely vote for consistency across numpy versions. So 👍 from me.

@adrn

adrn commented Oct 23, 2016

Copy link
Copy Markdown
Member

@mhvk I think the new formatting looks much cleaner. I also agree that we should just check for correctness and not formatting in the tests!

@mhvk
mhvk force-pushed the numpy_dev_array_printing branch from 7660ce5 to a89fd77 Compare October 25, 2016 20:50
@mhvk

mhvk commented Oct 25, 2016

Copy link
Copy Markdown
Contributor Author

(Rebased following merger of #5254)

mhvk added 3 commits October 28, 2016 12:14
For representations, this changes the expected output; for the one
failing fits table test, it simply allows for different style output.
@mhvk
mhvk force-pushed the numpy_dev_array_printing branch from b278bea to efa01b6 Compare October 28, 2016 11:17
@mhvk
mhvk force-pushed the numpy_dev_array_printing branch from efa01b6 to f1dd34d Compare October 28, 2016 12:16
@mhvk

mhvk commented Oct 28, 2016

Copy link
Copy Markdown
Contributor Author

The one remaining failure with numpy-dev is unrelated to this PR (and on its way to being fixed; numpy/numpy#8218). Since there was general agreement on this change in printing, I'll merge this now.

@mhvk
mhvk merged commit 9299049 into astropy:master Oct 28, 2016
@mhvk
mhvk deleted the numpy_dev_array_printing branch October 28, 2016 12:47
@eteq

eteq commented Dec 21, 2016

Copy link
Copy Markdown
Member

This is exceedingly difficult to backport do to conflicts almost everywhere, so re-classifying to 1.3.x . We can re-visit this if we feel we need 1.0.x tests with numpy-dev, but my sense is that this is not critical...?

@eteq eteq modified the milestones: v1.3.0, v1.0.11 Dec 21, 2016
@pllim

pllim commented Dec 21, 2016

Copy link
Copy Markdown
Member

Re: Backport and numpy-dev. IMHO, whoever still using 1.0.x is unlikely to be using numpy-dev, so my vote is "not critical."

@bsipocz

bsipocz commented Dec 21, 2016

Copy link
Copy Markdown
Member

I agree with @pllim here. Whomever is flexible enough to upgrade to numpy 1.12, should be flexible enough to upgrade to astropy 1.3.

@mhvk

mhvk commented Dec 21, 2016

Copy link
Copy Markdown
Contributor Author

Yes, agreed, especially as it only affects running the tests, not using actual code.

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.

6 participants