(axis, container)
| 5620 | "container", [pytest.param("array", marks=skip_if_no_sparray()), "matrix"] |
| 5621 | ) |
| 5622 | def test_scipy_sparse_concatenate(axis, container): |
| 5623 | pytest.importorskip("scipy.sparse") |
| 5624 | import scipy.sparse |
| 5625 | |
| 5626 | cls = scipy.sparse.csr_matrix if container == "matrix" else scipy.sparse.csr_array |
| 5627 | |
| 5628 | rng = da.random.default_rng() |
| 5629 | |
| 5630 | xs = [] |
| 5631 | for _ in range(2): |
| 5632 | x = rng.random((1000, 10), chunks=(100, 10)) |
| 5633 | x[x < 0.9] = 0 |
| 5634 | xs.append(x) |
| 5635 | |
| 5636 | with assert_scipy_sparse_matrix_deprecated(container == "matrix"): |
| 5637 | ys = [x.map_blocks(cls) for x in xs] |
| 5638 | z = da.concatenate(ys, axis=axis).compute() |
| 5639 | |
| 5640 | if axis == 0: |
| 5641 | sp_concatenate = scipy.sparse.vstack |
| 5642 | elif axis == 1: |
| 5643 | sp_concatenate = scipy.sparse.hstack |
| 5644 | z_expected = sp_concatenate([cls(e.compute()) for e in xs]) |
| 5645 | |
| 5646 | assert (z != z_expected).nnz == 0 |
| 5647 | |
| 5648 | |
| 5649 | @pytest.mark.parametrize("func", [da.asarray, da.asanyarray]) |
nothing calls this directly
no test coverage detected