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

jl.pytruth(np.bool_(False)) == true #321

Closed
schlichtanders opened this issue Jun 5, 2023 · 5 comments
Closed

jl.pytruth(np.bool_(False)) == true #321

schlichtanders opened this issue Jun 5, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@schlichtanders
Copy link
Contributor

Affects: Both

Describe the bug
A clear and concise description of what the bug is. What did you expect? What happened instead?

numpy has its own boolean values see its docs.
Using python, the numpy bools look exactly like normal bools, but are different types.

When using PythonCall/JuliaCall unfortunately numpy bools behaviour entirely differently from normal Python bool. That is very confusing. Especially

from juliacall import Main as jl
jl.pytruth(np.bool_(False))  # returns true

I guess this is just a bug with pytruth which actually should return true in this case.

Your system
Please provide detailed information about your system:

  • The operating system: Nixos
  • Julia 1.9.0 PythonCall/JuliaCall 0.9.13
@schlichtanders schlichtanders added the bug Something isn't working label Jun 5, 2023
@cjdoris
Copy link
Collaborator

cjdoris commented Jun 5, 2023

Are you sure you're on 0.9.13? This look a lot like an issue that was solved in 0.9.13, and I can't reproduce it:

>>> from juliacall import Main as jl
>>> import numpy as np
>>> jl.pytruth(np.bool_(False))
False
>>> jl.pytruth(np.bool_(True))
True

Also, what's the actual issue you're having? Because it never really makes sense to do jl.pytruth(x) from Python when you can do bool(x) instead.

@schlichtanders
Copy link
Contributor Author

yes I can confirm I am on 0.9.13

image

In the same vscode notebook jl.pytruth(np.bool_(False)) returns true

@schlichtanders
Copy link
Contributor Author

My usecase is that I am compiling a super small intro to PythonCall which is going to be presented today evening, where by chance I run into this point.

@cjdoris
Copy link
Collaborator

cjdoris commented Jun 5, 2023

I really can't see how you can get this issue on the current version. Are you definitely not on a dev version of PythonCall? What are juliacall.__version__, juliapkg.status(), juliapkg.state.STATE and pip show juliacall?

Also, when I asked about your usecase, I more meant in terms of code. Like I said, doing jl.pytruth(anything) is weird because you can do bool(anything) instead. Are you actually using pytruth from within a Julia function? If so, you should wrap that function using jl.pyfunc to create a Python callback function which avoids the automatic conversion causing the issues you're having.

@schlichtanders
Copy link
Contributor Author

thank you so much for not giving up!! Everything works now.

indeed the python kernel I used was not the one I thought I would be using. So I got 0.9.12 there for juliacall.version

and yes indeed I was originally using pytruth on the julia side of things, but running a python kernel using the python way was better for sharing here on github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants