openPMD / openPMD-api

:floppy_disk: C++ & Python API for Scientific I/O
https://openpmd-api.readthedocs.io
GNU Lesser General Public License v3.0
134 stars 51 forks source link

Python: Better error message when loading to a buffer with mismatched type #1452

Closed franzpoeschel closed 1 year ago

franzpoeschel commented 1 year ago

In the Python API, when using load_chunk() to a preallocated buffer, the buffer is checked for being contiguous. The calculations happen on the basis of the record component's datatype, not on the datatype of the buffer (the datatype of the buffer cannot be queried on a py::buffer object, just the item size). If the datatypes are mismatched, the error message is very confusing (and in fact wrong): [Record_Component::load_chunk()] Requires contiguous slab of memory.

This checks if the item size matches the datatype before doing and check for contiguous data.