Skip to content

DEP: deprecate np.testing.suppress_warnings #29293

@ngoldbaum

Description

@ngoldbaum

Python 3.14 makes the warnings module thread-safe. While testing whether we can globally allow tests that use warnings to run on 3.14 under pytest-run-parallel, I discovered that SciPy is making heavy use of np.testing.supress_warnings, and it isn't thread-safe:

PARALLEL FAILED scipy/cluster/tests/test_vq.py::TestKMeans::test_kmeans_lost_cluster[numpy] - AttributeError: 'suppress_warnings' object has no attribute '_orig_show'

(from logs of a SciPy test run)

The relevant SciPy test is here:

https://github.com/scipy/scipy/blob/8f51c63d384f0e9c966355362f982ea7ec2de1cc/scipy/cluster/tests/test_vq.py#L276

I'm not totally sure why the failure is happening - I would think each test instance would have its own private context manager instance, but the error I'm seeing makes it seem like threads are sharing the context manager.

In any case, it's clearly thread-unsafe and relies on manipulating global state stored in the warnings module:

self._orig_show = warnings.showwarning
self._filters = warnings.filters
warnings.filters = self._filters[:]

The whole thing should probably be implemented using a context variable instead of manipulating / relying on global state on the warnings module.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions