fix(stattests): silence scipy>=1.17 anderson_ksamp midrank deprecation (#1534)#1875
Open
jbbqqf wants to merge 1 commit into
Open
fix(stattests): silence scipy>=1.17 anderson_ksamp midrank deprecation (#1534)#1875jbbqqf wants to merge 1 commit into
jbbqqf wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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`):
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`:
string matches the legacy `midrank=True` default — and read the result
object's `.pvalue` attribute.
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
fails on `origin/main` (DeprecationWarning emitted), passes on this branch.
Edge cases
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.