Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 2 commits into from
Nov 14, 2023
Merged

Remove obsolete known issues #15609

merged 2 commits into from
Nov 14, 2023

Conversation

eerovaher
Copy link
Member

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 a float. However, trying to do that raises a very clear warning:

>>> from astropy import units as u
>>> float((1j * u.m).value)
<stdin>:1: ComplexWarning: Casting complex values to real discards the imaginary part
0.0

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.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

This reverts commit f869eec.

The entry is obsolete since 3beb2f4
(Drop support for Numpy 1.21).
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.
@eerovaher eerovaher added this to the v6.0 milestone Nov 13, 2023
Copy link
Contributor

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.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@pllim pllim added the units label Nov 13, 2023
@pllim pllim requested review from mhvk and nstarman November 13, 2023 17:58
@namurphy
Copy link
Contributor

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 float on Quantity objects now appears to give the same result with the ComplexWarning regardless of whether the Quantity was created from a complex or a numpy.complex128. Since there are warnings and exceptions in all of the above cases, I'm okay with removing this section.

Related to #10010, #10014, & numpy/numpy#13007.

Copy link
Contributor

@mhvk mhvk left a 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.

@mhvk mhvk merged commit bc80072 into astropy:main Nov 14, 2023
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Nov 14, 2023
mhvk added a commit that referenced this pull request Nov 14, 2023
…609-on-v6.0.x

Backport PR #15609 on branch v6.0.x (Remove obsolete known issues)
@eerovaher eerovaher deleted the clean-known-issues branch November 14, 2023 17:34
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.

4 participants