Skip to content

statsmodels: backport the scipy 1.18 compat.scipy.apply_where fix - #437

Merged
luhenry merged 2 commits into
mainfrom
statsmodels
Aug 27, 2026
Merged

statsmodels: backport the scipy 1.18 compat.scipy.apply_where fix#437
luhenry merged 2 commits into
mainfrom
statsmodels

Conversation

@luhenry

@luhenry luhenry commented Aug 26, 2026

Copy link
Copy Markdown
Member

Follow-up to #427. That workflow's test phase passed only while the registry topped out at scipy 1.15.2; scipy 1.18.1 is now published for cp312/cp313 and statsmodels 0.14.6 does not build against it.

Differs from upstream

Matrix: cp312, cp313. scipy is a build requirement and our registry has no riscv64 scipy for cp314/cp314t.

Testing

  • same as upstream

License: ✅

Patches

  • 0001-MAINT-fix-compat.scipy.apply_where-for-scipy-internal.patch — Backport [statsmodels/statsmodels@d72a99c]. scipy 1.18 removed scipy._lib._util._lazywhere and scipy._lib.array_api_extra, which statsmodels/compat/scipy.py imports; without it 40 tests fail across test_discrete, test_knockoff, test_predict, test_count_model and test_exponential_smoothing. Reproduces on x86.

pypi.riseproject.dev is currently building scipy 1.18.1 for
cp312/cp313/cp314/cp314t. The moment those wheels publish, this workflow's
PIP_ONLY_BINARY resolution moves statsmodels off scipy 1.15.2 and onto 1.18.1
-- and statsmodels 0.14.6 cannot run against it.

statsmodels/compat/scipy.py reaches into two scipy privates that SciPy 1.18
removed: it imports `scipy._lib.array_api_extra` (moved to
`scipy._external.array_api_extra`) and, when that fails, falls back to
`scipy._lib._util._lazywhere` (deleted). Both arms raise, so every caller of
compat.scipy.apply_where dies -- 41 failures across the ZI distributions,
count-model prediction, knockoff and power suites.

Upstream fixed exactly this in d72a99c9 (2026-03-12) but carries it on main
only; no 0.14.x release has it. The patch is that commit applied unchanged,
and it is a no-op below SciPy 1.18: the added inner try simply falls through
to the original import.

Measured on macOS/arm64 against the released 0.14.6 wheel, running this
workflow's exact test command:

  scipy 1.15.2, unpatched:  17037 passed, 726 skipped, 0 failed
  scipy 1.18.1, unpatched:  16987 passed, 732 skipped, 41 failed, 3 errors
  scipy 1.18.1, patched:    17029 passed, 732 skipped, 2 failed

The 2 residual failures are stats/tests/test_power.py TestTTPowerOneS1 and
TestTTPowerTwoS1 test_roots on the alpha root; upstream main xfails precisely
those two classes for "recent SciPy on Windows and Darwin", so they are the
host's, not riscv64's. Left alone rather than patched blind -- if they show up
on the riscv64 runner they need their own patch with its own evidence.

Patching leaves the checkout dirty, but the workflow already pins
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_STATSMODELS, so the wheel filename keeps
the plain 0.14.6 the docs entry and patches/statsmodels/0.14.6/ path need.
@luhenry luhenry closed this Aug 27, 2026
@luhenry luhenry reopened this Aug 27, 2026
…gent fit

_design_knockoff_equi runs np.linalg.eig on exog.T @ exog, which is symmetric,
so LAPACK's general dgeev is used where dsyevd would do. OpenBLAS's
riscv64_generic kernels leave non-zero imaginary parts there, which makes the
whole knockoff construction complex and raises a casting error -- 13 failures
across test_knockoff.py's equi parametrisations. eigh agrees to 3e-15.

test_seasonal_order[estimated] asserts that a maximum-likelihood fit upstream
itself reports as non-convergent lands within 1e-4 of an exact answer; it
reaches 1.9e-3 here against 2.4e-8 on aarch64, so it is dropped rather than
retuned -- the [heuristic] parametrisation, which is exact to 3.6e-15, keeps
covering the same code.
@luhenry
luhenry merged commit bfbe286 into main Aug 27, 2026
6 checks passed
@luhenry
luhenry deleted the statsmodels branch August 27, 2026 17:40
@luhenry luhenry linked an issue Aug 27, 2026 that may be closed by this pull request
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.

statsmodels riscv64 support

1 participant