Numpy 1.14 style changes - #6959
Conversation
|
Hi there @mhvk 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃. Everything looks good from my point of view! 👍 If there are any issues with this message, please report them here. |
e4cd13d to
4438383
Compare
|
Ah, I had forgotten about that earlier discussion! I think if we can backport this without too much trouble, then, yes, let's do it (given that 2.0 is LTS). |
|
The backport was surprisingly easy, there were some minor conflict only (and I hope git didn't mess up the automated ones). |
4438383 to
601ecbc
Compare
|
This now should have everything alright except for the new problems introduced by #6859. |
601ecbc to
0fd8b13
Compare
| 15.0 | ||
| 17.0 | ||
| 15.7 | ||
| >>> print(obs_by_name['mag_b'].groups.aggregate(np.mean)) # doctest: +SKIP |
There was a problem hiding this comment.
I looked at this on my cell phone 30 minutes ago and these values looked horrible (like 15.000000000002) and there was a doctest FLOAT_COMPARE. Now it's just skipped. What is the actual now?
There was a problem hiding this comment.
They do look horrible on numpy 1,14 - I think this is due to a change in how scalars are represented - they don't necessarily go through arrayprint any more, but rather always are represented such that the value is uniquely defined. I'm going to raise a separate issue for that, but here just want to be sure tests will continue to pass when the 1.14rc hits pypi.
0fd8b13 to
afdd9eb
Compare
| <TD>268435456</TD> | ||
| <TD>922337203685477</TD> | ||
| <TD>8.9999990000000007</TD> | ||
| <TD>8.9990234375</TD> |
There was a problem hiding this comment.
I changed the example such that it is 9 - 1/2**10 and thus exactly representable.
There was a problem hiding this comment.
I think "8.9999990000000007" was designed for a purpose (perhaps to test floating point precision), so I am not comfortable with this change. Is there no way to make test pass without changing the file?
There was a problem hiding this comment.
I think this is actually OK:
In [1]: 8.9999990000000007 == 8.999999
Out[1]: True
Previously, numpy just put out a large number of digits, so that one was sure that a number was well-represented, but it didn't not check it could be done with fewer; now it puts out just the right number (see above).
It also seems clear the "truth" was generated once, and is now tested against. The actual input file (regression.xml) does in fact had 8.999999 (and with numpy 1.14, that is what you get out; older versions are the ones that are problematic).
There was a problem hiding this comment.
Alright, you're the numpy expert here, so I'll just go with the flow.
| >>> nd2 = NDDataSliceable(nd, mask=mask) | ||
| >>> nd2[1:3].mask | ||
| array([False, True], dtype=bool) | ||
| >>> nd2slc = nd2[1:3] |
There was a problem hiding this comment.
Avoid showing a bool array since dtype=bool has disappeared.
|
|
||
| def test_setting_uncertainty_wrong_shape_raises_error(ccd_data): | ||
| with pytest.raises(ValueError): | ||
| ccd_data.uncertainty = np.random.random(size=2 * ccd_data.shape) |
There was a problem hiding this comment.
Oops, this made a 100,100,100,100 array (which is a bit much for my 2GB laptop)
There was a problem hiding this comment.
Yeah, I already fixed that downstream (astropy/ccdproc#579) but forgot that the test had been copied over...
| '------ ------- ------- ---- ----{0}' | ||
| 'target -- -- -- --{0}' | ||
| ' V_mag 12.8667 1.72111 11.1 15.2{0}').format(os.linesep) | ||
| if NUMPY_LT_1_14: |
There was a problem hiding this comment.
We really shouldn't be testing float output!
There was a problem hiding this comment.
We can maybe use another table, could you check the output with astropy/io/ascii/tests/t/simple_csv.csv ? (I don't have time to install numpy 1.14 right now, maybe later today or tomorrow):
❯ showtable astropy/io/ascii/tests/t/simple_csv.csv --stats
<Table length=2>
name mean std min max
---- ---- --- --- ---
a 2.5 1.5 1 4
b 3.5 1.5 2 5
c 4.5 1.5 3 6
There was a problem hiding this comment.
I think this is a case where we should be testing non-nice floating point values. The whole point of showtable is creating human-readable output that is informative and "pleasant". So using real-world values is important to catch formatting issues that our users will end up seeing.
There was a problem hiding this comment.
@taldcroft, @saimn - yes, although it may be that we have to define what is pleasant ourselves rather than rely on numpy doing it for us. But let's discuss in #6962, as it is somewhat orthogonal to the point of this PR, which is simply to get things to pass with numpy 1.14.x.
There was a problem hiding this comment.
Agreed about moving the discussion to #6962 , so the current change is fine by me.
| >>> delta, status = t.get_delta_ut1_utc(return_status=True) | ||
| >>> status == TIME_BEFORE_IERS_RANGE | ||
| array([ True, False], dtype=bool) | ||
| array([ True, False]...) |
There was a problem hiding this comment.
Yes, ugly, but don't know what else to do...
| """ | ||
|
|
||
| filename = tmpdir.join(self.filename).strpath | ||
| filename = str(tmpdir.join(self.filename)) |
There was a problem hiding this comment.
This allows one to call tests from ipython without having a tmpdir (no idea where to import it from)
There was a problem hiding this comment.
@mhvk I just noticed that there are 5 other instances in this file also using .strpath (lines 23, 28, 33, 42, and 54). Do those need to be changed also?
There was a problem hiding this comment.
A quick search reveals that there are a lot of tests across astropy that use tmpdir .strpath. Is a larger PR needed?
There was a problem hiding this comment.
Yes, you're right, we should probably change all. It may be easiest if I remove this commit from the PR, since it is really not numpy-dev related.
| >>> jup # doctest: +FLOAT_CMP +REMOTE_DATA | ||
| <SkyCoord (GCRS: obstime=2014-09-22 23:22:00.000, obsgeoloc=( 3949481.689878457, -550931.9118838, 4961151.73733447) m, obsgeovel=( 40.1745933, 288.00078051, 0.) m / s): (ra, dec, distance) in (deg, deg, AU) | ||
| ( 136.91116201, 17.02935408, 5.94386022)> | ||
| <SkyCoord (GCRS: obstime=2014-09-22 23:22:00.000, obsgeoloc=(3949481.68990863, -550931.91188162, 4961151.73733451) m, obsgeovel=(40.15954083, 287.47876693, -0.04597867) m / s): (ra, dec, distance) in (deg, deg, AU) |
There was a problem hiding this comment.
Not completely sure why this didn't fail before: the new baryvel has z component of geovel != 0.
There was a problem hiding this comment.
yeah, that's weird... I'm seeing the same as you, and that has nothing to do with numpy... maybe it's some weird quirk of the FLOAT_CMP? Anyway, looks fine to me
| fill_value = 1e+20) | ||
| <BLANKLINE> | ||
| >>> 2 * np.ones(3) * ccd_masked # one return value will be masked # doctest: +SKIP | ||
| masked_array(data=[2.0, 4.0, --], |
There was a problem hiding this comment.
Don't know how to get doctest to pass both old and new format...
| >>> ndd4.mask | ||
| array([False, True, False], dtype=bool) | ||
|
|
||
| or even a masked Quantity:: |
There was a problem hiding this comment.
I don't think we should encourage this in any way! Also, it looks very different in numpy 1.14 (probably a buglet)
21e1597 to
92e3c3c
Compare
pllim
left a comment
There was a problem hiding this comment.
I am not comfortable with changing actual file values for votable tests.
| <TD>268435456</TD> | ||
| <TD>922337203685477</TD> | ||
| <TD>8.9999990000000007</TD> | ||
| <TD>8.9990234375</TD> |
There was a problem hiding this comment.
I think "8.9999990000000007" was designed for a purpose (perhaps to test floating point precision), so I am not comfortable with this change. Is there no way to make test pass without changing the file?
|
I agree that io.fits looks good. I also basically approve the changes made in nddata, but I hope that either @crawfordsm or @mwcraig could also have a look. |
| """ | ||
|
|
||
| filename = tmpdir.join(self.filename).strpath | ||
| filename = str(tmpdir.join(self.filename)) |
| <TD>268435456</TD> | ||
| <TD>922337203685477</TD> | ||
| <TD>8.9999990000000007</TD> | ||
| <TD>8.9990234375</TD> |
There was a problem hiding this comment.
Alright, you're the numpy expert here, so I'll just go with the flow.
eteq
left a comment
There was a problem hiding this comment.
LGTM as far as coordinates are concerned
| >>> jup # doctest: +FLOAT_CMP +REMOTE_DATA | ||
| <SkyCoord (GCRS: obstime=2014-09-22 23:22:00.000, obsgeoloc=( 3949481.689878457, -550931.9118838, 4961151.73733447) m, obsgeovel=( 40.1745933, 288.00078051, 0.) m / s): (ra, dec, distance) in (deg, deg, AU) | ||
| ( 136.91116201, 17.02935408, 5.94386022)> | ||
| <SkyCoord (GCRS: obstime=2014-09-22 23:22:00.000, obsgeoloc=(3949481.68990863, -550931.91188162, 4961151.73733451) m, obsgeovel=(40.15954083, 287.47876693, -0.04597867) m / s): (ra, dec, distance) in (deg, deg, AU) |
There was a problem hiding this comment.
yeah, that's weird... I'm seeing the same as you, and that has nothing to do with numpy... maybe it's some weird quirk of the FLOAT_CMP? Anyway, looks fine to me
mwcraig
left a comment
There was a problem hiding this comment.
The nddata pieces of this look goo to me. Thanks for taking this on!
| >>> ndd4.mask | ||
| array([False, True, False], dtype=bool) | ||
|
|
||
| or even a masked Quantity:: |
|
@mhvk - can you rebase? Also I think this got approval from each relevant submodule lead or deputy, so ready to go. |
Use a double that is exactly representable: 9 - 1/2**10 instead of 8.999999 which gets represented as 8.999999000007 (or so) on numpy <1.14.
In the process, changed one test that took a lot of memory as it created a random array of shape 100,100,100,100. Also removed all mention of masked Quantities, as these really are not supported, and should not be encouraged to be used in any way.
Note: cannot do MaskedArray sensibly, so just skipping those.
92e3c3c to
8b935fb
Compare
|
passing and approved, so I'm merging this now! |
|
Enormous thanks @mhvk for keeping us compatible with the latest and greatest and even the future numpy! |
Numpy 1.14 is being branched, so it seemed time to ensure we're passing all tests.
EDIT: commits are by module - feel free to just look at relevant commits! Check-list for review:
An annoyance is that
boolarrays are now represented withoutdtype=bool(since that is obvious from the content), which meant that every time this was done in doctest, I had to add..., which is rather ugly.Furthermore, the
reprofMaskedArrayhas become much more logical, but that means our doctests cannot work on both new and old - hence, I just skipped those (after adjusting to the new style).