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 — Replace deprecated usage of numpy array shape, dtype and strides setting · Issue #18561 · astropy/astropy

Replace deprecated usage of numpy array shape, dtype and strides setting #18561

New issue
Copy link
New issue
Copy link
Closed
Closed
Replace deprecated usage of numpy array shape, dtype and strides setting#18561
Copy link
Labels
Refactoringnumpy-dev

Description

@eendebakpt
eendebakpt
opened on Aug 28, 2025
Issue body actions

In Numpy the direct setting of the dtype, shape and strides attributes is being deprecated as these operations are not safe (in particular in the free-threading build). See numpy/numpy#28800 for details.

Most direct setting of the attributes can be replaced with alternatives like array.view(dtype=...) or array.reshape(new_shape). These alternatives have a minor performance penalty (since a new object has to be created), but in general these methods create a view so no data is copied.

The astropy.utils.masked.Masked might be a bit more complex to convert, but can perhaps be handled in the same was as the numpy MaskedArray.

Update: most changes are mechanical changes for which no detailed knowledge of numpy or astropy is required. For a short description on how to approach this see scipy/scipy#23522 (comment)

Activity

  1. pllim
    added
    numpy-dev
    Refactoring
    on Aug 28, 2025
  2. pllim commented on Aug 28, 2025

    @pllim
    pllim
    on Aug 28, 2025
    Member
    More actions

    Thanks for this and the PR(s)!

  3. pllim commented on Aug 28, 2025

    @pllim
    pllim
    on Aug 28, 2025
    Member
    More actions

    The astropy.utils.masked.Masked might be a bit more complex to convert

    Hopefully @mhvk could advise there. 🙏

  4. eendebakpt commented on Aug 29, 2025

    @eendebakpt
    eendebakpt
    on Aug 29, 2025
    ContributorAuthor
    More actions

    For the dtype the number of changes is relatively small. A PR passing all tests is

    main...eendebakpt:numpy_dtype_deprecations

    There are two issues I found though:

    1. The PR used the private _set_dtype. That will be available once the PR in numpy is merged, but not be available in earlier numpy versions. This would mean astropy would have to write code depending on the numpy version. Not very hard, but not very elegant either. In an ideal world we would have added the _set_dtype already in the last numpy version supported by astropy.
    2. The method _init_tbdata from astropy/io/fits/hdu/table.py is used in only two places. From the code is looks like we can use a view to convert the data argument dtype (since at both places a view is applied to the data later), but this resulted in an error in the unit test test_table.py::TestVLATables::test_empty_vla_raw_data. It looks like the _init_tbdata is modyfying some global state (maybe via _get_raw_data which gets the .base of a recarray). If someone more familiar with the codebase could have a look, then perhaps there we can avoid the private dtype setter.

    @mhvk @seberg @ngoldbaum

  5. mhvk commented on Aug 29, 2025

    @mhvk
    mhvk
    on Aug 29, 2025
    Contributor
    More actions

    @eendebakpt - we're quite used to having numpy-version specific code paths; it would just require a from astropy.utils.compat import NUMPY_LT_2_4 and then use that.

    That said, for .dtype setting in particular, I do think it should never be needed (at least outside of uncertainties, and likely not there either). I'd need to look closer at the FITS code to see what the problem is there...

  6. emieczko commented on Sep 30, 2025

    @emieczko
    emieczko
    on Sep 30, 2025
    More actions

    Hi @mhvk @eendebakpt - I'm working on a school project involving contributing to an open-source project, and I was hoping to help out with this issue. I see that #18562 and #18599 address most of the work here, but I wanted to check with you guys to see if there was anything left that I could possibly work on; maybe looking for any leftover .dtype or .shape assignments elsewhere in the codebase?

    Any guidance you could provide on where I could help would be much appreciated!

  7. mhvk commented on Sep 30, 2025

    @mhvk
    mhvk
    on Sep 30, 2025
    Contributor
    More actions

    @emieczko - thanks! I think this particular issue is mostly done. It is also reasonable detailed, yet tedious, so perhaps not such a good one to work on. Generally, I'd recommend to pick something you're interested in yourself. Note that it doesn't have to be code: if while trying to use astropy for yourself, you find that the documentation is unclear or so, fixing that is most welcome too -- it is usually written by the people who wrote the code, who are not necessarily the best people to explain it.

  8. eendebakpt commented on Sep 30, 2025

    @eendebakpt
    eendebakpt
    on Sep 30, 2025
    ContributorAuthor
    More actions

    @emieczko I agree with @mhvk. However, you are interested in working on the dtype, shape and stride deprecation, there are other packages where this still needs to be done. In short:

    • Install numpy with the deprecation branches on your local system (the strides is merged to numpy, the others not yet)
    • Pick a package (pandas, scikit-learn, matplotlib). Run the test suit for that package, looking out for errors and deprecation warnings
    • If needed, report the deprecations using an issue on the git repo and/or submit a PR to address the issue

    If interested, you can reach out to me via email or on discuss.python.org

  9. jodamatta commented on Apr 29, 2026

    @jodamatta
    jodamatta
    on Apr 29, 2026
    More actions

    Hi there! just like emieczko, i'm working on a school project to contribute to open source software (particularly refactoring issues). Is there anything left over from this issue i could help with? Thanks! @mhvk

  10. neutrinoceros commented on Apr 29, 2026

    @neutrinoceros
    neutrinoceros
    on Apr 29, 2026
    Contributor
    More actions

    I don't think there is, deprecation warnings show up as hard errors in our CI and we're very diligent in fixing them as the come. It might be that I'm misremembering parts of the problem and that we're not actually done, but checking this takes time and we have other priorities right now... so, unless your program only counts PRs as "contributions", we could actually use a hand with answering your question. In my book, triage is a very valuable contribution, though I'd understand if your school disagrees.

  11. mhvk commented on Apr 29, 2026

    @mhvk
    mhvk
    on Apr 29, 2026
    Contributor
    More actions

    I indeed think this particular issue is done, indeed I'm confident enough to just go ahead and close it.

  12. mhvk
    closed this as completedon Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Refactoringnumpy-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.