mirror of https://github.com/pyodide/pyodide.git
Merge pull request #322 from mdboom/issue319
Handle numpy scalars in python2js_buffer
This commit is contained in:
commit
1c4362203c
|
@ -427,6 +427,10 @@ _python2js_shareable_buffer_recursive(Py_buffer* buff,
|
|||
static enum shareable_enum
|
||||
_python2js_buffer_is_shareable(Py_buffer* buff)
|
||||
{
|
||||
if (buff->ndim == 0) {
|
||||
return NOT_SHAREABLE;
|
||||
}
|
||||
|
||||
char* invalid_codes = ">!qQ?";
|
||||
for (char* i = buff->format; *i != 0; ++i) {
|
||||
for (char* j = invalid_codes; *j != 0; ++j) {
|
||||
|
|
|
@ -146,6 +146,46 @@ def test_python2js_numpy_dtype(selenium_standalone):
|
|||
assert selenium.run_js("return pyodide.pyimport('x')[1][1]") == 'string4'
|
||||
|
||||
|
||||
def test_python2js_numpy_scalar(selenium_standalone):
|
||||
selenium = selenium_standalone
|
||||
|
||||
selenium.load_package('numpy')
|
||||
selenium.run("import numpy as np")
|
||||
|
||||
for dtype in (
|
||||
'int8',
|
||||
'uint8',
|
||||
'int16',
|
||||
'uint16',
|
||||
'int32',
|
||||
'uint32',
|
||||
'int64',
|
||||
'uint64',
|
||||
'float32',
|
||||
'float64'
|
||||
):
|
||||
selenium.run(
|
||||
f"""
|
||||
x = np.{dtype}(1)
|
||||
"""
|
||||
)
|
||||
assert selenium.run_js(
|
||||
"""
|
||||
return pyodide.pyimport('x') == 1
|
||||
"""
|
||||
) is True
|
||||
selenium.run(
|
||||
"""
|
||||
x = x.byteswap().newbyteorder()
|
||||
"""
|
||||
)
|
||||
assert selenium.run_js(
|
||||
"""
|
||||
return pyodide.pyimport('x') == 1
|
||||
"""
|
||||
) is True
|
||||
|
||||
|
||||
def test_pythonexc2js(selenium):
|
||||
try:
|
||||
selenium.run_js('return pyodide.runPython("5 / 0")')
|
||||
|
|
Loading…
Reference in New Issue