Skip to content
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

Fix NumPy deprecation of setting np.int16 with out-of-bound value #13835

Merged
merged 2 commits into from
Oct 18, 2022

Conversation

dhomeier
Copy link
Contributor

@dhomeier dhomeier commented Oct 13, 2022

Description

This pull request is to address deprecation in NumPy 1.24 of implicit casting of np.int types with out-of-bond numbers (thus forcing an overflow); replacing this with an explicit np.array(a).astype(np.int16)

Fixes #13834

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • 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 "When to rebase and squash commits".
  • 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 astropy-bot check might be missing; 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.

@github-actions
Copy link

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@pllim pllim added this to the v5.0.5 milestone Oct 13, 2022
@pllim pllim added 💤 backport-v5.0.x on-merge: backport to v5.0.x 💤 backport-v5.1.x on-merge: backport to v5.1.x testing labels Oct 13, 2022
@dhomeier dhomeier marked this pull request as ready for review October 13, 2022 14:46
@dhomeier dhomeier requested a review from saimn as a code owner October 13, 2022 14:46
n[0] = 1
n[1] = 60000
n[2] = 2
n = np.array([1, 60000, 0]).astype('i2')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has been pure luck that this test worked -- that it wrapped around automatically. I think we should just be explicit and write n[1] = 60000 - 65536

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But by construction fits.Column is setting it with a int16 that is declared to be interpreted as uint16, so would make sense to create it this way. Or perhaps a bit more explicitly
np.array([1, 60000, 0], dtype=np.uint16).astype(np.int16)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's true. Maybe use your more explicit route?

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.

Don't want to hold up this nice fix for no reason, so let me approve. If you have the oomph to add the dtype='u2', then please do, otherwise also fine to just merge.

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.

Thanks!

@saimn saimn merged commit 3b44881 into astropy:main Oct 18, 2022
@saimn
Copy link
Contributor

saimn commented Oct 18, 2022

Thanks!

meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Oct 18, 2022
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Oct 18, 2022
saimn added a commit that referenced this pull request Oct 18, 2022
…835-on-v5.1.x

Backport PR #13835 on branch v5.1.x (Fix NumPy deprecation of setting `np.int16` with out-of-bound value)
saimn added a commit that referenced this pull request Oct 19, 2022
…835-on-v5.0.x

Backport PR #13835 on branch v5.0.x (Fix NumPy deprecation of setting `np.int16` with out-of-bound value)
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.

TST: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays
4 participants