2929#include < utility>
3030#include < vector>
3131
32- #if defined(PYBIND11_NUMPY_1_ONLY) && !defined(PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED)
33- # error PYBIND11_NUMPY_1_ONLY must be defined before any pybind11 header is included.
32+ #if defined(PYBIND11_NUMPY_1_ONLY)
33+ # error " PYBIND11_NUMPY_1_ONLY is no longer supported (see PR #5595)."
3434#endif
3535
3636/* This will be true on all flat address space platforms and allows us to reduce the
@@ -80,7 +80,6 @@ struct PyArrayDescr1_Proxy {
8080 PyObject *names;
8181};
8282
83- #ifndef PYBIND11_NUMPY_1_ONLY
8483struct PyArrayDescr_Proxy {
8584 PyObject_HEAD
8685 PyObject *typeobj;
@@ -91,10 +90,6 @@ struct PyArrayDescr_Proxy {
9190 int type_num;
9291 /* Additional fields are NumPy version specific. */
9392};
94- #else
95- /* NumPy 1.x only, we can expose all fields */
96- using PyArrayDescr_Proxy = PyArrayDescr1_Proxy;
97- #endif
9893
9994/* NumPy 2 proxy, including legacy fields */
10095struct PyArrayDescr2_Proxy {
@@ -179,14 +174,6 @@ PYBIND11_NOINLINE module_ import_numpy_core_submodule(const char *submodule_name
179174 object numpy_version = numpy_lib.attr (" NumpyVersion" )(version_string);
180175 int major_version = numpy_version.attr (" major" ).cast <int >();
181176
182- #ifdef PYBIND11_NUMPY_1_ONLY
183- if (major_version >= 2 ) {
184- throw std::runtime_error (
185- " This extension was built with PYBIND11_NUMPY_1_ONLY defined, "
186- " but NumPy 2 is used in this process. For NumPy2 compatibility, "
187- " this extension needs to be rebuilt without the PYBIND11_NUMPY_1_ONLY define." );
188- }
189- #endif
190177 /* `numpy.core` was renamed to `numpy._core` in NumPy 2.0 as it officially
191178 became a private module. */
192179 std::string numpy_core_path = major_version >= 2 ? " numpy._core" : " numpy.core" ;
@@ -300,16 +287,6 @@ struct npy_api {
300287 PyObject *(*PyArray_FromAny_)(PyObject *, PyObject *, int , int , int , PyObject *);
301288 int (*PyArray_DescrConverter_)(PyObject *, PyObject **);
302289 bool (*PyArray_EquivTypes_)(PyObject *, PyObject *);
303- #ifdef PYBIND11_NUMPY_1_ONLY
304- int (*PyArray_GetArrayParamsFromObject_)(PyObject *,
305- PyObject *,
306- unsigned char ,
307- PyObject **,
308- int *,
309- Py_intptr_t *,
310- PyObject **,
311- PyObject *);
312- #endif
313290 PyObject *(*PyArray_Squeeze_)(PyObject *);
314291 // Unused. Not removed because that affects ABI of the class.
315292 int (*PyArray_SetBaseObject_)(PyObject *, PyObject *);
@@ -337,9 +314,6 @@ struct npy_api {
337314 API_PyArray_View = 137 ,
338315 API_PyArray_DescrConverter = 174 ,
339316 API_PyArray_EquivTypes = 182 ,
340- #ifdef PYBIND11_NUMPY_1_ONLY
341- API_PyArray_GetArrayParamsFromObject = 278 ,
342- #endif
343317 API_PyArray_SetBaseObject = 282
344318 };
345319
@@ -374,9 +348,6 @@ struct npy_api {
374348 DECL_NPY_API (PyArray_View);
375349 DECL_NPY_API (PyArray_DescrConverter);
376350 DECL_NPY_API (PyArray_EquivTypes);
377- #ifdef PYBIND11_NUMPY_1_ONLY
378- DECL_NPY_API (PyArray_GetArrayParamsFromObject);
379- #endif
380351 DECL_NPY_API (PyArray_SetBaseObject);
381352
382353#undef DECL_NPY_API
@@ -760,21 +731,14 @@ class dtype : public object {
760731 }
761732
762733 // / Size of the data type in bytes.
763- #ifdef PYBIND11_NUMPY_1_ONLY
764- ssize_t itemsize () const { return detail::array_descriptor_proxy (m_ptr)->elsize ; }
765- #else
766734 ssize_t itemsize () const {
767735 if (detail::npy_api::get ().PyArray_RUNTIME_VERSION_ < 0x12 ) {
768736 return detail::array_descriptor1_proxy (m_ptr)->elsize ;
769737 }
770738 return detail::array_descriptor2_proxy (m_ptr)->elsize ;
771739 }
772- #endif
773740
774741 // / Returns true for structured data types.
775- #ifdef PYBIND11_NUMPY_1_ONLY
776- bool has_fields () const { return detail::array_descriptor_proxy (m_ptr)->names != nullptr ; }
777- #else
778742 bool has_fields () const {
779743 if (detail::npy_api::get ().PyArray_RUNTIME_VERSION_ < 0x12 ) {
780744 return detail::array_descriptor1_proxy (m_ptr)->names != nullptr ;
@@ -785,7 +749,6 @@ class dtype : public object {
785749 }
786750 return proxy->names != nullptr ;
787751 }
788- #endif
789752
790753 // / Single-character code for dtype's kind.
791754 // / For example, floating point types are 'f' and integral types are 'i'.
@@ -824,29 +787,21 @@ class dtype : public object {
824787 // / Single character for byteorder
825788 char byteorder () const { return detail::array_descriptor_proxy (m_ptr)->byteorder ; }
826789
827- // / Alignment of the data type
828- #ifdef PYBIND11_NUMPY_1_ONLY
829- int alignment () const { return detail::array_descriptor_proxy (m_ptr)->alignment ; }
830- #else
790+ // / Alignment of the data type
831791 ssize_t alignment () const {
832792 if (detail::npy_api::get ().PyArray_RUNTIME_VERSION_ < 0x12 ) {
833793 return detail::array_descriptor1_proxy (m_ptr)->alignment ;
834794 }
835795 return detail::array_descriptor2_proxy (m_ptr)->alignment ;
836796 }
837- #endif
838797
839- // / Flags for the array descriptor
840- #ifdef PYBIND11_NUMPY_1_ONLY
841- char flags () const { return detail::array_descriptor_proxy (m_ptr)->flags ; }
842- #else
798+ // / Flags for the array descriptor
843799 std::uint64_t flags () const {
844800 if (detail::npy_api::get ().PyArray_RUNTIME_VERSION_ < 0x12 ) {
845801 return (unsigned char ) detail::array_descriptor1_proxy (m_ptr)->flags ;
846802 }
847803 return detail::array_descriptor2_proxy (m_ptr)->flags ;
848804 }
849- #endif
850805
851806private:
852807 static object &_dtype_from_pep3118 () {
0 commit comments