Skip to content

Commit

Permalink
backport patch for numpy 2.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed May 15, 2024
1 parent aed9881 commit 8275b5c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ source:
patches:
# ensure our compiler flags get used during bootstrapping
- patches/0001-Add-default-value-for-cxx-and-cxxflags-options-for-t.patch
# backport https://github.com/boostorg/locale/pull/212
- patches/0002-Reimplement-string_set-as-any_string.patch
# backport https://github.com/boostorg/python/pull/432
- patches/0003-Support-numpy-2.0.0b1.patch

build:
number: 3
Expand Down
28 changes: 28 additions & 0 deletions recipe/patches/0003-Support-numpy-2.0.0b1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 8ac13ee041e575a5b2af196dfd5088d9bdf90700 Mon Sep 17 00:00:00 2001
From: Alexis DUBURCQ <[email protected]>
Date: Fri, 15 Mar 2024 14:10:16 +0100
Subject: [PATCH] Support numpy 2.0.0b1

---
libs/python/libs/python/src/numpy/dtype.cpp | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libs/python/src/numpy/dtype.cpp b/libs/python/src/numpy/dtype.cpp
index 88a20a27..da30d192 100644
--- a/libs/python/src/numpy/dtype.cpp
+++ b/libs/python/src/numpy/dtype.cpp
@@ -98,7 +98,13 @@ python::detail::new_reference dtype::convert(object const & arg, bool align)
return python::detail::new_reference(reinterpret_cast<PyObject*>(obj));
}

-int dtype::get_itemsize() const { return reinterpret_cast<PyArray_Descr*>(ptr())->elsize;}
+int dtype::get_itemsize() const {
+#if NPY_ABI_VERSION < 0x02000000
+ return reinterpret_cast<PyArray_Descr*>(ptr())->elsize;
+#else
+ return PyDataType_ELSIZE(reinterpret_cast<PyArray_Descr*>(ptr()));
+#endif
+}

bool equivalent(dtype const & a, dtype const & b) {
// On Windows x64, the behaviour described on

0 comments on commit 8275b5c

Please sign in to comment.