scipy / scipy_doctest

Floating-point aware doctesting
BSD 3-Clause "New" or "Revised" License
5 stars 4 forks source link

Filter out Deprecation Warnings #93

Closed Sheila-nk closed 1 year ago

Sheila-nk commented 1 year ago

On executing doctests on some Scipy submodules, all public objects are collected and the deprecated objects collected and doctested raise DeprecationWarnings which can be noisy.

_______________________________________________________________________________________ [doctest] scipy.linalg.triu ________________________________________________________________________________________
137     Returns
138     -------
139     triu : ndarray
140         Return matrix with zeroed elements below the kth diagonal and has
141         same shape and type as `m`.
142 
143     Examples
144     --------
145     >>> from scipy.linalg import triu
146     >>> triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1)
UNEXPECTED EXCEPTION: DeprecationWarning("'tri'/'tril/'triu' are deprecated as of SciPy 1.11.0 and will be removed in v1.13.0. Please use numpy.(tri/tril/triu) instead.")
Traceback (most recent call last):
  File "/Users/sheilakahwai/mambaforge/envs/scipy-dev/lib/python3.11/doctest.py", line 1351, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest scipy.linalg.triu[1]>", line 1, in <module>
  File "/Users/sheilakahwai/Documents/Work/scipy/build-install/lib/python3.11/site-packages/scipy/linalg/_special_matrices.py", line 154, in triu
    out = (1 - tri(m.shape[0], m.shape[1], k - 1, m.dtype.char)) * m
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sheilakahwai/Documents/Work/scipy/build-install/lib/python3.11/site-packages/scipy/linalg/_special_matrices.py", line 64, in tri
    warnings.warn("'tri'/'tril/'triu' are deprecated as of SciPy 1.11.0 and "
DeprecationWarning: 'tri'/'tril/'triu' are deprecated as of SciPy 1.11.0 and will be removed in v1.13.0. Please use numpy.(tri/tril/triu) instead.
/Users/sheilakahwai/Documents/Work/scipy/build-install/lib/python3.11/site-packages/scipy/linalg/_special_matrices.py:146: UnexpectedException

To reproduce on the scipy shell:

pytest --doctest-modules build-install/lib/python3.11/site-packages/scipy/linalg -v

When running doctests through dev.py:

python dev.py doctest -s linalg -v 

There is need to filter out these deprecated objects at the point of collection so that these items are exempted from doctesting.

ev-br commented 1 year ago

There are two separate things at play here. One is individual functions which are deprecated but not marked as such. scipy.linalg.tri seem to be of that kind. What needs investigating here is if they are not marked as deprecated in __all__ listings or if is_deprecated utility of scpdt/utils.py does not pick them.

The other, more annoying, issue is whole modules which are deprecated. E.g. try codata.epsilon0: the whole codata submodule is deprecated via the module-level __geattr__. The warnings this emits are not caught anywhere because AFAIU we just do getattr(module, name). These warnings need to be filtered out at the getattr call sites.

A reproducer for these kinds of things is (or an equivalent stanza of https://github.com/ev-br/scpdt/issues/92#issuecomment-1719533203 )

$ python dev.py shell
$ pytest --pyargs scipy.constants

None of these two issues seem to be related to the plugin, both need to be addressed at the documentation or scpdt level.