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

Fixes failing doctests due to numpy 2.x #173

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

thisandthatuser
Copy link
Contributor

Fixes #172

@bluescarni
Copy link
Member

@thisandthatuser thanks for the PR!

Since it seems like it is enough to change a couple of lines, shouldn't we consider using # doctest:+ELLIPSIS instead so that the tests keep on working on both numpy 1 and 2?

@thisandthatuser
Copy link
Contributor Author

Seems desirable but, not being a python nor a ci/cd expert, I do not yet know how to use that instruction for leading characters. I will have a look. It does seem to run on multiple versions of python and the tests do not seem to be failing. That is, it might be that only numpy 2.x is being used in the tests, in which case we should also look into explicitly including numpy 1.

@bluescarni
Copy link
Member

It does seem to run on multiple versions of python and the tests do not seem to be failing. That is, it might be that only numpy 2.x is being used in the tests, in which case we should also look into explicitly including numpy 1.

I think the CI is always picking the latest version of NumPy. I am not so sure it is worth it to double the CI runs in order to test also numpy 1.x though, as the CI is already quite heavy.

@thisandthatuser
Copy link
Contributor Author

I updated the PR. The thing is that the changes introduced will not be picked up in the CI runs because Numpy 1.x will not be used there.

@thisandthatuser
Copy link
Contributor Author

thisandthatuser commented Sep 5, 2024

I realised that doctest does not seem to allow for a leading ellipsis at the moment. Since the tests worked, I had a closer look at the CI run and it seems to be skipping the tests ("ignoring invalid doctest code"):

Document: algorithms
--------------------
/home/runner/work/pygmo2/pygmo2/doc/../../../../local/lib/python3.10/site-packages/pygmo/_py_algorithms.py.rst: WARNING: ignoring invalid doctest code: '>>> import pygmo as pg\n>>> prob = pg.problem(pg.rosenbrock(10))\n>>> pop = pg.population(prob=prob, size=1, seed=0)\n>>> pop.champion_f[0] # doctest: +ELLIPSIS\n...929975.7994682974...\n>>> scp = pg.algorithm(pg.scipy_optimize(method="L-BFGS-B"))\n>>> result = scp.evolve(pop).champion_f\n>>> result[0] # doctest: +ELLIPSIS\n...1.1377...\n>>> pop.problem.get_fevals()\n55\n>>> pop.problem.get_gevals()\n54'
1 items passed all tests:
 198 tests in default
198 tests in 1 items.
198 passed and 0 failed.
Test passed.

Therefore, I think two things are in order:

  • Fix the PR.
  • Ensure tests are not skipped without errors being raised.

I propose to do the former, which will require me to simply require me to use square brackets to ensure there is always something leading the output. The solution is not pretty but I do not see any other option at the moment other than just sticking to newer versions of numpy. As for the tests being skipped, I have no idea why that happens.

Added brackets to certain instructions to make sure doctest is able to process the ellipses (namely leading ones) as intended.
@thisandthatuser
Copy link
Contributor Author

Tests seem to be passing now:

 Document: algorithm
-------------------
1 items passed all tests:
   6 tests in default
6 tests in 1 items.
6 passed and 0 failed.
Test passed.

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.

[BUG] Tests are failing because of changes introduced with numpy 2.x
2 participants