scipy: BUG: `csr_array(int())` errors
Describe your issue.
It seems like the described behavior does no work while np.array(int())
does seem to work. This comes from the array api test suite setup, so presumably it should work and indeed does for csr_matrix
. I think the error is recent (or on main
) because it does not error in 1.11.4
. I know there has been a lot of work around 1d so sorry if this is expected! Happy to fix if it’s a real bug!
Reproducing Code Example
from scipy import sparse
import numpy as np
sparse.csr_array(int()) # errors
sparse.csr_matrix(int()) # does not error
np.array(int()) # does not error
Error message
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ilangold/Projects/Theis/scipy/scipy/sparse/_compressed.py", line 86, in __init__
self._coo_container(arg1, dtype=dtype)
File "/Users/ilangold/Projects/Theis/scipy/scipy/sparse/_coo.py", line 81, in __init__
self._shape = check_shape(M.shape, allow_1d=is_array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ilangold/Projects/Theis/scipy/scipy/sparse/_sputils.py", line 317, in check_shape
raise TypeError("function missing 1 required positional argument: "
TypeError: function missing 1 required positional argument: 'shape'
SciPy/NumPy/Python version and system information
1.13.0.dev0+1365.cd9d20b 1.26.4 sys.version_info(major=3, minor=11, micro=8, releaselevel='final', serial=0)
Build Dependencies:
blas:
detection method: pkgconfig
found: true
include directory: /Users/ilangold/micromamba/envs/scipy-dev-array-api/include
lib directory: /Users/ilangold/micromamba/envs/scipy-dev-array-api/lib
name: openblas
openblas configuration: USE_64BITINT=0 DYNAMIC_ARCH=0 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK=0 NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP=1 VORTEX MAX_THREADS=128
pc file directory: /Users/ilangold/micromamba/envs/scipy-dev-array-api/lib/pkgconfig
version: 0.3.26
lapack:
detection method: pkgconfig
found: true
include directory: /Users/ilangold/micromamba/envs/scipy-dev-array-api/include
lib directory: /Users/ilangold/micromamba/envs/scipy-dev-array-api/lib
name: openblas
openblas configuration: USE_64BITINT=0 DYNAMIC_ARCH=0 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK=0 NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP=1 VORTEX MAX_THREADS=128
pc file directory: /Users/ilangold/micromamba/envs/scipy-dev-array-api/lib/pkgconfig
version: 0.3.26
pybind11:
detection method: pkgconfig
include directory: /Users/ilangold/micromamba/envs/scipy-dev-array-api/include
name: pybind11
version: 2.11.1
Compilers:
c:
args: -ftree-vectorize, -fPIC, -fstack-protector-strong, -O2, -pipe, -isystem,
/Users/ilangold/micromamba/envs/scipy-dev/include, -D_FORTIFY_SOURCE=2, -isystem,
/Users/ilangold/micromamba/envs/scipy-dev/include
commands: arm64-apple-darwin20.0.0-clang
linker: ld64
linker args: -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs, -Wl,-rpath,/Users/ilangold/micromamba/envs/scipy-dev/lib,
-L/Users/ilangold/micromamba/envs/scipy-dev/lib, -ftree-vectorize, -fPIC, -fstack-protector-strong,
-O2, -pipe, -isystem, /Users/ilangold/micromamba/envs/scipy-dev/include, -D_FORTIFY_SOURCE=2,
-isystem, /Users/ilangold/micromamba/envs/scipy-dev/include
name: clang
version: 16.0.6
c++:
args: -ftree-vectorize, -fPIC, -fstack-protector-strong, -O2, -pipe, -stdlib=libc++,
-fvisibility-inlines-hidden, -fmessage-length=0, -isystem, /Users/ilangold/micromamba/envs/scipy-dev/include,
-D_FORTIFY_SOURCE=2, -isystem, /Users/ilangold/micromamba/envs/scipy-dev/include
commands: arm64-apple-darwin20.0.0-clang++
linker: ld64
linker args: -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs, -Wl,-rpath,/Users/ilangold/micromamba/envs/scipy-dev/lib,
-L/Users/ilangold/micromamba/envs/scipy-dev/lib, -ftree-vectorize, -fPIC, -fstack-protector-strong,
-O2, -pipe, -stdlib=libc++, -fvisibility-inlines-hidden, -fmessage-length=0,
-isystem, /Users/ilangold/micromamba/envs/scipy-dev/include, -D_FORTIFY_SOURCE=2,
-isystem, /Users/ilangold/micromamba/envs/scipy-dev/include
name: clang
version: 16.0.6
cython:
commands: cython
linker: cython
name: cython
version: 3.0.8
fortran:
args: -march=armv8.3-a, -ftree-vectorize, -fPIC, -fno-stack-protector, -O2, -pipe,
-isystem, /Users/ilangold/micromamba/envs/scipy-dev/include
commands: /Users/ilangold/micromamba/envs/scipy-dev/bin/arm64-apple-darwin20.0.0-gfortran
linker: ld64
linker args: -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs, -Wl,-rpath,/Users/ilangold/micromamba/envs/scipy-dev/lib,
-L/Users/ilangold/micromamba/envs/scipy-dev/lib, -march=armv8.3-a, -ftree-vectorize,
-fPIC, -fno-stack-protector, -O2, -pipe, -isystem, /Users/ilangold/micromamba/envs/scipy-dev/include
name: gcc
version: 12.3.0
pythran:
include directory: ../../../../micromamba/envs/scipy-dev-array-api/lib/python3.11/site-packages/pythran
version: 0.15.0
Machine Information:
build:
cpu: aarch64
endian: little
family: aarch64
system: darwin
cross-compiled: false
host:
cpu: aarch64
endian: little
family: aarch64
system: darwin
Python Information:
path: /Users/ilangold/micromamba/envs/scipy-dev-array-api/bin/python3.11
version: '3.11'
About this issue
- Original URL
- State: open
- Created 4 months ago
- Comments: 19 (10 by maintainers)
Oh very cool @lucascolley thanks! I had not!
@lucascolley I agree, but it just seemed that this case was special given that covering it is apparently needed just to get the tests to run at all. Otherwise I don’t think I would have posted it.
One thing I can see as a result of thinking about this would be some level of customization for hypothesis tests in the array api test suite. This would allow us to pass tests we want to, while being clear about what we don’t support. I am not really sure it makes sense to have some sort of testing suite where some things pass and others error, which we then have to track by hand somehow. I imagine we will not be the only ones with this issue. Although, I guess trakcing by hand isn’t the worst thing, although it would not let us customize to only do 2D tests for example. So we might want
__getitem__
to pass for 2D but not 3D.This is somewhat related to https://github.com/scipy/scipy/issues/19919 as well. The array api test suite actually provides a nice barrage of tests by which we could try to standardize some of this behavior. I will do some more digging to formalize a list or at least some more concrete points of what exactly is needed/missing.
But that is separate from this issue, which I think is focused on construction, not return types.
From https://data-apis.org/array-api/draft/API_specification/array_object.html: “Furthermore, a conforming implementation of the array API standard must support, at minimum, array objects of rank (i.e., number of dimensions) 0, 1, 2, 3, and 4 and must explicitly document their maximum supported rank
N
. … Conforming implementations must support zero-dimensional arrays.”It is pretty weird indeed to return numpy scalars (i.e., a more-or-less 0-D array from another library) for a standard operation like indexing a 1-D or 2-D array.