Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with NumPy 2.0 #1972

Open
8 of 10 tasks
jorisvandenbossche opened this issue Jan 24, 2024 · 8 comments
Open
8 of 10 tasks

Compatibility with NumPy 2.0 #1972

jorisvandenbossche opened this issue Jan 24, 2024 · 8 comments
Milestone

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Jan 24, 2024

NumPy 2.0 is coming soon, and we should ensure shapely is fully compatible to ensure a smooth transition of our users. Overview issue on numpy's side:

Quick summary of the most important aspects for us:

  • NumPy 2.0 as a major release changes the C ABI, so any package that builds against the NumPy C API like shapely will have to be rebuilt with numpy 2.0 to be able to run with numpy 2.0. That also means that our current released packages (built with older versions of numpy) will break (fail to import) with numpy 2.0, and so we should ideally add a numpy<2 pin.
    This happens at the moment when installing shapely from a wheel in an environment with numpy nightly.

We don't yet test with numpy nightly

A to do list based on my current understanding:

@djhoese
Copy link
Contributor

djhoese commented Feb 14, 2024

I don't see it mentioned above, but a recent change in numpy 2 seems to be that Cython modules (or anything using the numpy C API) must call np.import_array() at the top of the module. I have CI that installs shapely from github main and it now fails (used to pass with older numpy 2 nightly wheels) because of this upstream change in numpy 2.

Edit: It looks like shapely already runs tests against numpy 2 and is passing:

https://github.com/shapely/shapely/actions/runs/7884170432/job/21512589917?pr=1990

Now I'm very confused at why my CI is failing.

Edit 2: I suppose this means libgeos needs to be compiled with numpy 2 in my CI?

    import shapely.geometry as sgeom
../../../miniconda3/envs/test-environment/lib/python3.12/site-packages/shapely/__init__.py:1: in <module>
    from shapely.lib import GEOSException  # NOQA
E   ImportError: numpy.core.multiarray failed to import

@jorisvandenbossche
Copy link
Member Author

@djhoese do you have a link to the CI in question? (failing build)

@djhoese
Copy link
Contributor

djhoese commented Feb 15, 2024

@jorisvandenbossche Here you go: https://github.com/pytroll/pyresample/actions/runs/7906385079/job/21581090150

RuntimeError: module compiled against ABI version 0x1000009 but this version of numpy is 0x2000000

@jorisvandenbossche
Copy link
Member Author

The problem is that pip by default will create an isolated build environment, and at that point it still installs numpy 1.x in that build environment.

So one option is to change the line for shapely at https://github.com/pytroll/pyresample/blob/df92fb921f9116a819c21d75d8e6dba291622e4b/.github/workflows/ci.yaml#L66 to be pip install --no-deps --no-build-isolation git+https://github.com/shapely/shapely

Then that should ensure that shapely is built against the numpy 2.0 nightly you installed just before.

Another option is to figure out how to ensure pip will also install nightly packages from the extra index during the build isolation, but that I don't know exactly what that would look like.

@pllim
Copy link

pllim commented Feb 15, 2024

FWIW we found that --pre helped, at least in tox.

https://github.com/astropy/astropy/blob/2c98602609aaf7d41ef9b2b4416d17665d3910d0/tox.ini#L120

@djhoese
Copy link
Contributor

djhoese commented Feb 15, 2024

@jorisvandenbossche Thanks. What's sad is I actually knew I needed --no-build-isolation as I've used it in another project for this same exact purpose, but thought I had already done it in pyresample. Tests are done yet, but I'm sure this will fix it. Thanks.

@jorisvandenbossche
Copy link
Member Author

I am planning to do a 2.0.4 release next week to have wheels compatible with numpy 2.0

@jorisvandenbossche
Copy link
Member Author

I am planning to do a 2.0.4 release next week to have wheels compatible with numpy 2.0

This is done in the meantime: https://github.com/shapely/shapely/releases/tag/2.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants