GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Dealing with deprecation of setting dtype in record arrays, and unitless times by mhvk · Pull Request #19584 · astropy/astropy

Conversation

@mhvk

@mhvk mhvk commented Apr 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR aims to ensure astropy does not raise any numpy deprecation warnings.

Note that the numpy 2.5 change to add _set_dtype = None to recarray (EDIT: in numpy/numpy#31293) means that in released versions of astropy, fits code will not work with numpy 2.5. I'll mention this upstream, though personally I feel people cannot simply expect to be able to upgrade to a newer numpy while sticking to an older astropy. Obviously, that does mean this should be backported.

@neutrinoceros - this PR includes your commit from #19578, to ensure we get all errors in one go.

Fixes #19579

  • 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mhvk mhvk added this to the v7.2.1 milestone Apr 22, 2026
@mhvk
mhvk requested review from neutrinoceros, saimn and taldcroft as code owners April 22, 2026 12:24
@mhvk mhvk added table io.fits time numpy-dev backport-v7.2.x on-merge: backport to v7.2.x labels Apr 22, 2026
@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown
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?
  • 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhvk mhvk added the no-changelog-entry-needed label Apr 22, 2026
This was referenced Apr 22, 2026
DEP: Correct dtype in __array_finalize__ if _set_dtype=None numpy/numpy#31293
Merged
BUG: incoming incompatibility between masked and numpy 2.5 (dev) #19579
Closed
BUG: recarray doesn't have a proper _set_dtype method ? numpy/numpy#31295
Closed
@seberg

seberg commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Coming over from NumPy, curious:

  • Without any changes (i.e. old astropy) is this really a break or just a DeprecationWarning? (Since _set_dtype() use was introduced very recently, I would guess it doesn't affect released astropy?)
  • Can't you use .view() here? Considering that this code even goes through the trouble of setting back the original dtype, it seems not using .view() is just a bunch of threading issues anyway?
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mhvk
mhvk commented Apr 22, 2026
View reviewed changes

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor Author

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.

@seberg - unfortunately, older astropy with new numpy will get real failures, since this subclass of recarray tries to set the dtype but that is circumvented by its inherited _set_dtype = None. If we want to solve that on the numpy side (still not clear to me we need to), I think we cannot yet introduce _set_dtype = None in recarray...

As for views, as commented in-line, for one case a view makes sense, but the other may be less so, as all the bytes are swapped in-place too (i.e., that whole _binary_table_byte_swap routine should be replaced, which is a bit trickier...)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread astropy/io/fits/hdu/table.py
else:
# TODO: see if a a view is possible still; initial trial gives
# error in test_table.py::TestVLATables::test_empty_vla_raw_data.
np.ndarray._set_dtype(data, data.dtype.newbyteorder(">"))

@mhvk mhvk Apr 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

This _set_dtype could fairly easily be changed into a .view(). See #19585 for that effort.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread astropy/io/fits/hdu/table.py
else:
# TODO: ensure self.data is never used with this context manager, so that
# a view here would work (and the second _set_dtype can be removed).
np.ndarray._set_dtype(data, new_dtype)

@mhvk mhvk Apr 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

A view here is possible, but not necessarily all that logical, since the array has also been byteswapped inplace. See #19595 for a rewrite that doesn't byteswap either.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@seberg

seberg commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

since this subclass of recarray tries to

Arggggg... So this is generally borked, sure these are crazy subclasses, but :(...

In theory, I suppose we would have to walk the subclasses: if dtype is higher in the __mro__ than _set_dtype then that it is preferred, otherwise, we can't use it in principle.
But that seems awful, propertys seem to tell you who they belong to, but Python methods don't trivially (and while I saw discussions around adding a C-API that would include that information, that doesn't exist).
(For this class, that probably wouldn't even work if it might use __getattr__, but dunno.)

Unless we make up some API so that _set_dtype advertises the dtype property it replaces, heh...

(Maybe this is all too super crazy, but...)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

neutrinoceros
neutrinoceros reviewed Apr 22, 2026
View reviewed changes

@neutrinoceros neutrinoceros left a comment

Copy link
Copy Markdown
Contributor

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.

thanks a lot for picking this up, I'm barely managing my task list these days

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread astropy/io/fits/hdu/table.py
if NUMPY_LT_2_5:
data.dtype = data.dtype.newbyteorder(">")
else:
# TODO: see if a a view is possible still; initial trial gives

@neutrinoceros neutrinoceros Apr 22, 2026

Copy link
Copy Markdown
Contributor

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.

to be clear, is the intention to handle this TODO before this is merged ? (if not, I'd rather have an open issue and no comment there)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mhvk mhvk Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

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.

See #19585...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

neutrinoceros reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread astropy/time/tests/test_basic.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mhvk mhvk mentioned this pull request Apr 22, 2026
View or index rather than explicitly set dtype and byteswap #19585
Merged
1 task done
@mhvk

mhvk commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

@neutrinoceros, @saimn - yes, I'd like to get rid of any dtype setting, and, after basically spending the day on it, came up with #19585.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mhvk added 3 commits April 23, 2026 09:53
@mhvk
MAINT: avoid dtype setting deprecation warning in io.fits (and wcs)
4ad895d
@mhvk
MAINT: Ensure tables use time unit when writing to pandas
99200be
@mhvk
TST: Ignore deprecation warnings indirectly raised by matplotlib
15b2c2c
@mhvk
mhvk force-pushed the numpy-dev-2.5-set-dtype-fixes branch from f89b7e3 to 15b2c2c Compare April 23, 2026 07:54
@mhvk mhvk mentioned this pull request Apr 23, 2026
TST: avoid a deprecation warning from numpy 2.5 (datetime64 without and explicit unit) #19578
Merged
1 task
neutrinoceros
neutrinoceros reviewed Apr 23, 2026
View reviewed changes
Comment thread astropy/time/tests/test_basic.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@neutrinoceros
Link follow up issue in a comment
7bf264a
neutrinoceros
neutrinoceros approved these changes Apr 23, 2026
View reviewed changes
@neutrinoceros
neutrinoceros enabled auto-merge April 23, 2026 08:04
@seberg

seberg commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Just as a note: I have not quite given up hope that we might find a slightly safer approach in NumPy. But, I think this solution will be fine either way, of course.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@neutrinoceros

neutrinoceros commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@seberg we're in this together ! thank you for your patience and continued support !

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@neutrinoceros
neutrinoceros merged commit a620e1e into astropy:main Apr 23, 2026
55 of 57 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@meeseeksmachine meeseeksmachine mentioned this pull request Apr 23, 2026
Backport PR #19584 on branch v7.2.x (Dealing with deprecation of setting dtype in record arrays, and unitless times) #19588
Merged
@mhvk
mhvk deleted the numpy-dev-2.5-set-dtype-fixes branch April 23, 2026 11:15
neutrinoceros added a commit that referenced this pull request Apr 23, 2026
@neutrinoceros @meeseeksmachine
Backport PR #19584: Dealing with deprecation of setting dtype in reco…
1c89ef1
…rd arrays, and unitless times
This was referenced Apr 27, 2026
Compatibility with numpy 2.5 spacetelescope/stdatamodels#716
Closed
Compatibility with numpy 2.5 spacetelescope/stsci.tools#199
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@neutrinoceros neutrinoceros neutrinoceros approved these changes
@taldcroft taldcroft Awaiting requested review from taldcroft taldcroft is a code owner
@saimn saimn Awaiting requested review from saimn saimn is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

backport-v7.2.x on-merge: backport to v7.2.x io.fits no-changelog-entry-needed numpy-dev table time

Projects

None yet

Milestone

v7.2.1

Development

Successfully merging this pull request may close these issues.

BUG: incoming incompatibility between masked and numpy 2.5 (dev)

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mhvk @seberg @neutrinoceros
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.