Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np.bool_ is not autoconverted to C++ bool unlike other numpy numeric types #922

Closed
anntzer opened this issue Jun 26, 2017 · 0 comments · Fixed by #925
Closed

np.bool_ is not autoconverted to C++ bool unlike other numpy numeric types #922

anntzer opened this issue Jun 26, 2017 · 0 comments · Fixed by #925

Comments

@anntzer
Copy link
Contributor

anntzer commented Jun 26, 2017

Issue description

It looks like all numpy types are autoconverted to C++-level int/double/etc. as needed, with the exception of np.bool_. I'd think np.bool_ should likewise get autoconverted to a C++ bool.

Reproducible example code

Compiling the example repository pybind11/python_example with the following patch applied:

diff --git a/src/main.cpp b/src/main.cpp
index d81046d..8adbe25 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,6 @@
 #include <pybind11/pybind11.h>

-int add(int i, int j) {
+int add(int i, bool j) {
     return i + j;
 }

Then

python_example.add(np.int64(1), True)

works, but

python_example.add(1, np.bool_(True))

fails with a TypeError.

(initially reported on gitter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant