From ab92eb37650d3c59a4484b585b8dedde44dac89d Mon Sep 17 00:00:00 2001 From: Jan Dohl Date: Tue, 15 Dec 2015 04:16:49 +0100 Subject: [PATCH] Fixed py:array constructor from failing for complex types The array(const buffer_info &info) constructor fails when given complex types since their format string is 'Zd' or 'Zf' which has a length of two and causes an error here: if (info.format.size() != 1) throw std::runtime_error("Unsupported buffer format!"); Fixed by allowing format sizes of one and two. --- include/pybind11/numpy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index dfbdc4988..d3d8e1030 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -96,7 +96,7 @@ public: array(const buffer_info &info) { API& api = lookup_api(); - if (info.format.size() != 1) + if ((info.format.size() < 1) || (info.format.size() > 2)) throw std::runtime_error("Unsupported buffer format!"); int fmt = (int) info.format[0]; if (info.format == "Zd")