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 — BUG: `recarray` doesn't have a proper `_set_dtype` method ? · Issue #31295 · numpy/numpy

BUG: recarray doesn't have a proper _set_dtype method ? #31295

New issue
Copy link
New issue
Copy link
Closed
#31316
Closed
BUG: recarray doesn't have a proper _set_dtype method ?#31295
#31316
Copy link
Labels
00 - Bug

Description

@neutrinoceros
neutrinoceros
opened on Apr 21, 2026
Issue body actions

Describe the issue:

I'm trying to get rid of newly found deprecation warnings about dtype attribute setters in astropy.
There's one occurence in particular where I don't think we can use a view, so the next best thing would be _set_dtype, but it looks like it's not properly set on record arrays (it exists but it's a None)

self = <astropy.io.fits.hdu.table.BinTableHDU object at 0x10bf5f380>
data = rec.array([([ -939524096,           0],), ([ -637534208,  -939524096],),
           ([ -637534208, -1576992768],), ([ ...     ([-1090519040, -1157431040],), ([ -704643072,  2047082752],)],
          dtype=[('COMPRESSED_DATA', '<i4', (2,))])

    def _init_tbdata(self, data):
        columns = self.columns

        print(type(data))
>       data._set_dtype(data.dtype.newbyteorder(">"))
E       TypeError: 'NoneType' object is not callable

astropy/io/fits/hdu/table.py:212: TypeError

Reproduce the code example:

import numpy as np
a = np.array([1], dtype="float64").view(np.rec.recarray)
a._set_dtype("float64")

Error message:

Traceback (most recent call last):
  File "/Users/clm/dev/gh/neutrinoceros/astropy-compatibility-checks/numpy-dev/_astropy/t.py", line 3, in <module>
    a._set_dtype("float64")
    ~~~~~~~~~~~~^^^^^^^^^^^
TypeError: 'NoneType' object is not callable

Python and NumPy Versions:

2.5.0.dev0+git20260421.388bd75
3.14.3 (main, Feb  4 2026, 01:51:49) [Clang 21.1.4 ]

Runtime Environment:

No response

How does this issue affect you or how did you find it:

No response

Activity

  1. neutrinoceros
    added
    00 - Bug
    on Apr 21, 2026
  2. ikrommyd commented on Apr 21, 2026

    @ikrommyd
    ikrommyd
    on Apr 21, 2026
    Member
    More actions

    Just a curiosity of mine regarding your first snippet.
    Why doesn't

    data = data.view(data.dtype.newbyteorder(">"))

    work?

  3. seberg commented on Apr 22, 2026

    @seberg
    seberg
    on Apr 22, 2026
    Member
    More actions

    Yeah, this was somewhat intentional, but we could change it. It would be nice to not rely on _set_dtype all this much beyond finalization. (On first look, this does look like a case that shouldn't is very unsafe using _set_dtype, e.g. in threaded executation -- and not just free-threaded.)

    Is this something users would see or a very weird niche test?

  4. mhvk commented on Apr 22, 2026

    @mhvk
    mhvk
    on Apr 22, 2026
    Contributor
    More actions

    Oops, should have posted here: the addition of _set_dtype = None to np.recarray breaks a FITS_rec subclass in astropy. This means older astropy cannot be used with numpy 2.5. Personally, I don't think this is a disaster -- the fix is easy and can be backported (and people should not expect to be able to run newest numpy with older astropy), but I've raised it to ask for others' opinion. See astropy/astropy#19584.

    p.s. That said, I guess there is little wrong from the numpy side to postpone using _set_dtype = None for another version.

    Extra: I do think the use in FITS_rec can be replaced by views, though my initial attempt left one failing test, so I decided just to use ndarray._set_dtype for now. I'd still like to transition to views later...

  5. seberg commented on Apr 22, 2026

    @seberg
    seberg
    on Apr 22, 2026
    Member
    More actions

    Extra: I do think the use in FITS_rec can be replaced by views, though my initial attempt left one failing test, so I decided just to use ndarray._set_dtype for now. I'd still like to transition to views later...

    Ah missed that commenting on the astropy PR. That is unfortunate since it seems that the FITS code is precisely the kind of code that should use view (although I am not quite sure if everywhere -- some paths seem to restore the original dtype!).

  6. seberg commented on Apr 23, 2026

    @seberg
    seberg
    on Apr 23, 2026
    Member
    More actions

    OK... I am gaming out actually checking walking the MRO, which only leaves the __setattr__ path as a potentially regressing one (and too liberal downstream _set_dtype use, but I think that's on them).

    I think it should be around ~100 lines of code, but not too bad (plus tests), given that it should propel us into an even safer state, I think that is fine...
    It does mean we have to so a silly amount of attribute lookups for multi-level subclasses... But if we have multi-level subclasses, I think that should be pretty unproblematic...

    EDIT: And too be clear, after we are done with the .dtype = ... deprecation and everyone must use _set_dtype() we can delete that walking.

  7. seberg
    closed this as completedin #31316on Apr 28, 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

    00 - Bug

    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.