-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Remove obsolete known issues #15609
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
Remove obsolete known issues #15609
Conversation
This reverts commit 1a03364. Trying to convert a complex-valued `Quantity` to a float raises a very clear warning and the known issues entry did not provide any additional useful information.
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
That is a very good question. Thank you for revisiting this! I remember getting tripped up by this in a unit test because the warning got hidden amongst a bunch of other warnings from the full test suite. I tried the following with Python 3.11, NumPy 1.24, and Astropy 5.3.1: >>> import numpy as np, astropy.units as u, warnings
>>> warnings.filterwarnings("always")
>>> float(5+5j) # regular complex number
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: float() argument must be a string or a real number, not 'complex'
>>> float(np.complex128(5+5j)) # NumPy complex number
<stdin>:1: ComplexWarning: Casting complex values to real discards the imaginary part
5.0
>>> float(u.Quantity(5+5j, u.dimensionless_unscaled)) # Quantity from Python complex number
.../astropy/units/quantity.py:1350: ComplexWarning: Casting complex values to real discards the imaginary part
return float(self.to_value(dimensionless_unscaled))
5.0
>>> float(u.Quantity(np.complex128(5+5j), u.dimensionless_unscaled)) # Quantity from NumPy complex number
.../astropy/units/quantity.py:1350: ComplexWarning: Casting complex values to real discards the imaginary part
return float(self.to_value(dimensionless_unscaled))
5.0 Using Related to #10010, #10014, & numpy/numpy#13007. |
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'm OK with removing both. The numpy behaviour of dropping imaginary is certainly surprising, but there is a warning, and it certainly is not astropy's problem since Quantity
just behaves the same way as ndarray
.
…609-on-v6.0.x Backport PR #15609 on branch v6.0.x (Remove obsolete known issues)
Description
The first commit here removes a known issues entry about
numpy<1.21.1
that was made obsolete by 3beb2f4. Removing it is obviously the correct thing to do.The second commit might be more controversial. The entry it removes describes possible unexpected behavior when converting a complex-valued
Quantity
to afloat
. However, trying to do that raises a very clear warning:It doesn't seem to me like the known issues entry is adding any useful information to what the warning message already contains, so I don't see a good reason for keeping it around. But I'll ping @namurphy, who authored 1a03364, and @bsipocz, who reviewed and merged it. Maybe they can point out something that I'm missing.