Skip to content

fix(stattests): silence scipy>=1.17 anderson_ksamp midrank deprecation (#1534)#1875

Open
jbbqqf wants to merge 1 commit into
evidentlyai:mainfrom
jbbqqf:fix/1534-scipy-anderson-deprecation
Open

fix(stattests): silence scipy>=1.17 anderson_ksamp midrank deprecation (#1534)#1875
jbbqqf wants to merge 1 commit into
evidentlyai:mainfrom
jbbqqf:fix/1534-scipy-anderson-deprecation

Conversation

@jbbqqf
Copy link
Copy Markdown

@jbbqqf jbbqqf commented May 9, 2026

Summary

Closes #1534.

scipy 1.17 deprecated the implicit `midrank` default of `anderson_ksamp` in
favour of an explicit `variant=` keyword. Calling
`anderson_ksamp(samples)` without `variant=` emits a `DeprecationWarning`
per call (visible in any test run, see the "warnings summary" section of
`pytest tests/stattests/` on `origin/main`):

`Parameter 'variant' has been introduced to replace 'midrank';
'midrank' will be removed in SciPy 1.19.0. Specify 'variant' to silence
this warning. Note that the returned object will no longer be unpackable
as a tuple, and 'critical_values' will be omitted.`

Issue #1534 reports that this breaks user CI policies that promote
`DeprecationWarning` to errors.

Fix

In `src/evidently/legacy/calculations/stattests/anderson_darling_stattest.py`:

  • On scipy>=1.17, call `anderson_ksamp(samples, variant="midrank")` — the
    string matches the legacy `midrank=True` default — and read the result
    object's `.pvalue` attribute.
  • On older scipy (down to 1.10, the project's floor), keep the legacy
    3-tuple unpacking.

Reproduce BEFORE/AFTER yourself (copy-paste)

```bash
git fetch origin && git fetch https://github.com/jbbqqf/evidently.git fix/1534-scipy-anderson-deprecation:_pr1534
pip install -q -e ".[dev]" >/dev/null

run_check() {
python - <<'PY'
import warnings, pandas as pd
from evidently.legacy.calculations.stattests.anderson_darling_stattest import anderson_darling_test
ref = pd.Series([38.7, 41.5, 43.8, 44.5, 45.5, 46.0, 47.7, 58.0])
cur = pd.Series([39.2, 39.3, 39.7, 41.4, 41.8, 42.9, 43.3, 45.8])
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
anderson_darling_test.func(ref, cur, "num", 0.001)
hits = [x for x in w if 'midrank' in str(x.message) or 'variant' in str(x.message)]
print(f"midrank/variant warnings: {len(hits)}")
for h in hits:
print(" -", h.category.name, str(h.message)[:120])
PY
}

BEFORE — origin/main: scipy emits DeprecationWarning.

git checkout origin/main -- src/evidently/legacy/calculations/stattests/anderson_darling_stattest.py
run_check

Expected (scipy>=1.17): 'midrank/variant warnings: 1' with the deprecation message.

AFTER — this branch: silenced.

git checkout _pr1534 -- src/evidently/legacy/calculations/stattests/anderson_darling_stattest.py
run_check

Expected: 'midrank/variant warnings: 0'.

Restore.

git checkout origin/main -- src/evidently/legacy/calculations/stattests/anderson_darling_stattest.py
```

What I ran locally

  • `pytest tests/stattests -q` -> 63 passed
  • `pytest tests/stattests/test_stattests.py::test_anderson_darling_no_scipy_deprecation_warning`
    fails on `origin/main` (DeprecationWarning emitted), passes on this branch.
  • `ruff check` and `ruff format --check` -> clean.

Edge cases

scipy version Path taken Numerical result
1.17+ `variant="midrank"` + `.pvalue` Same p-value as legacy midrank=True
1.10 .. 1.16 Legacy 3-tuple unpack Unchanged
<1.10 Below pyproject floor; not supported n/a

AI disclosure

This pull request was authored with assistance from Anthropic's Claude (an AI
coding assistant) running under my direction. I verified the SciPy
deprecation message and the new return-shape contract via `help(anderson_ksamp)`
on scipy 1.17 before writing the patch.

evidentlyai#1534)

scipy 1.17 deprecated the implicit "midrank" default of anderson_ksamp
in favour of the `variant=` keyword. Calling anderson_ksamp(samples)
without `variant=` emits a DeprecationWarning per call, which fails CI
in projects that promote DeprecationWarnings to errors (the case
reported in issue evidentlyai#1534).

Pass `variant="midrank"` (matching the legacy default) on
scipy>=1.17 and use the new result object's .pvalue attribute.
Fall back to the old 3-tuple shape on scipy<1.17 — required because
pyproject.toml floors scipy at 1.10.

Add a regression test that runs anderson_darling_test under
warnings.catch_warnings and asserts no midrank/variant warning is
emitted.

Co-Authored-By: Claude Opus 4.7 <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.

Fix Scipy Deprecation Warning

1 participant