Skip to content

Support pandas 3, follow SPEC 0 for Python versions, and test each optimizer library separately - #749

Merged
janosg merged 11 commits into
mainfrom
pandas3-python-versions
Nov 25, 2026
Merged

janosg merged 11 commits into
mainfrom
pandas3-python-versions

Conversation

@janosg

@janosg janosg commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Remove the pandas<3 pin and fix what breaks with pandas 3 / 3.1:
    • traceback_report(return_type="dataframe"): stack() no longer drops NaN in pandas 3, so the report contained rows for algorithm/problem pairs that did not fail. The DataFrame is now built directly from the failed runs.
    • estimation_table LaTeX rendering with confidence intervals: assigning via a partial MultiIndex key fails in pandas 3; use a boolean row mask instead.
    • Replace inplace=True calls (deprecated in pandas 3.1) and DataFrame.from_dict(<DataFrame>).
  • Follow SPEC 0: drop Python 3.12, add Python 3.15, and raise the minimum versions to numpy 2.2, scipy 1.15, pandas 2.3 and plotly 6.0.
  • Test each optimizer library in its own environment and CI job, so the libraries never have to be installable together.
  • Python versions in CI: the main Linux job runs 3.13, 3.14 and 3.15. Every job that runs with one Python version uses 3.14, the second newest, because the newest often has problems.
  • The tests-old-pandas job (pandas<3) keeps pandas 2.3 tested; SPEC 0 supports it until June 2027. The tests-old-plotly job is removed, because all plotly 5 releases are more than two years old.
  • The pixi test tasks run the tests in parallel with pytest-xdist (-n auto).
  • pygad ignored stopping_maxiter; it now runs the smaller of num_generations and stopping_maxiter generations.
  • nevergrad_bo was never available: config.py checked find_spec("bayes-optim"), which needs the module name bayes_optim.

One environment and CI job per optimizer library

  • The main test environments only contain scipy (plus JAX on Linux). Each library has a pixi feature and an environment tests-<library>: bayesopt, fides, gfo, iminuit, ipopt, nag, nevergrad, nlopt, pygad, pygmo, pyswarms, tao, tranquilo.
  • The marker of a library (e.g. nlopt) is the only way a test declares that it needs the library:
    • tests/conftest.py adds the marker to every test that is parametrized with an algorithm of the library, e.g. the tests in test_many_algorithms.py. Test modules of one library set it with pytestmark.
    • Tests with a library marker are skipped if one of the library's algorithms is not available. They need no skipif; tests/test_optimizer_library_markers.py fails if a test uses an availability flag such as IS_NLOPT_INSTALLED for anything but guarding imports.
    • pytest --library nlopt runs only the tests of nlopt. It fails if an nlopt algorithm is not available or if a selected test is skipped, so that a broken environment or an empty parametrization cannot hide tests. CI runs it on Linux with Python 3.14; locally: pixi run -e tests-nlopt tests --library nlopt.
  • All test jobs save their coverage report as an artifact; one final job uploads them to codecov together.
  • tests/test_optimizer_library_markers.py also fails if an optimizer module has no marker, environment or CI job.
  • default, docs and type-checking still combine all libraries that can be installed together (all except nevergrad and the Linux-only tao), because ty and the docs need them. The main test environments are no longer in a solve group with them, so the libraries cannot restrict the versions of optimagic's own dependencies.

Tests that the old setup never ran, fixed here:

  • test_bayesian_optimizer.py failed to collect without bayesian-optimization.
  • test_infinite_and_incomplete_bounds.py skipped itself without nevergrad, but the old nevergrad job only ran test_nevergrad.py.
  • nevergrad_de and nevergrad_meta did not reach the required precision in test_many_algorithms.py with the default budget of 1000 evaluations; the test now gives them 20,000.
  • nevergrad_bo (see above). The nevergrad environment now installs bayes-optim, with pytorch-cpu from conda-forge and pydoe<0.4, because bayes-optim imports the module pyDOE, which pydoe 1.0 renamed.
  • test_nevergrad.py read the optimizer names of nevergrad_meta and nevergrad_ngopt with get_args from string annotations, which returns (). The tests over all 37 Meta and 52 NGOpt optimizers, and the check that they exist in nevergrad, therefore never ran. They run now; NoisyBandit does not reach the required precision and is marked as an expected failure.
  • test_with_nonlinear_constraints.py skipped slow cases at runtime; they are now left out of the parametrization, so that --library does not count them as skipped.

Tests that were slow:

  • test_history_collection_with_parallelization set stopping_maxiter=3, which most nevergrad algorithms do not have, so each of them ran 1,000 evaluations (about 14 seconds). The test now sets stopping_maxfun or stopping_maxiter, whichever the algorithm has. With the pygad fix, pygad stops after 3 generations instead of 50 (66 seconds before).
  • test_gfo_internal ran up to 1,000,000 iterations (about 50 seconds); 2,000 give the same result.

Dependency notes

  • On Python 3.15, petsc4py cannot be installed together with cyipopt/pygmo (int64 vs. int32 variant of libscotch on conda-forge). With a separate tao environment this no longer matters.
  • Removed pytorch-cpu from the base dependencies: nothing there uses it (it was added in Fix recent issues with CI #656 to keep pip from installing CUDA torch). The nevergrad environment needs it again for bayes-optim.
  • h5py (for fides), scikit-learn (for bayesian-optimization) and orjson (for kaleido) come from conda-forge, because PyPI has no Python 3.15 wheels for them yet.
  • gradient-free-optimizers (≤1.13.0, also on its main branch) declares pandas<3. A pixi dependency-overrides entry in the gfo environment lets CI test it against pandas 3, and its tests pass. Users who install it with pip are still held at pandas 2 until upstream drops the cap.
  • nevergrad 1.0.12 calls float() on an array with one element in its metamodel, which numpy ≥ 2.4 rejects. Meta and NGOpt optimizers that use the metamodel (e.g. NgIoh4, Wiz, CSEC) crash and leave a thread behind that keeps Python from exiting. This is fixed on nevergrad's main branch (NGOpt is incompatible with numpy 2.4.0 facebookresearch/nevergrad#1707) but not released, so the nevergrad environment uses numpy<2.4 until the next release. Users with numpy ≥ 2.4 hit this bug with these optimizers.

Testing

Locally on macOS with Python 3.14: the main environment, all library environments with --library except tao (Linux-only), the default environment with all compatible libraries, tests-old-pandas, ty and prek pass. Earlier runs also passed on Python 3.15 with pandas 3.1.1 and on Python 3.13 with pandas 2.3.3. The tao job and the combined coverage upload are only checked by CI.

🤖 Generated with Claude Code

Closes #748

janosg and others added 2 commits November 23, 2026 11:19
- Remove the pandas<3 pin and fix the two pandas 3 incompatibilities
  (traceback_report's dataframe output and LaTeX rendering of
  confidence intervals in estimation_table) plus pandas 3.1 deprecations.
- Follow SPEC 0: drop Python 3.12, add Python 3.15.
- Run all Python versions on Linux; macOS and Windows only the latest.
- Add a tests-old-pandas environment and CI job to keep testing pandas 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Remove the optional optimizer libraries from the main test environments.
  Each library gets a pixi feature and an environment tests-<library>.
- tests/conftest.py marks tests that are parametrized with an algorithm with
  the marker of its library. Test modules of one library set the marker with
  pytestmark. CI runs `pytest -m "<library> or <library>_wrappers"` in each
  library environment on Linux.
- All test jobs save their coverage report; one job uploads them together.
- Jobs that run with only one Python version use Python 3.14, the second
  newest, because the newest often has problems.
- Fix test_bayesian_optimizer.py, which failed without bayesian-optimization,
  and give nevergrad_de and nevergrad_meta enough evaluations in
  test_many_algorithms.py; nevergrad never ran in those tests before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.37306% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tests/conftest.py 89.83% 6 Missing ⚠️
src/estimagic/estimation_table.py 83.33% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/optimagic/benchmarking/benchmark_reports.py 98.48% <100.00%> (+0.09%) ⬆️
src/optimagic/config.py 100.00% <100.00%> (ø)
src/optimagic/optimization/history.py 93.57% <100.00%> (ø)
src/optimagic/optimization/multistart.py 91.19% <100.00%> (ø)
src/optimagic/optimization/optimize_result.py 94.73% <100.00%> (ø)
src/optimagic/optimizers/_pounders/gqtpar.py 90.54% <ø> (ø)
src/optimagic/optimizers/nevergrad_optimizers.py 97.05% <100.00%> (+19.96%) ⬆️
src/optimagic/optimizers/pygad_optimizer.py 89.17% <100.00%> (+0.14%) ⬆️
src/optimagic/optimizers/tao_optimizers.py 94.11% <100.00%> (ø)
...rc/optimagic/parameters/consolidate_constraints.py 96.94% <100.00%> (ø)
... and 21 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…das 3.

- petsc4py 3.26 removed TAO.setInitial; use TAO.setSolution, which exists in
  all supported versions (>= 3.18).
- The bootstrap tutorial replaced values of a categorical column, which
  pandas 3 rejects. Convert the column to integers instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@review-notebook-app

Copy link
Copy Markdown

Review Notebooks

Notebooks changed:

Review visual diffs and comment on any notebook cell. All comments sync back to this PR.


Powered by ReviewNB

janosg and others added 5 commits November 23, 2026 13:12
The job names will be required status checks on main. Without the version,
updating the Python version of these jobs does not require a ruleset change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd speed up CI.

- Tests with a library marker are skipped if the library is missing; `pytest
  --library <lib>` runs one library's tests and fails on unavailable algorithms or
  skipped tests. A guard test rejects `skipif` on library availability flags.
- Run the test tasks with pytest-xdist and fix slow tests (history collection with
  nevergrad, gfo internal) and pygad ignoring `stopping_maxiter`.
- Fix `nevergrad_bo` never being available and the nevergrad tests that read empty
  optimizer lists; test nevergrad_bo with bayes-optim and cap numpy below 2.4 in the
  nevergrad environment until nevergrad releases its fix.
- Follow SPEC 0 for minimum versions (numpy 2.2, scipy 1.15, pandas 2.3, plotly 6.0)
  and drop the old-plotly job.
- Solve the main test environments on their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CMA-ES reaches 5e-3 on Linux and 1e-4 on macOS with the same seed. The test never ran
in CI before, because the old nevergrad job only ran test_nevergrad.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ping_maxtime stop nevergrad_cmaes.

nevergrad restarts CMA-ES whenever one of its stopping criteria is met and only
recommends the best point of the last restart, so nevergrad_cmaes could return a much
worse point than it had evaluated. stopping_maxtime was passed to CMA-ES as timeout,
which triggered such restarts instead of ending the optimization.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@janosg
janosg marked this pull request as ready for review November 24, 2026 08:20
@janosg
janosg requested a review from timmens November 24, 2026 08:25
@janosg

janosg commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Probably the runtime of CI can be further reduced by splitting or merging jobs but I want to wait with that until more optimizer wrappers have an extensive test suite as proposed in #746

janosg added a commit that referenced this pull request Nov 24, 2026
The wrapper tests carry the marker of their library instead of a *_wrappers marker
and no longer need to be selected with -m. They run wherever the library is
installed and in the CI job of the library for every pull request, which replaces
the dedicated wrapper test job. Leftover skipif decorators and importorskip calls
are replaced by the library markers. The monthly wrapper-tests workflow runs the
tests of each wrapped library in its own environment with --library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without this, a failing test in a library job also dropped that job's coverage
report, so codecov reported all code that only this job tests as uncovered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
janosg added a commit that referenced this pull request Nov 24, 2026
The wrapper tests carry the marker of their library instead of a *_wrappers marker
and no longer need to be selected with -m. They run wherever the library is
installed and in the CI job of the library for every pull request, which replaces
the dedicated wrapper test job. Leftover skipif decorators and importorskip calls
are replaced by the library markers. The monthly wrapper-tests workflow runs the
tests of each wrapped library in its own environment with --library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@timmens timmens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very very good IMO! No comments from me.

@janosg
janosg merged commit 1d05a14 into main Nov 25, 2026
29 checks passed
@janosg
janosg deleted the pandas3-python-versions branch November 25, 2026 07:26
janosg added a commit that referenced this pull request Nov 25, 2026
Keep the pandas 3 fix of traceback_report from #749, which builds the DataFrame without stack(), on top of the BenchmarkResult objects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
janosg added a commit that referenced this pull request Nov 25, 2026
… of main

- tests/test_optimizer_library_markers.py (#749) read the source files with the platform encoding, which fails on Windows for the non-ASCII characters in the BHHH modules. Read them as UTF-8.
- The LineSearch docs in algorithms.md and numdiff_background.md both cite Dennis1996, which sphinxcontrib-bibtex reports as a duplicate citation; since #741 the docs build fails on warnings. Prefix the keys of the local bibliography of numdiff_background.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Support pandas 3 and remove the upper bound on pandas

2 participants