Skip to content

TST: add tests for stable ABI numpy extensions - #31822

Merged
kumaraditya303 merged 18 commits into
numpy:mainfrom
kumaraditya303:abi-tests
Jul 6, 2026
Merged

TST: add tests for stable ABI numpy extensions#31822
kumaraditya303 merged 18 commits into
numpy:mainfrom
kumaraditya303:abi-tests

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

PR summary

This PR adds tests for stable ABI extensions compiled with numpy C-API as well as cython API.
limited_api.c is used as a template and parameterized by MODULE_NAME for every combination of Python abi3 version and NumPy target version. Same is done for limited_api_cython where cython extension is tested against every combination of Python abi3 version and NumPy target version. I've expanded tests to cover the datetime APIs which was broken recently to avoid such future breakages.

The failing MSVC test on x86 is because of #31762 which is now detected as a failure.

AI Disclosure

I used Claude to work on this.

@kumaraditya303
kumaraditya303 marked this pull request as ready for review July 1, 2026 10:55
@kumaraditya303

kumaraditya303 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Seems like gcc 9 which is used in the failing old_gcc CI does not support taking address of opaque pointer while de-referencing it. In Limited C-API PyTypeObject is opaque and previously the tests were empty so this was missed, we may need to skip this on such old gcc compilers.

rror: dereferencing pointer to incomplete type ‘PyTypeObject’ {aka ‘struct _typeobject’}
   1156 | #define PyTimedeltaArrType_Type (*(PyTypeObject *)PyArray_API[216])
        |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /opt/hostedtoolcache/Python/3.12.13/x64/include/python3.12/object.h:384:80: note: in definition of macro ‘PyObject_TypeCheck’
    384 | #  define PyObject_TypeCheck(ob, type) PyObject_TypeCheck(_PyObject_CAST(ob), (type))
        |                                                                                ^~~~
  limited_api_cython_3_9_npy2_0.abi3.so.p/limited_api_cython.pyx.c:5078:47: note: in expansion of macro ‘PyTimedeltaArrType_Type’
   5078 |   __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type));
        |                                               ^~~~~~~~~~~~~~~~~~~~~~~

@kumaraditya303
kumaraditya303 requested a review from seberg July 1, 2026 11:01
@seberg
seberg requested a review from ngoldbaum July 1, 2026 11:03
Comment thread numpy/_core/tests/examples/limited_api/meson.build Outdated
Co-authored-by: da-woods <dw-git@d-woods.co.uk>
@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Jul 1, 2026
@ngoldbaum

Copy link
Copy Markdown
Member

We talked about this at the community meeting and no one objected to dropping gcc9 from the CI matrix. I'm going to put in a PR to do that.

@ngoldbaum ngoldbaum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks pretty good. I left some comments inline.

Comment thread numpy/_core/tests/test_limited_api.py
Comment thread numpy/_core/tests/test_limited_api.py Outdated
Comment thread numpy/_core/tests/test_limited_api.py Outdated
Comment thread numpy/_core/tests/examples/limited_api/limited_api.c Outdated
Comment thread numpy/_core/tests/examples/limited_api/meson.build Outdated
Comment thread numpy/_core/tests/examples/limited_api/limited_api.c
Comment thread numpy/_core/tests/examples/limited_api/limited_api.c Outdated
Comment thread numpy/_core/tests/examples/limited_api/limited_api_cython.pyx
Comment thread numpy/_core/tests/test_limited_api.py Outdated
Comment thread numpy/_core/tests/test_limited_api.py Outdated
@ngoldbaum

Copy link
Copy Markdown
Member

I think if you rebase on or merge with main the error will go away because #31843 is merged.

@ngoldbaum ngoldbaum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I did one more review pass and caught a couple minor issues and one suggestion about testing without NPY_TARGET_VERSION that I missed on the last pass. Otherwise I think this looks great so I'm approving. Please go ahead and merge this once you've addressed this last round of comments.

Comment thread numpy/_core/tests/examples/limited_api/meson.build Outdated
Comment thread numpy/_core/tests/test_limited_api.py Outdated
Comment thread numpy/_core/tests/test_limited_api.py Outdated
Comment thread numpy/_core/tests/examples/limited_api/limited_api_cython.pyx
@kumaraditya303
kumaraditya303 merged commit afeda72 into numpy:main Jul 6, 2026
85 checks passed
@kumaraditya303
kumaraditya303 deleted the abi-tests branch July 6, 2026 14:10
@charris

charris commented Jul 6, 2026

Copy link
Copy Markdown
Member

Missed the cython version check in meson.build. I'll fix that.

@charris

charris commented Jul 6, 2026

Copy link
Copy Markdown
Member

See #31875.

MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request Jul 7, 2026
Co-authored-by: da-woods <dw-git@d-woods.co.uk>
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 7, 2026
charris pushed a commit that referenced this pull request Jul 7, 2026
Co-authored-by: da-woods <dw-git@d-woods.co.uk>
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
charris added a commit that referenced this pull request Jul 7, 2026
TST: add tests for stable ABI numpy extensions (#31822)
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.

4 participants