From 6734d6314e42e1e079b5659cab5e4e01abc2d9f0 Mon Sep 17 00:00:00 2001 From: Ellis Ratner Date: Sat, 18 Jul 2020 11:53:04 -0700 Subject: [PATCH] Fixed issue in passing floating-point values as parameters to fill --- matplotlibcpp.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/matplotlibcpp.h b/matplotlibcpp.h index 6770074..62fb581 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -312,9 +312,9 @@ template <> struct select_npy_type { const static NPY_TYPES type = NPY // Sanity checks; comment them out or change the numpy type below if you're compiling on // a platform where they don't apply -static_assert(sizeof(long long) == 8); +// static_assert(sizeof(long long) == 8); template <> struct select_npy_type { const static NPY_TYPES type = NPY_INT64; }; -static_assert(sizeof(unsigned long long) == 8); +// static_assert(sizeof(unsigned long long) == 8); template <> struct select_npy_type { const static NPY_TYPES type = NPY_UINT64; }; // TODO: add int, long, etc. @@ -670,7 +670,13 @@ bool fill(const std::vector& x, const std::vector& y, const st // construct keyword args PyObject* kwargs = PyDict_New(); for (auto it = keywords.begin(); it != keywords.end(); ++it) { - PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); + try { + double value = std::stod(it->second); + PyDict_SetItemString(kwargs, it->first.c_str(), PyFloat_FromDouble(value)); + } catch (std::exception &) { + PyDict_SetItemString(kwargs, it->first.c_str(), + PyUnicode_FromString(it->second.c_str())); + } } PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_fill, args, kwargs);