Commit 571475c8 authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

Merge branch 'development/fix-check-numpy' into 'next'

Fix the input type checking of the numpy array type caster

See merge request !125
parents 339d6e2f 78f96967
Pipeline #32443 failed with stages
in 23 minutes and 48 seconds
......@@ -5,6 +5,8 @@
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <fmt/format.h>
namespace pln
/// \brief Convert a NumPy array to a ndbuffer_image
......@@ -33,6 +35,8 @@ namespace pybind11::detail
bool load(handle h, bool)
if (!pybind11::array::check_(h))
throw std::invalid_argument(fmt::format("Input value is not a valid array (Got `{}`)", static_cast<std::string>(pybind11::str(pybind11::type::handle_of(h)))));
pybind11::array arr = reinterpret_borrow<pybind11::array>(h);
value = pln::from_numpy(arr);
return true;
......@@ -131,6 +131,11 @@ class TestNumpyImage(unittest.TestCase):
with self.assertRaises(ValueError, msg="Invalid number of dimension from numpy array (Got 5 but should be < 5)"):
def test_invalid_input(self):
a = 10
with self.assertRaises(ValueError, msg="Input value is not a valid array (Got `<class 'int'>`)"):
if __name__ == "__main__":
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment