ninia / jep

Embed Python in Java
Other
1.31k stars 149 forks source link

`numpy.bool_` does not automatically convert to `java.lang.Boolean` #563

Open CHanzyLazer opened 1 week ago

CHanzyLazer commented 1 week ago

Describe the bug numpy.bool_ does not automatically convert to java.lang.Boolean.

To Reproduce

try (SharedInterpreter inter = new SharedInterpreter()) {
    inter.exec("import numpy as np");
    Object pyBool = inter.getValue("True");
    Object npyBool = inter.getValue("np.True_");
    System.out.println(pyBool.getClass());
    System.out.println(npyBool.getClass());
}

Output:

class java.lang.Boolean
class jep.python.PyObject

Expected behavior

Output:

class java.lang.Boolean
class java.lang.Boolean
ndjensen commented 1 week ago

Thank you for reporting this and providing an easily reproducible test case. A workaround is to cast it to a bool in Python, like

Object npyBool = interp.getValue("bool(numpy.True_)").