From 83158fff83c1e68722097676f504ef76971d8c1f Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Mon, 17 Jun 2024 16:40:09 -0500 Subject: [PATCH] fixes for numpy 1.22+ --- pyproject.toml | 4 ++-- src/pdal/io/NumpyReader.cpp | 9 +++++---- src/pdal/plang/Invocation.cpp | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 25486c1..8dc6ea4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,10 +26,10 @@ classifiers = [ ] dependencies = [ - "numpy" + "numpy >= 1.22" ] -version="1.5.0" +version="1.5.1" [project.optional-dependencies] test = [ ] diff --git a/src/pdal/io/NumpyReader.cpp b/src/pdal/io/NumpyReader.cpp index dd4c1ea..b20994b 100644 --- a/src/pdal/io/NumpyReader.cpp +++ b/src/pdal/io/NumpyReader.cpp @@ -377,8 +377,9 @@ void NumpyReader::createFields(PointLayoutPtr layout) int offset; m_numFields = 0; - if (m_dtype->fields != Py_None) - m_numFields = static_cast(PyDict_Size(m_dtype->fields)); + PyObject* fields = PyDataType_FIELDS(m_dtype); + if (fields != Py_None) + m_numFields = static_cast(PyDict_Size(fields)); // Array isn't structured - just a bunch of data. if (m_numFields <= 0) @@ -389,7 +390,7 @@ void NumpyReader::createFields(PointLayoutPtr layout) } else { - PyObject* names_dict = m_dtype->fields; + PyObject* names_dict = fields; PyObject* names = PyDict_Keys(names_dict); PyObject* values = PyDict_Values(names_dict); if (!names || !values) @@ -413,7 +414,7 @@ void NumpyReader::createFields(PointLayoutPtr layout) type = getType(dt, name); char byteorder = dt->byteorder; - int elsize = dt->elsize; + int elsize = (int) PyDataType_ELSIZE(dt); id = registerDim(layout, name, type); m_fields.push_back({id, type, offset, byteorder, elsize}); } diff --git a/src/pdal/plang/Invocation.cpp b/src/pdal/plang/Invocation.cpp index ac7fe02..68b646e 100644 --- a/src/pdal/plang/Invocation.cpp +++ b/src/pdal/plang/Invocation.cpp @@ -258,10 +258,11 @@ void *Invocation::extractArray(PyObject *array, std::string const& name, num_elements = (size_t)nPoints; - if (static_cast(dtype->elsize) != Dimension::size(t)) + npy_intp elsize = PyDataType_ELSIZE(dtype); + if (static_cast(elsize) != Dimension::size(t)) { std::ostringstream oss; - oss << "dtype of array has size " << dtype->elsize + oss << "dtype of array has size " << elsize << " but PDAL dimension '" << name << "' has byte size of " << Dimension::size(t) << " bytes."; throw pdal_error(oss.str());