question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NumPy ABI does not successfully maintain forward compatibility -- should it?

See original GitHub issue

Not sure whether this is something we consider a bug, but flagging for potential discussion and so it doesn’t get lost: I hadn’t realized until today that NumPy in practice does not provide a forward compatible ABI, i.e., if you build with numpy 1.9 then try to run against 1.8, this may not work. Apparently packages that care about this like sklearn are actively working around this by carefully installing old versions of numpy before building wheels.

In particular, we have several times added extra fields to the dtype struct. In practice this is normally fine b/c no-one actually accesses these fields, but Cython in particular does struct size checking. For backwards compat – build against 1.8 and then run against 1.9 – the struct appears to get larger, and Cython merely issues a warning (which we suppress). For forward compat – build against 1.9 and then run against 1.8 – the struct appears to get smaller, and in this case Cython issues a hard error.

We could work around this by simply exposing a truncated struct to user code, so that Cython sees a small struct when doing sizeof, and the actual object is always larger then this, meaning that we always hit the warning path rather than the error path.

I don’t know if this is the only problem we would have to fix in order to achieve forward compatibility, e.g. I haven’t checked the C API import code to see what import_multiarray or import_umath do when they find themselves running against an older version of numpy.

If we want to take ABI compatibility seriously I guess we should probably also start requiring C API users to explicitly state which version of the ABI they expect, and enforce that they don’t get access to anything newer than that. This would at least give us the option then in the future to provide different versions of the same function to old-users and new-users.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:20 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
sebergcommented, Nov 20, 2022

Closing. This is effectively solved by https://pypi.org/project/oldest-supported-numpy/ and build requires. So we don’t attempt this, and thats that. (There is an interesting problem of ensuring that API break in the future is adhered to even though you compile against an older version, i.e. some compat headers, etc. This would be for a major NumPy 2.0 release, and something we need to figure out… But probably not on this issue.)

1reaction
mattipcommented, Jun 19, 2019

If I recall correctly, SciPy pins its build system to the oldest numpy it wishes to support, but tests against later numpy versions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

For downstream package authors — NumPy v1.23 Manual
If your package uses the C API, then ABI (application binary interface) stability of NumPy is important. NumPy's ABI is forward but not...
Read more >
ValueError: numpy.dtype has the wrong size, try recompiling
Numpy developers follow in general a policy of keeping a backward compatible binary interface (ABI). However, the ABI is not forward ...
Read more >
Mailman 3 Pre-PEP: Maintaining the Stable ABI - capi-sig
The Stable ABI is not generally forward-compatible: an extension built and tested with CPython 3.10 will not generally be compatible with CPython 3.9....
Read more >
SciPy Core Developer Guide
It fits the topic of the submodule, and does not require extensive support ... version (because NumPy's ABI is backward but not forward...
Read more >
First time rasterio error - GIS Stack Exchange
You may need to upgrade numpy (test this out in a virtualenv, don't break your system numpy) as the numpy ABI is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found