-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Numpy style changes #6090
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 style changes #6090
Conversation
|
As this seems to have solved the fixes #6089 |
adrn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, but mainly questions (sorry for asking so many!).
astropy/units/tests/test_quantity.py
Outdated
| if NUMPY_LT_1_14: | ||
| assert repr(self.scalarfloatq) == "<Quantity 1.3 m>" | ||
| else: | ||
| assert repr(self.scalarfloatq) == "<Quantity 1.3 m>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. I know you're probably just making changes to make it consistent with what numpy does, but seems strange that an extra space is added here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The array style always has a place for the sign.
docs/coordinates/angles.rst
Outdated
| <Angle 3.5 rad> | ||
| >>> np.sin(a / 2) # doctest: +FLOAT_CMP | ||
| <Quantity 0.479425538604203> | ||
| >>> a == a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this get removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get doctest to think both ( True and (True were the same thing, and I thought this example was sufficiently trivial (and repeated below) that I could just remove it.
| >>> g = Gaussian1D(amplitude=1, mean=0, stddev=1) | ||
| >>> g | ||
| <Gaussian1D(amplitude=1.0, mean=0.0, stddev=1.0)> | ||
| >>> g # doctest: +FLOAT_CMP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If FLOAT_CMP is needed here, what do the actual repr's end up looking like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For old numpy, 1.0, for new numpy 1.
docs/nddata/subclassing.rst
Outdated
|
|
||
| >>> ndd = NDDataMaskBoolNumpy([1,2,3]) | ||
| >>> ndd.mask = True | ||
| >>> ndd.mask = True, False, True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is valid, but maybe we want to make it [True, False, True] to be more explicit? This might look strange to new users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done
| >>> import numpy as np | ||
| >>> np.exp((1j*0.125*u.cycle).to('', equivalencies=u.dimensionless_angles())) # doctest: +FLOAT_CMP | ||
| <Quantity (0.7071067811865476+0.7071067811865475j)> | ||
| >>> np.exp((1j*0.125*u.cycle).to('', equivalencies=u.dimensionless_angles())) # doctest: +SKIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this skipped now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New numpy removes the parentheses around the complex number; I didn't know how to get doctest to accept both as valid...
| >>> u.Magnitude(15.) | ||
| <Magnitude 15.0 mag> | ||
| >>> u.Magnitude(10.*u.count/u.second) | ||
| >>> u.Magnitude(12.5) # doctest: +FLOAT_CMP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all these FLOAT_CMP necessary? The float format usually isn't messed up when no arithmetic is done, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this particular one is actually not necessary -- the real reason is to ensure that nnn.0 and nnn. are treated as being the same -- and here I changed to nnn.5 for that reason.
|
@mhvk - Looks good to me. A bit more |
|
@bsipocz - good point about the docstrings; I'll see if for those I can try a bit harder not to use |
|
This is OK, but let's hold off a little as there is some discussion in numpy/numpy#8983 (comment) about whether the effects of the change were all that good (though I'd guess that would only lead to more/other edits...) |
|
@mhvk - I guess there is still no clear decision upstream, so I'm moving the milestone of this to the next bugfix release. |
|
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 labelled 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 |
af2c87f to
9b7f675
Compare
|
@mhvk - Not backporting this would mean that the LTS version wont support 1.14. Do we really want that? |
|
@bsipocz - I think this is mostly up to you - do you think this is easy enough to backport? |
|
Note to whoever reviews: to make tests pass, I had to modify |
|
@mhvk - if the rebase was relatively easy, then backporting shouldn't be too messed up either (I hope at least). |
|
@mhvk - This looks uncontroversial to me, but if you think otherwise please assign someone to do the review. |
|
Re: |
|
Agreed this should be uncontroversial, so maybe you can give the required OK? And then perhaps we move the |
|
I agree that it's better to move the |
|
Thanks very much @mhvk! |
|
Finally things should work with numpy-dev again! |
https//:github.com/astropy/astropy/pull/6090
Numpy style changes
Numpy style changes
fixes #6086
numpy
1.131.14 changes the formatting of float scalars, to be identical to what is used for arrays. This is a good thing in principle, but breaks a lot of doctests. Furthermore,array2stringnow has thestylekeyword deprecated.This PR hopefully addresses both issues.
I'm putting the milestone at 2.0, since it may not be worth backporting... EDIT: especially since the real change is for numpy 1.14, not 1.13.