Skip to content

ENH: add getters for accessing struct fields in cython#30994

Merged
seberg merged 12 commits intonumpy:mainfrom
kumaraditya303:cython-static-inline
Mar 24, 2026
Merged

ENH: add getters for accessing struct fields in cython#30994
seberg merged 12 commits intonumpy:mainfrom
kumaraditya303:cython-static-inline

Conversation

@kumaraditya303
Copy link
Copy Markdown
Contributor

@kumaraditya303 kumaraditya303 commented Mar 12, 2026

PR summary

This PR adds getters for accessing struct fields in cython. In future these would call an ABI function to get the actual fields struct on opaque PyObject builds.

See #30704

AI Disclosure

No AI tools used

@kumaraditya303 kumaraditya303 added the 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) label Mar 12, 2026
Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks, this is nice. I am wondering a bit if it matters to bother with the ufunc code but probably it is just pragmatic.
(Mainly, while I could see doing something different, I can't think of a path forward short of just deleting it all and telling people to vendor a ufunc.pxd if they need it... -- but while that may even make sense, it isn't a minor relase thing.)

Copy link
Copy Markdown
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

We probably need to touch the C API docs as well. Historically any time we touch the C API docs we also notice a bunch of other issues and out-of-date docs, please feel free to ping me for help on that. I did a big docs change for the StringDType C API so I know where most of the skeletons in the closet are.

@kumaraditya303
Copy link
Copy Markdown
Contributor Author

We probably need to touch the C API docs as well.

I think it is too early to start working on the docs, IMO we should wait for the full implementation to land before working on docs because it is possible that we may end up removing or adding things later.

@ngoldbaum
Copy link
Copy Markdown
Member

IMO we should wait for the full implementation to land before working on docs because it is possible that we may end up removing or adding things later.

This PR adds new C API functions so we should update the C API docs to match. It's a really minor change though, see kumaraditya303#1.

@ngoldbaum
Copy link
Copy Markdown
Member

Let's also add a release note for the new C API macros too.

Copy link
Copy Markdown
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

Ping @seberg - maybe you want to look over the new docs?

Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks, looks good and nicer with just the struct getter. Let's see if anyone needs writeable access to the ufunc or descr in Cython.
At least the descr would make a little bit of sense, so we might need setters eventually.
But I'll doubt anyone creates new dtype objects in Cython, so it should be fine (and casting it to the struct isn't hard).

@seberg seberg merged commit b996b34 into numpy:main Mar 24, 2026
78 of 79 checks passed
@kumaraditya303 kumaraditya303 deleted the cython-static-inline branch March 24, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants