lazyarray icon indicating copy to clipboard operation
lazyarray copied to clipboard

Test test_create_with_sparse_array fails with Numpy 2.2.2

Open mcepl opened this issue 7 months ago • 0 comments

When packaging lazyarray 0.6.0 for openSUSE test test_create_with_sparse_array fails:

[   25s] ________________________ test_create_with_sparse_array _________________________
[   25s] 
[   25s]     def test_create_with_sparse_array():
[   25s]         row = np.array([0, 2, 2, 0, 1, 2])
[   25s]         col = np.array([0, 0, 1, 2, 2, 2])
[   25s]         data = np.array([1, 2, 3, 4, 5, 6])
[   25s]         bsr = larray(bsr_matrix((data, (row, col)), shape=(3, 3))) # For bsr_matrix
[   25s]         coo = larray(coo_matrix((data, (row, col)), shape=(3, 3))) # For coo_matrix
[   25s]         csc = larray(csc_matrix((data, (row, col)), shape=(3, 3))) # For csc_matrix
[   25s]         csr = larray(csr_matrix((data, (row, col)), shape=(3, 3))) # For csr_matrix
[   25s]         data_dia = np.array([[1, 2, 3, 4]]).repeat(3, axis=0) # For dia_matrix
[   25s]         offsets_dia = np.array([0, -1, 2]) # For dia_matrix
[   25s]         dia = larray(dia_matrix((data_dia, offsets_dia), shape=(4, 4))) # For dia_matrix
[   25s] >       dok = larray(dok_matrix(((row, col)), shape=(3, 3))) # For dok_matrix
[   25s] 
[   25s] test/test_lazyarray.py:124: 
[   25s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   25s] /usr/lib64/python3.11/site-packages/scipy/sparse/_dok.py:56: in __init__
[   25s]     d = self._coo_container(arg1, shape=shape, dtype=dtype).todok()
[   25s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   25s] 
[   25s] self = <[AttributeError("'coo_matrix' object has no attribute 'data'") raised in repr()] coo_matrix object at 0x7f7132b78650>
[   25s] arg1 = array([[0, 2, 2, 0, 1, 2],
[   25s]        [0, 0, 1, 2, 2, 2]]), shape = (3, 3)
[   25s] dtype = None, copy = None
[   25s] 
[   25s]     def __init__(self, arg1, shape=None, dtype=None, copy=False, *, maxprint=None):
[   25s]         _data_matrix.__init__(self, arg1, maxprint=maxprint)
[   25s]         if not copy:
[   25s]             copy = copy_if_needed
[   25s]     
[   25s]         if isinstance(arg1, tuple):
[   25s]             if isshape(arg1, allow_nd=self._allow_nd):
[   25s]                 self._shape = check_shape(arg1, allow_nd=self._allow_nd)
[   25s]                 idx_dtype = self._get_index_dtype(maxval=max(self._shape))
[   25s]                 data_dtype = getdtype(dtype, default=float)
[   25s]                 self.coords = tuple(np.array([], dtype=idx_dtype)
[   25s]                                      for _ in range(len(self._shape)))
[   25s]                 self.data = np.array([], dtype=data_dtype)
[   25s]                 self.has_canonical_format = True
[   25s]             else:
[   25s]                 try:
[   25s]                     obj, coords = arg1
[   25s]                 except (TypeError, ValueError) as e:
[   25s]                     raise TypeError('invalid input format') from e
[   25s]     
[   25s]                 if shape is None:
[   25s]                     if any(len(idx) == 0 for idx in coords):
[   25s]                         raise ValueError('cannot infer dimensions from zero '
[   25s]                                          'sized index arrays')
[   25s]                     shape = tuple(operator.index(np.max(idx)) + 1
[   25s]                                   for idx in coords)
[   25s]                 self._shape = check_shape(shape, allow_nd=self._allow_nd)
[   25s]                 idx_dtype = self._get_index_dtype(coords,
[   25s]                                                   maxval=max(self.shape),
[   25s]                                                   check_contents=True)
[   25s]                 self.coords = tuple(np.array(idx, copy=copy, dtype=idx_dtype)
[   25s]                                      for idx in coords)
[   25s]                 self.data = getdata(obj, copy=copy, dtype=dtype)
[   25s]                 self.has_canonical_format = False
[   25s]         else:
[   25s]             if issparse(arg1):
[   25s]                 if arg1.format == self.format and copy:
[   25s]                     self.coords = tuple(idx.copy() for idx in arg1.coords)
[   25s]                     self.data = arg1.data.astype(getdtype(dtype, arg1))  # copy=True
[   25s]                     self._shape = check_shape(arg1.shape, allow_nd=self._allow_nd)
[   25s]                     self.has_canonical_format = arg1.has_canonical_format
[   25s]                 else:
[   25s]                     coo = arg1.tocoo()
[   25s]                     self.coords = tuple(coo.coords)
[   25s]                     self.data = coo.data.astype(getdtype(dtype, coo), copy=False)
[   25s]                     self._shape = check_shape(coo.shape, allow_nd=self._allow_nd)
[   25s]                     self.has_canonical_format = False
[   25s]             else:
[   25s]                 # dense argument
[   25s]                 M = np.asarray(arg1)
[   25s]                 if not isinstance(self, sparray):
[   25s]                     M = np.atleast_2d(M)
[   25s]                     if M.ndim != 2:
[   25s]                         raise TypeError(f'expected 2D array or matrix, not {M.ndim}D')
[   25s]     
[   25s]                 self._shape = check_shape(M.shape, allow_nd=self._allow_nd)
[   25s]                 if shape is not None:
[   25s]                     if check_shape(shape, allow_nd=self._allow_nd) != self._shape:
[   25s]                         message = f'inconsistent shapes: {shape} != {self._shape}'
[   25s] >                       raise ValueError(message)
[   25s] E                       ValueError: inconsistent shapes: (3, 3) != (2, 6)
[   25s] 
[   25s] /usr/lib64/python3.11/site-packages/scipy/sparse/_coo.py:89: ValueError
[   25s] =============================== warnings summary ===============================
[   25s] test/test_lazy_arrays_from_Sparse_Matrices.py::test_function_array_general
[   25s]   /usr/lib/python3.11/site-packages/_pytest/python.py:163: PytestReturnNotNoneWarning: Expected None, but test/test_lazy_arrays_from_Sparse_Matrices.py::test_function_array_general returned array([[ -9,  69,  -6],
[   25s]          [-30,  18,   5],
[   25s]          [-50, -93,  -2]]), which will be an error in a future version of pytest.  Did you mean to use `assert` instead of `return`?
[   25s]     warnings.warn(
[   25s] 
[   25s] -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
[   25s] =========================== short test summary info ============================
[   25s] FAILED test/test_lazyarray.py::test_create_with_sparse_array - ValueError: in...
[   25s] =================== 1 failed, 93 passed, 1 warning in 0.32s ====================

Complete build log with all packages used and steps taken to reproduce.

mcepl avatar Mar 19 '25 10:03 mcepl