data-apis / array-api-strict

Strict implementation of the Python array API (previously numpy.array_api)
http://data-apis.org/array-api-strict/
Other
7 stars 4 forks source link

MAINT: copy semantics shim #11

Closed tylerjereddy closed 6 months ago

tylerjereddy commented 6 months ago

Probably not surprising; in https://github.com/scipy/scipy/pull/20172 I noticed what looks like a requirement for at least a small copy argument pass-through shim with NumPy main here because of (currently) a single test in SciPy. In that PR I was able to patch similar errors with fairly crude copy=None pass-through type shims, though in this library it may actually need to do something useful (the intended purpose) if the copy arg really needs to be respected I suppose.

============================================================================================ FAILURES =============================================================================================
______________________________________________________________________________ test_dispatch_to_unrecognize_library _______________________________________________________________________________
[gw22] linux -- Python 3.11.2 /home/treddy/python_venvs/py_311_scipy_dev/bin/python
scipy/special/tests/test_support_alternative_backends.py:25: in test_dispatch_to_unrecognize_library
    res = f(xp.asarray(x))
        f          = <function get_array_special_func.<locals>.f at 0x7f404756a2a0>
        x          = [1, 2, 3]
        xp         = <module 'array_api_strict' from '/home/treddy/python_venvs/py_311_scipy_dev/lib/python3.11/site-packages/array_api_strict/__init__.py'>
scipy/special/_support_alternative_backends.py:33: in f
    array_args = [np.asarray(arg) for arg in array_args]
        args       = (Array([1, 2, 3], dtype=array_api_strict.int64),)
        array_args = (Array([1, 2, 3], dtype=array_api_strict.int64),)
        f_scipy    = <ufunc 'ndtr'>
        kwargs     = {}
        n_array_args = 1
        other_args = ()
        xp         = <module 'array_api_strict' from '/home/treddy/python_venvs/py_311_scipy_dev/lib/python3.11/site-packages/array_api_strict/__init__.py'>
scipy/special/_support_alternative_backends.py:33: in <listcomp>
    array_args = [np.asarray(arg) for arg in array_args]
E   TypeError: Array.__array__() got an unexpected keyword argument 'copy'
        .0         = <tuple_iterator object at 0x7f4062090cd0>
        arg        = Array([1, 2, 3], dtype=array_api_strict.int64)
===================================================================================== short test summary info =====================================================================================
FAILED scipy/special/tests/test_support_alternative_backends.py::test_dispatch_to_unrecognize_library - TypeError: Array.__array__() got an unexpected keyword argument 'copy'
asmeurer commented 6 months ago

I don't think we can really emulate copy=False in NumPy 1.26, hence the NotImplementedError. If NumPy main now actually supports copy=False we should update that code to pass it through for NumPy >= 2.0.

rgommers commented 6 months ago

Should be fixed by gh-12. Since the NumPy change got merged in a way that wasn't backwards-compatible, this is breaking SciPy tests now (and probably tests of other users of this package). Even if that is addressed in NumPy, a missing copy keyword will still emit a warning, which is still going to break the SciPy test suite. So it'd be nice to do a release with this issue fixed very soon.