Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: collect methods from private superclasses #179

Merged
merged 1 commit into from
Dec 17, 2024
Merged

BUG: collect methods from private superclasses #179

merged 1 commit into from
Dec 17, 2024

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented Dec 15, 2024

fixes gh-177

@ev-br ev-br added the bug Something isn't working label Dec 15, 2024
@ev-br
Copy link
Member Author

ev-br commented Dec 15, 2024

@mdhaber @steppi could you please check that this branch fixes the issue with stats docstrings?

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

THere is now a little hiccup from gh-180: some things from superclasses are collected twice (Klass.__weakref__). The standard library doctest finding maintains the cache of things already collected, need to duplicate it here.

EDIT: worked around it.

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

I can't say I like how __weakref__ appears depending on the strategy being 'None' or not. Not much to do about it, and it is rather unlikely to have examples in its docstring anyway, so let's just roll with how it is now.

@ev-br ev-br merged commit 7d012aa into main Dec 17, 2024
16 checks passed
@ev-br ev-br deleted the superclasses branch December 17, 2024 11:14
@mdhaber
Copy link

mdhaber commented Dec 17, 2024

Oops, missed the ping. I can't test locally, but I could create a PR to the SciPy repo with a mistake in a doctest to see whether it fails now?

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

Yup, that'd be helpful if you can't test locally. OTOH, why is that. If you can build scipy locally, installing an additional pure python lib is hardly a blocker?

That said, I'm pretty confident this one works as intended, no big issues in either scipy or numpy with scipy-doctest==1.6 which contains this fix. So if you're pressed on time, it's not blocking.

@mdhaber
Copy link

mdhaber commented Dec 17, 2024

Yup, that'd be helpful if you can't test locally. OTOH, why is that. If you can build scipy locally, installing an additional pure python lib is hardly a blocker?

If you can give me the invocation to run the refguide check without dev.py, I can try. But I use an in-place build, and when I've asked before, the answer involved dev.py.

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

Ah, interesting. I think it's

pytest --doctest-modules --doctest-collect=api path/to/scipy

The --doctest-modules --doctest-collect=api part I'm sure about; whether this plays ball with selecting specific test files and/or needs explicit --ignores, is... untested.

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

Also:

  • make sure you've updated scipy-doctest: the fix is in 1.6 only.
  • dev.py additionally passes --assert-plain to pytest; I think it's not needed anymore, but it's pytest magic, so hard to be sure.

@mdhaber
Copy link

mdhaber commented Dec 17, 2024

And I use mamba. Install scipy-doctest with pip nonetheless?

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

Yes, I also use mamba and have no issues with pip install scipy-doctest or pip install -e ..

@mdhaber
Copy link

mdhaber commented Dec 17, 2024

I'm in the scipy repo. I get collection errors when the path/to/scipy is just the scipy subdirectory.

(scipy-dev) C:\Users\matth\Desktop\scipy>pytest --doctest-modules --doctest-collect=api scipy
meson-python: building scipy: meson compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\Users\matth\miniforge3\envs\scipy-dev\Library\bin\ninja.EXE
[2/338] Generating subprojects/highs/src/HConfig.h with a custom command
================================================= test session starts =================================================
platform win32 -- Python 3.12.5, pytest-8.3.2, pluggy-1.5.0
rootdir: C:\Users\matth\Desktop\scipy
configfile: pytest.ini
plugins: anyio-4.4.0, hypothesis-6.112.0, cov-5.0.0, timeout-2.3.1, xdist-3.6.1, scipy_doctest-1.6
collected 3866 items / 20 errors

======================================================= ERRORS ========================================================
___________________________________ ERROR collecting scipy/_build_utils/tempita.py ____________________________________
import file mismatch:
imported module 'tempita' has this __file__ attribute:
  C:\Users\matth\Desktop\scipy\scipy\_build_utils\tempita
which is not the same as the test file we want to collect:
  C:\Users\matth\Desktop\scipy\scipy\_build_utils\tempita.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_____________________________________ ERROR collecting scipy/_lib/_boost_utils.py _____________________________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\_lib\_boost_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'scipy._lib._boost_utils'
____________________________________ ERROR collecting scipy/_lib/_unuran_utils.py _____________________________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\_lib\_unuran_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'scipy._lib._unuran_utils'
______________________________ ERROR collecting scipy/_lib/array_api_extra/docs/conf.py _______________________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\_lib\array_api_extra\docs\conf.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\metadata\__init__.py:397: in from_name
    return next(cls.discover(name=name))
E   StopIteration

During handling of the above exception, another exception occurred:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy\_lib\array_api_extra\docs\conf.py:5: in <module>
    version = release = importlib.metadata.version("array_api_extra")
..\..\miniforge3\envs\scipy-dev\Lib\importlib\metadata\__init__.py:889: in version
    return distribution(distribution_name).version
..\..\miniforge3\envs\scipy-dev\Lib\importlib\metadata\__init__.py:862: in distribution
    return Distribution.from_name(distribution_name)
..\..\miniforge3\envs\scipy-dev\Lib\importlib\metadata\__init__.py:399: in from_name
    raise PackageNotFoundError(name)
E   importlib.metadata.PackageNotFoundError: No package metadata was found for array_api_extra
_____________________ ERROR collecting scipy/_lib/array_api_extra/src/array_api_extra/__init__.py _____________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\_lib\array_api_extra\src\array_api_extra\__init__.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py:5: in <module>
    from ..._array_api_compat_vendor import (  # pyright: ignore[reportMissingImports]
E   ImportError: attempted relative import beyond top-level package

During handling of the above exception, another exception occurred:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy\_lib\array_api_extra\src\array_api_extra\__init__.py:1: in <module>
    from ._funcs import atleast_nd, cov, create_diagonal, expand_dims, kron, setdiff1d, sinc
scipy\_lib\array_api_extra\src\array_api_extra\_funcs.py:3: in <module>
    from ._lib import _compat, _utils
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py:10: in <module>
    from array_api_compat import (  # pyright: ignore[reportMissingTypeStubs]
E   ModuleNotFoundError: No module named 'array_api_compat'
______________________ ERROR collecting scipy/_lib/array_api_extra/src/array_api_extra/_funcs.py ______________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\_lib\array_api_extra\src\array_api_extra\_funcs.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py:5: in <module>
    from ..._array_api_compat_vendor import (  # pyright: ignore[reportMissingImports]
E   ImportError: attempted relative import beyond top-level package

During handling of the above exception, another exception occurred:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy\_lib\array_api_extra\src\array_api_extra\__init__.py:1: in <module>
    from ._funcs import atleast_nd, cov, create_diagonal, expand_dims, kron, setdiff1d, sinc
scipy\_lib\array_api_extra\src\array_api_extra\_funcs.py:3: in <module>
    from ._lib import _compat, _utils
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py:10: in <module>
    from array_api_compat import (  # pyright: ignore[reportMissingTypeStubs]
E   ModuleNotFoundError: No module named 'array_api_compat'
___________________ ERROR collecting scipy/_lib/array_api_extra/src/array_api_extra/_lib/_compat.py ___________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py:5: in <module>
    from ..._array_api_compat_vendor import (  # pyright: ignore[reportMissingImports]
E   ImportError: attempted relative import beyond top-level package

During handling of the above exception, another exception occurred:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py:10: in <module>
    from array_api_compat import (  # pyright: ignore[reportMissingTypeStubs]
E   ModuleNotFoundError: No module named 'array_api_compat'
___________________ ERROR collecting scipy/_lib/array_api_extra/src/array_api_extra/_lib/_utils.py ____________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\_lib\array_api_extra\src\array_api_extra\_lib\_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py:5: in <module>
    from ..._array_api_compat_vendor import (  # pyright: ignore[reportMissingImports]
E   ImportError: attempted relative import beyond top-level package

During handling of the above exception, another exception occurred:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_utils.py:1: in <module>
    from . import _compat
scipy\_lib\array_api_extra\src\array_api_extra\_lib\_compat.py:10: in <module>
    from array_api_compat import (  # pyright: ignore[reportMissingTypeStubs]
E   ModuleNotFoundError: No module named 'array_api_compat'
________________________________ ERROR collecting scipy/interpolate/_interpnd_info.py _________________________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\interpolate\_interpnd_info.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'scipy.interpolate._interpnd_info'
______________________________ ERROR collecting scipy/interpolate/_rbfinterp_pythran.py _______________________________
import file mismatch:
imported module 'scipy.interpolate._rbfinterp_pythran' has this __file__ attribute:
  C:\Users\matth\Desktop\scipy\build\cp312\scipy\interpolate\_rbfinterp_pythran.cp312-win_amd64.pyd
which is not the same as the test file we want to collect:
  C:\Users\matth\Desktop\scipy\scipy\interpolate\_rbfinterp_pythran.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
____________________________ ERROR collecting scipy/linalg/_cython_signature_generator.py _____________________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\linalg\_cython_signature_generator.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'scipy.linalg._cython_signature_generator'
___________________________________ ERROR collecting scipy/linalg/_generate_pyx.py ____________________________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\linalg\_generate_pyx.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'scipy.linalg._generate_pyx'
__________________________________ ERROR collecting scipy/linalg/_linalg_pythran.py ___________________________________
import file mismatch:
imported module 'scipy.linalg._linalg_pythran' has this __file__ attribute:
  C:\Users\matth\Desktop\scipy\build\cp312\scipy\linalg\_linalg_pythran.cp312-win_amd64.pyd
which is not the same as the test file we want to collect:
  C:\Users\matth\Desktop\scipy\scipy\linalg\_linalg_pythran.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
________________________________ ERROR collecting scipy/linalg/_matfuncs_sqrtm_triu.py ________________________________
import file mismatch:
imported module 'scipy.linalg._matfuncs_sqrtm_triu' has this __file__ attribute:
  C:\Users\matth\Desktop\scipy\build\cp312\scipy\linalg\_matfuncs_sqrtm_triu.cp312-win_amd64.pyd
which is not the same as the test file we want to collect:
  C:\Users\matth\Desktop\scipy\scipy\linalg\_matfuncs_sqrtm_triu.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_________________________ ERROR collecting scipy/ndimage/utils/generate_label_testvectors.py __________________________
scipy\ndimage\utils\generate_label_testvectors.py:44: in <module>
    generate_test_vecs("label_inputs.txt", "label_strels.txt", "label_results.txt")
        __builtins__ = <builtins>
        __cached__ = 'C:\\Users\\matth\\Desktop\\scipy\\scipy\\ndimage\\utils\\__pycache__\\generate_label_testvectors.cpython-312.pyc'
        __doc__    = None
        __file__   = 'C:\\Users\\matth\\Desktop\\scipy\\scipy\\ndimage\\utils\\generate_label_testvectors.py'
        __loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x000001D36DCEE030>
        __name__   = 'generate_label_testvectors'
        __package__ = ''
        __spec__   = ModuleSpec(name='generate_label_testvectors', loader=<_frozen_importlib_external.SourceFileLoader object at 0x000001D36DCEE030>, origin='C:\\Users\\matth\\Desktop\\scipy\\scipy\\ndimage\\utils\\generate_label_testvectors.py')
        __warningregistry__ = {'version': 4331}
        generate_test_vecs = <function generate_test_vecs at 0x000001D36DD0B1A0>
        label      = <function label at 0x000001D36B4AA0C0>
        np         = <module 'numpy' from 'C:\\Users\\matth\\miniforge3\\envs\\scipy-dev\\Lib\\site-packages\\numpy\\__init__.py'>
scipy\ndimage\utils\generate_label_testvectors.py:34: in generate_test_vecs
    strels = [np.fromstring(s, dtype=int).reshape((3, 3))
E   DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
        bitimage   = <function generate_test_vecs.<locals>.bitimage at 0x000001D36DD0B060>
        data       = [array([[1., 1., 1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1., 1., 1.],
      ...,
       [False, False, False,  True, False, False, False],
       [ True, False,  True,  True,  True, False,  True]])]
        infile     = 'label_inputs.txt'
        resultfile = 'label_results.txt'
        strelfile  = 'label_strels.txt'
        strels     = [array([[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]]), array([[0., 0., 0.],
       [0., 0., 0.],
       [0....alse, False,  True]]), array([[False, False, False],
       [ True,  True,  True],
       [False, False, False]]), ...]
__________________________________ ERROR collecting scipy/optimize/_group_columns.py __________________________________
import file mismatch:
imported module 'scipy.optimize._group_columns' has this __file__ attribute:
  C:\Users\matth\Desktop\scipy\build\cp312\scipy\optimize\_group_columns.cp312-win_amd64.pyd
which is not the same as the test file we want to collect:
  C:\Users\matth\Desktop\scipy\scipy\optimize\_group_columns.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_________________________________ ERROR collecting scipy/signal/_max_len_seq_inner.py _________________________________
import file mismatch:
imported module 'scipy.signal._max_len_seq_inner' has this __file__ attribute:
  C:\Users\matth\Desktop\scipy\build\cp312\scipy\signal\_max_len_seq_inner.cp312-win_amd64.pyd
which is not the same as the test file we want to collect:
  C:\Users\matth\Desktop\scipy\scipy\signal\_max_len_seq_inner.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_______________________________ ERROR collecting scipy/sparse/_generate_sparsetools.py ________________________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\sparse\_generate_sparsetools.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'scipy.sparse._generate_sparsetools'
___________________________________ ERROR collecting scipy/special/_generate_pyx.py ___________________________________
ImportError while importing test module 'C:\Users\matth\Desktop\scipy\scipy\special\_generate_pyx.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniforge3\envs\scipy-dev\Lib\importlib\__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'scipy.special._generate_pyx'
___________________________________ ERROR collecting scipy/stats/_stats_pythran.py ____________________________________
import file mismatch:
imported module 'scipy.stats._stats_pythran' has this __file__ attribute:
  C:\Users\matth\Desktop\scipy\build\cp312\scipy\stats\_stats_pythran.cp312-win_amd64.pyd
which is not the same as the test file we want to collect:
  C:\Users\matth\Desktop\scipy\scipy\stats\_stats_pythran.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
=============================================== short test summary info ===============================================
ERROR scipy/_build_utils/tempita.py
ERROR scipy/_lib/_boost_utils.py
ERROR scipy/_lib/_unuran_utils.py
ERROR scipy/_lib/array_api_extra/docs/conf.py
ERROR scipy/_lib/array_api_extra/src/array_api_extra/__init__.py
ERROR scipy/_lib/array_api_extra/src/array_api_extra/_funcs.py
ERROR scipy/_lib/array_api_extra/src/array_api_extra/_lib/_compat.py
ERROR scipy/_lib/array_api_extra/src/array_api_extra/_lib/_utils.py
ERROR scipy/interpolate/_interpnd_info.py
ERROR scipy/interpolate/_rbfinterp_pythran.py
ERROR scipy/linalg/_cython_signature_generator.py
ERROR scipy/linalg/_generate_pyx.py
ERROR scipy/linalg/_linalg_pythran.py
ERROR scipy/linalg/_matfuncs_sqrtm_triu.py
ERROR scipy/ndimage/utils/generate_label_testvectors.py - DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use ...
ERROR scipy/optimize/_group_columns.py
ERROR scipy/signal/_max_len_seq_inner.py
ERROR scipy/sparse/_generate_sparsetools.py
ERROR scipy/special/_generate_pyx.py
ERROR scipy/stats/_stats_pythran.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 20 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================= 20 errors in 6.89s ==================================================

When I specify the file, no tests run:

(scipy-dev) C:\Users\matth\Desktop\scipy>pytest --doctest-modules --doctest-collect=api scipy/stats/_probability_distribution.py
meson-python: building scipy: meson compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\Users\matth\miniforge3\envs\scipy-dev\Library\bin\ninja.EXE
[2/338] Generating subprojects/highs/src/HConfig.h with a custom command
================================================= test session starts =================================================
platform win32 -- Python 3.12.5, pytest-8.3.2, pluggy-1.5.0
rootdir: C:\Users\matth\Desktop\scipy
configfile: pytest.ini
plugins: anyio-4.4.0, hypothesis-6.112.0, cov-5.0.0, timeout-2.3.1, xdist-3.6.1, scipy_doctest-1.6
collected 0 items

================================================ no tests ran in 1.37s ================================================

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

Ugh. Can you detail how you build scipy? I'll try replicating.

@mdhaber
Copy link

mdhaber commented Dec 17, 2024

It sounds like spin will support in-place builds, so it might not be worth the trouble?

But I follow the Windows MinGW-w64 + Conda env instructions at Building from source, with the required exceptions: I remove compilers from environment.yml before creating the environment, and instead of pip install scipy --no-build-isolation --no-binary scipy, I do python -m pip install --no-build-isolation --editable .

@lucascolley
Copy link
Member

let me look at getting scipy_doctest on conda-forge

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

Tried (on linux, but that won't matter, hopefully):

$ git clean -xdf
$ pip install --no-build-isolation -e .

... seems to have been built ...

  1. $ pytest -v --doctest-modules --doctest-collect=api --pyargs scipy

Fails at collection stage, similar to #179 (comment)

  1. $ pytest -v --doctest-modules --doctest-collect=api build/cp311/scipy/

runs but misses our configuration. Not strange because conftest.py has not been copied to build/

  1. $ pytest -v --doctest-modules --doctest-collect=api --import-mode=importlib ./scipy --ignore=scipy/special/_generate_pyx.py --ignore=scipy/_build_utils --ignore=scipy/ndimage/utils/

Works! The list of --ignores is constructed experimentally : was adding --ignore of what it complained until it stopped.

  1. Let me now check if --import-mode=importlib is relevant or not:

$ pytest -v --doctest-modules --doctest-collect=api ./scipy --ignore=scipy/special/_generate_pyx.py --ignore=scipy/_build_utils --ignore=scipy/ndimage/utils/

fails at collection, so yes, it's needed. So to sum up:

  1. In the scipy directory (where you ran pip install, feed the scipy directory to pytest: pytest ./scipy
  2. Add --doctest-modules to activate doctesting, add --doctest-collect=api to match the scipy's dev.py
  3. Add --import-mode=importlib (no idea what it does and, yes, I read the docs and fora, and no, I still have no idea)
  4. Add enough --ignore=path/which/fails/collection

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

let me look at getting scipy_doctest on conda-forge

Wow, thank you Lucas!

@mdhaber
Copy link

mdhaber commented Dec 17, 2024

I tried:

(scipy-dev) C:\Users\matth\Desktop\scipy>pytest -v --doctest-modules --doctest-collect=api --import-mode=importlib  ./scipy/stats/_distribution_infrastructure.py --ignore=scipy/special/_generate_pyx.py --ignore=scipy/_build_utils --ignore=s
cipy/ndimage/utils/
meson-python: building scipy: meson compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\Users\matth\miniforge3\envs\scipy-dev\Library\bin\ninja.EXE
[2/338] Generating subprojects/highs/src/HConfig.h with a custom command
================================================= test session starts =================================================
platform win32 -- Python 3.12.5, pytest-8.3.2, pluggy-1.5.0 -- C:\Users\matth\miniforge3\envs\scipy-dev\python.exe
cachedir: .pytest_cache
hypothesis profile 'deterministic' -> database=None, deadline=None, print_blob=True, derandomize=True, suppress_health_check=[HealthCheck.data_too_large, HealthCheck.filter_too_much, HealthCheck.too_slow, HealthCheck.large_base_example, HealthCheck.function_scoped_fixture, HealthCheck.differing_executors]
rootdir: C:\Users\matth\Desktop\scipy
configfile: pytest.ini
plugins: anyio-4.4.0, hypothesis-6.112.0, cov-5.0.0, timeout-2.3.1, xdist-3.6.1, scipy_doctest-1.6
collected 28 items

================================================ no tests ran in 1.44s ================================================

which is your magic command but with the full path to the file in question, but still it doesn't run : (

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

Ah, that actually has an explanation :-). TL;DR: remove --doctest-collect=api

Why on earth? This flag makes doctest collection only look at public objects. What is public is --- in this single-file case --- decided by what is __all__. Since _distribution_infrastructure.py does not have __all__, nothing happends. See how it "collected 28 tests" but then "no tests run", they all got removed by the piece of logic which filters out what's public.

This is what dev.py does (and spin check-docs does in numpy):

        if not args.tests:
            extra_argv += ['--doctest-collect=api']

Without this switch, you're back to collecting all doctests from all functions, so you may get extra failures from objects which are actually private in scipy, but the doctester does not know it.

ev-br added a commit that referenced this pull request Dec 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
No idea what this really does, but apparently it does something. See the discussion around #179 (comment)
@mdhaber
Copy link

mdhaber commented Dec 17, 2024

Hah, ok. Now the problem is that the tests are passing locally (which they shouldn't). They failed as expected on CI : )

(scipy-dev) C:\Users\matth\Desktop\scipy>pytest -v --doctest-modules --import-mode=importlib  ./scipy/stats/_new_distributions.py --ignore=scipy/special/_generate_pyx.py --ignore=scipy/_build_utils --ignore=s
meson-python: building scipy: meson compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\Users\matth\miniforge3\envs\scipy-dev\Library\bin\ninja.EXE
[2/338] Generating subprojects/highs/src/HConfig.h with a custom command
================================================= test session starts =================================================
platform win32 -- Python 3.12.5, pytest-8.3.2, pluggy-1.5.0 -- C:\Users\matth\miniforge3\envs\scipy-dev\python.exe
cachedir: .pytest_cache
hypothesis profile 'deterministic' -> database=None, deadline=None, print_blob=True, derandomize=True, suppress_health_check=[HealthCheck.data_too_large, HealthCheck.filter_too_much, HealthCheck.too_slow, HealthCheck.large_base_example, HealthCheck.function_scoped_fixture, HealthCheck.differing_executors]
rootdir: C:\Users\matth\Desktop\scipy
configfile: pytest.ini
plugins: anyio-4.4.0, hypothesis-6.112.0, cov-5.0.0, timeout-2.3.1, xdist-3.6.1, scipy_doctest-1.6
collected 2 items

scipy/stats/_new_distributions.py::scipy.stats._new_distributions.Normal PASSED                                  [ 50%]
scipy/stats/_new_distributions.py::scipy.stats._new_distributions.Uniform PASSED                                 [100%]

================================================== 2 passed in 1.87s ==================================================

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

Don't know. Wrong branch?

Applied

$ git diff
diff --git a/scipy/stats/_distribution_infrastructure.py b/scipy/stats/_distribution_infrastructure.py
index 291f3d997a..be0cfce12f 100644
--- a/scipy/stats/_distribution_infrastructure.py
+++ b/scipy/stats/_distribution_infrastructure.py
@@ -211,6 +211,9 @@ class _Domain(ABC):
         Returns a text representation of the domain (e.g. ``[0, b)``).
         Used for generating documentation.
 
+    >>> 2 / 3
+    4
+
     """
     symbols = {np.inf: r"\infty", -np.inf: r"-\infty", np.pi: r"\pi", -np.pi: r"-\pi"}

to main, and it does pick a failure in _Domain for me locally.

@lucascolley
Copy link
Member

https://anaconda.org/conda-forge/scipy-doctest

@ev-br
Copy link
Member Author

ev-br commented Dec 17, 2024

How do we advertise it? Maybe add conda-forge and pypi badges to README? I personally don't care about the download counts, just that these builds are discoverable.

@lucascolley
Copy link
Member

Feel free to copy from https://github.com/data-apis/array-api-extra/blob/main/README.md or https://github.com/data-apis/array-api-extra/blob/main/docs/index.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

strategy="api" misses methods from private superclasses
3 participants