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

Dependencies: Added support of numpy v2 #4082

Merged
merged 12 commits into from
Apr 9, 2024
Merged

Dependencies: Added support of numpy v2 #4082

merged 12 commits into from
Apr 9, 2024

Conversation

t20100
Copy link
Member

@t20100 t20100 commented Mar 14, 2024

Checklist:


This PR prepares silx for support of numpy v2 by:

  • Using np.rec instead of np.core.recarray
  • Using cython fixed-size types instead of cimport numpy: This leaves the constraint of using numpy headers to build C extensions.
  • Fixing incompatibilities spotted by ruff check --select NPY201

I've tested that cython extensions built with numpy v1 can be imported with numpy v2.
Full testing with numpy v2 is still needed.

I also raised the minimum supported version of numpy to the "oldest-supported-numpy" one on Python3.7.

Closes #4080

@t20100 t20100 added this to the 2.1.0 milestone Mar 14, 2024
@t20100 t20100 marked this pull request as ready for review March 14, 2024 16:01
@t20100 t20100 marked this pull request as draft March 15, 2024 12:38
@t20100 t20100 force-pushed the numpy2 branch 2 times, most recently from 647d3bf to 268d43c Compare March 15, 2024 15:57
@t20100
Copy link
Member Author

t20100 commented Mar 15, 2024

A few tests still fails with numpy v2:

FAILED build/lib.macosx-10.9-universal2-3.12/silx/gui/plot/tools/test/testScatterProfileToolBar.py::TestScatterProfileToolBar::testHorizontalProfile - AssertionError: None is not an instance of <class 'silx.gui.plot.tools.profile.core.CurveProfileData'>
FAILED build/lib.macosx-10.9-universal2-3.12/silx/gui/plot/tools/test/testScatterProfileToolBar.py::TestScatterProfileToolBar::testVerticalProfile - AssertionError: None is not an instance of <class 'silx.gui.plot.tools.profile.core.CurveProfileData'>
FAILED build/lib.macosx-10.9-universal2-3.12/silx/math/test/test_histogramnd_error.py::Test_chistogramnd_1D_errors::test_histo_shape - AssertionError: "Prov[48 chars]le with <n_bins> : should be (np.int64(10),) instead of (11,)." != "Prov...
FAILED build/lib.macosx-10.9-universal2-3.12/silx/math/test/test_histogramnd_error.py::Test_chistogramnd_1D_errors::test_weighted_histo_shape - AssertionError: "Prov[57 chars]le with <n_bins> : should be (np.int64(10),) instead of (11,)." != "Prov...
FAILED build/lib.macosx-10.9-universal2-3.12/silx/math/test/test_histogramnd_error.py::Test_chistogramnd_ND_errors::test_histo_shape - AssertionError: "Prov[73 chars] be (np.int64(10), np.int64(20), np.int64(30))[21 chars]30)." != "Prov[7...
FAILED build/lib.macosx-10.9-universal2-3.12/silx/math/test/test_histogramnd_error.py::Test_chistogramnd_ND_errors::test_weighted_histo_shape - AssertionError: "Prov[82 chars] be (np.int64(10), np.int64(20), np.int64(30))[21 chars]30)." != "Prov[8...
ERROR build/lib.macosx-10.9-universal2-3.12/silx/gui/plot/tools/test/testScatterProfileToolBar.py::TestScatterProfileToolBar::testHorizontalProfile - RuntimeError: Test ended with widgets alive: [<PyQt5.QtWidgets.QRadioButton object at 0x1248a6b10>, <si...
ERROR build/lib.macosx-10.9-universal2-3.12/silx/gui/plot/tools/test/testScatterProfileToolBar.py::TestScatterProfileToolBar::testVerticalProfile - RuntimeError: Test ended with widgets alive: [<PyQt5.QtWidgets.QLabel object at 0x132811ac0>, <PyQt5.Qt...

@t20100
Copy link
Member Author

t20100 commented Mar 18, 2024

FAILED build/lib.macosx-10.9-universal2-3.12/silx/gui/plot/tools/test/testScatterProfileToolBar.py::TestScatterProfileToolBar::testHorizontalProfile - AssertionError: None is not an instance of <class 'silx.gui.plot.tools.profile.core.CurveProfileData'>
FAILED build/lib.macosx-10.9-universal2-3.12/silx/gui/plot/tools/test/testScatterProfileToolBar.py::TestScatterProfileToolBar::testVerticalProfile - AssertionError: None is not an instance of <class 'silx.gui.plot.tools.profile.core.CurveProfileData'>

Digging into those issues, leads to issue with matplotlib.tri.TriFinder which is most likely related to: matplotlib/matplotlib#27892 (comment)

@t20100
Copy link
Member Author

t20100 commented Mar 18, 2024

The following issues are fixed by dd403ee:

FAILED build/lib.macosx-10.9-universal2-3.12/silx/math/test/test_histogramnd_error.py::Test_chistogramnd_1D_errors::test_histo_shape - AssertionError: "Prov[48 chars]le with <n_bins> : should be (np.int64(10),) instead of (11,)." != "Prov...
FAILED build/lib.macosx-10.9-universal2-3.12/silx/math/test/test_histogramnd_error.py::Test_chistogramnd_1D_errors::test_weighted_histo_shape - AssertionError: "Prov[57 chars]le with <n_bins> : should be (np.int64(10),) instead of (11,)." != "Prov...
FAILED build/lib.macosx-10.9-universal2-3.12/silx/math/test/test_histogramnd_error.py::Test_chistogramnd_ND_errors::test_histo_shape - AssertionError: "Prov[73 chars] be (np.int64(10), np.int64(20), np.int64(30))[21 chars]30)." != "Prov[7...
FAILED build/lib.macosx-10.9-universal2-3.12/silx/math/test/test_histogramnd_error.py::Test_chistogramnd_ND_errors::test_weighted_histo_shape - AssertionError: "Prov[82 chars] be (np.int64(10), np.int64(20), np.int64(30))[21 chars]30)." != "Prov[8...

@t20100 t20100 marked this pull request as ready for review March 21, 2024 10:25
@t20100
Copy link
Member Author

t20100 commented Mar 21, 2024

Added changes to support:

With this PR tests passes with numpy2, except:

  • Tests using OpenCL or scipy
  • Tests relying on matplotlib Triangulator which has a known issue with numpy 2.

@t20100
Copy link
Member Author

t20100 commented Mar 21, 2024

Changes are grouped by commit, so it should be simpler to review commits than the whole PR...

@t20100
Copy link
Member Author

t20100 commented Apr 3, 2024

From what I tested, with this PR tests pass, except for https://github.com/silx-kit/silx/blob/main/src/silx/math/fft/test/test_fft.py which as mainy extra dependencies.

So ready for review.

What I haven't checked is the effect of changes to numpy data type promotion

@kif kif self-requested a review April 9, 2024 18:51
@kif
Copy link
Member

kif commented Apr 9, 2024

LGTM

@kif kif merged commit db600d7 into silx-kit:main Apr 9, 2024
7 of 8 checks passed
@t20100 t20100 deleted the numpy2 branch April 10, 2024 09:00
@t20100
Copy link
Member Author

t20100 commented Apr 10, 2024

Thanks for the review!

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.

numpy v2 support
2 participants