Improve buffer_info type checking in numpy docs (#5805)

When comparing buffer types there are some edge cases on some platforms that are equivalent but the format string is not identical.
item_type_is_equivalent_to is more forgiving than direct string comparison.
This commit is contained in:
gentlegiantJGC
2025-08-21 20:14:57 +01:00
committed by GitHub
parent 03607757fc
commit 8bbc3091c8

View File

@@ -88,7 +88,7 @@ buffer objects (e.g. a NumPy matrix).
py::buffer_info info = b.request();
/* Some basic validation checks ... */
if (info.format != py::format_descriptor<Scalar>::format())
if (!info.item_type_is_equivalent_to<Scalar>())
throw std::runtime_error("Incompatible format: expected a double array!");
if (info.ndim != 2)