Skip to content

Commit

Permalink
fixes for numpy 1.22+
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Jun 17, 2024
1 parent b00c8ef commit 83158ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ classifiers = [
]

dependencies = [
"numpy"
"numpy >= 1.22"
]

version="1.5.0"
version="1.5.1"

[project.optional-dependencies]
test = [ ]
Expand Down
9 changes: 5 additions & 4 deletions src/pdal/io/NumpyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,9 @@ void NumpyReader::createFields(PointLayoutPtr layout)
int offset;

m_numFields = 0;
if (m_dtype->fields != Py_None)
m_numFields = static_cast<int>(PyDict_Size(m_dtype->fields));
PyObject* fields = PyDataType_FIELDS(m_dtype);
if (fields != Py_None)
m_numFields = static_cast<int>(PyDict_Size(fields));

// Array isn't structured - just a bunch of data.
if (m_numFields <= 0)
Expand All @@ -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)
Expand All @@ -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});
}
Expand Down
5 changes: 3 additions & 2 deletions src/pdal/plang/Invocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ void *Invocation::extractArray(PyObject *array, std::string const& name,

num_elements = (size_t)nPoints;

if (static_cast<uint32_t>(dtype->elsize) != Dimension::size(t))
npy_intp elsize = PyDataType_ELSIZE(dtype);
if (static_cast<uint32_t>(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());
Expand Down

0 comments on commit 83158ff

Please sign in to comment.