Commit 7c097fa4 authored by Michael Droettboom's avatar Michael Droettboom

Handle numpy scalars in python2js_buffer

parent 16580a16
...@@ -427,6 +427,10 @@ _python2js_shareable_buffer_recursive(Py_buffer* buff, ...@@ -427,6 +427,10 @@ _python2js_shareable_buffer_recursive(Py_buffer* buff,
static enum shareable_enum static enum shareable_enum
_python2js_buffer_is_shareable(Py_buffer* buff) _python2js_buffer_is_shareable(Py_buffer* buff)
{ {
if (buff->ndim == 0) {
return NOT_SHAREABLE;
}
char* invalid_codes = ">!qQ?"; char* invalid_codes = ">!qQ?";
for (char* i = buff->format; *i != 0; ++i) { for (char* i = buff->format; *i != 0; ++i) {
for (char* j = invalid_codes; *j != 0; ++j) { for (char* j = invalid_codes; *j != 0; ++j) {
......
...@@ -146,6 +146,46 @@ def test_python2js_numpy_dtype(selenium_standalone): ...@@ -146,6 +146,46 @@ def test_python2js_numpy_dtype(selenium_standalone):
assert selenium.run_js("return pyodide.pyimport('x')[1][1]") == 'string4' 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): def test_pythonexc2js(selenium):
try: try:
selenium.run_js('return pyodide.runPython("5 / 0")') selenium.run_js('return pyodide.runPython("5 / 0")')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment