Skip to content

Better scipy.sparse handling - #12722

Merged
crusaderky merged 7 commits into
dask:mainfrom
crusaderky:fix/scipy-sparse-deprecations
Nov 17, 2026
Merged

crusaderky merged 7 commits into
dask:mainfrom
crusaderky:fix/scipy-sparse-deprecations

Conversation

@crusaderky

@crusaderky crusaderky commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator
  • register sizeof for scipy.sparse.sparray
  • handle DeprecationWarning for scipy.sparse.matrix in Scipy 2.0
  • support cupyx.scipy.sparse in array_safe, asarray_safe, asanyarray_safe (untested)

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

     29 files  ± 0       29 suites  ±0   7h 20m 23s ⏱️ + 40m 32s
 19 934 tests + 2   18 505 ✅ + 2   1 429 💤 ±0  0 ❌ ±0 
436 381 runs  +51  384 906 ✅ +49  51 475 💤 +2  0 ❌ ±0 

Results for commit 676737c. ± Comparison against base commit 9c85cb7.

♻️ This comment has been updated with latest results.

@crusaderky
crusaderky force-pushed the fix/scipy-sparse-deprecations branch from acd3c72 to 162b871 Compare November 13, 2026 14:03
@crusaderky crusaderky changed the title [unsupervised AI] Ignore SciPy sparse matrix deprecation warnings in tests [unsupervised AI] Rework SciPy sparse handling instead of ignoring warnings Nov 13, 2026
@crusaderky
crusaderky force-pushed the fix/scipy-sparse-deprecations branch from 681abdb to f4d5dde Compare November 16, 2026 11:08
…f ignoring them

The blanket `filterwarnings` ignore in pyproject.toml hides every "is being
replaced by" DeprecationWarning, including unrelated ones that could mask real
problems. Replace it with per-test assertions that the warning is raised when
SciPy >= 2.0.0.dev0, so the deprecation stays visible on older SciPy releases.
…arnings

The previous approach blanket-ignored every SciPy spmatrix deprecation warning
through a pyproject filterwarnings entry. That hid the warning for generic dask
API calls and for users who explicitly asked for a sparse matrix, so the library
behaviour was wrong and the filter masked real regressions.

Redesign the handling so that the three cases are distinct:

* A user who explicitly asks for a scipy.sparse matrix still gets the SciPy
  deprecation warning unfiltered. The affected tests now assert it on
  SciPy >= 2.0.0.dev0 and stay silent on older releases.
* A user who explicitly asks for scipy.sparse arrays keeps working, and the
  tests that exercise the array API use the array constructors (eye_array,
  etc.) so no warning is emitted.
* Dask never constructs a sparse matrix on its own. A regression test asserts
  that generic operations on a csr_array emit no spmatrix deprecation warning.

Also harden the library routing: _array_like_safe now identifies SciPy and CuPy
sparse containers through a dedicated helper and always constructs the user's
own container type. sizeof() gains a scipy.sparse.sparray registration, because
sparray is not a subclass of spmatrix and previously fell through to the generic
handler, returning a bogus size for sparse arrays.
…sion tests

`test_sparse_array` called `scipy.sparse.eye_array`, which does not exist in
SciPy 1.11, and the regression test for silent matrix construction called
`Array.T`, which SciPy's sparse arrays reject because dask passes an explicit
`axes` argument. Guard on the `sparray` API and build the sample with
`csr_array(np.eye(...))` instead, and drop the transpose from the regression
test.
@crusaderky
crusaderky force-pushed the fix/scipy-sparse-deprecations branch from f4d5dde to 9e91607 Compare November 16, 2026 23:01
@crusaderky crusaderky changed the title [unsupervised AI] Rework SciPy sparse handling instead of ignoring warnings SciPy 2.0: scipy.sparse.matrix is deprecated in favour of scipy.sparse.sparray Nov 17, 2026
@crusaderky crusaderky changed the title SciPy 2.0: scipy.sparse.matrix is deprecated in favour of scipy.sparse.sparray SciPy 2.0: scipy.sparse.matrix is deprecated Nov 17, 2026
@crusaderky crusaderky changed the title SciPy 2.0: scipy.sparse.matrix is deprecated Better scipy.sparse handling Nov 17, 2026
@crusaderky
crusaderky marked this pull request as ready for review November 17, 2026 00:05
@crusaderky
crusaderky merged commit 934c164 into dask:main Nov 17, 2026
37 of 38 checks passed
@crusaderky
crusaderky deleted the fix/scipy-sparse-deprecations branch November 17, 2026 00:40
crusaderky added a commit to crusaderky/distributed that referenced this pull request Nov 25, 2026
…cation

SciPy 2 deprecates the sparse matrix classes. Dask must not construct one on
its own when the user hands it a sparse array, and must not swallow the warning
when the user does hand it a deprecated matrix.

Assert the container family in the existing round-trip tests, use `toarray()`
instead of `todense()` (which returns the also-deprecated `numpy.matrix`), and
add a test that a full sparse-array round trip through the dask serializer
emits no "is being replaced by" deprecation warning. Mirrors
`test_scipy_sparse_array_never_constructs_matrix` in dask/dask#12722.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant