Skip to content

ENH: Snapshot statistic outputs before reusing callbacks - #954

Open
antonsoo wants to merge 1 commit into
bashtage:mainfrom
antonsoo:fix/bootstrap-statistic-snapshots
Open

antonsoo wants to merge 1 commit into
bashtage:mainfrom
antonsoo:fix/bootstrap-statistic-snapshots

Conversation

@antonsoo

@antonsoo antonsoo commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

A statistic can reuse an output array, for example with NumPy's out= argument. Subsequent calls then overwrite the saved original-sample estimate and the stored jackknife estimates. This shifts confidence intervals and non-recentered covariances; BCa can incorrectly raise a zero-jackknife-variance error.

import numpy as np
from arch.bootstrap import IIDBootstrap

x = np.arange(10.0)
out = np.empty(())

def statistic(x):
    return np.mean(x, out=out)

a = IIDBootstrap(x, seed=17).conf_int(statistic, reps=100, method="norm")
b = IIDBootstrap(x, seed=17).conf_int(np.mean, reps=100, method="norm")
print(a.ravel(), b.ravel())
np.testing.assert_allclose(a, b)

Before: [3.37564149, 6.62435851] versus [2.87564149, 6.12435851]. After, both give the second interval.

Copy the original-sample result and each jackknife result when retaining them. Bootstrap replication rows already copy through assignment. The regression cases cover scalar and vector outputs, all six interval methods (including nested studentization), covariance, variance and jackknife estimates.

The refreshed change preserves the complex-statistic support and real-only interval validation added in #957. The covariance regression also covers reusable complex outputs.

Validation on current main a93ff73:

  • Twenty regression cases fail before the correction; all 22 pass afterward, including the two existing percentile controls. The complex-statistic area passes alongside them.
  • All 264 recorded annual-sunspot callback pairs agree with allocating callbacks and independent mean/interval references. Allocating outputs remain byte-identical; 168 incorrect reusable-output cases and 24 BCa exceptions are corrected.
  • The complete bootstrap suite with compiled samplers, covariance dtype cases and live docstrings pass locally on Linux/Python 3.14. Changed-file Ruff, Black, isort and Flake8 checks pass.

The earlier KPSS docstring and covariance dtype failures are resolved by current upstream. The new head still needs its hosted CI run; other platforms and a full repository run are not claimed locally.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T18:17:04.837322Z df9ca56 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@antonsoo

Copy link
Copy Markdown
Contributor Author

CI follow-up for d8d642c: the Lint jobs stop on KPSS's duplicate Examples section. The four wheel-test jobs report the same seven covariance dtype failures; all seven also fail on untouched base d921c35. Those assertions were added in #942 and now conflict with main's float64-only conversion and complex-input rejection. The complete bootstrap suite passes (1531 tests), including the new buffer cases.

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.01%. Comparing base (a93ff73) to head (df9ca56).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #954   +/-   ##
=======================================
  Coverage   99.01%   99.01%           
=======================================
  Files         134      135    +1     
  Lines       29563    29605   +42     
  Branches     2290     2293    +3     
=======================================
+ Hits        29271    29313   +42     
  Misses        239      239           
  Partials       53       53           
Flag Coverage Δ
adder 98.95% <100.00%> (+<0.01%) ⬆️
subtractor 98.95% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@antonsoo
antonsoo force-pushed the fix/bootstrap-statistic-snapshots branch from d8d642c to df9ca56 Compare October 17, 2026 18:14
@antonsoo

Copy link
Copy Markdown
Contributor Author

Rebased onto a93ff73 in df9ca56, preserving #957's complex-statistic support and real-only interval checks. Added reusable-complex-output covariance cases as well. All 264 recorded-data callback pairs agree with their allocating/reference results, and the full bootstrap suite passes. The covariance dtype and live-docstring cases that previously failed also pass against the new upstream base; this head still needs its hosted CI run.

@antonsoo

antonsoo commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

The remaining Intel macOS wheel failure is test_valid_results_are_unchanged_by_numpy_scalars: an exact equality differs by about 1e-15. The same test fails on unchanged base a93ff732 and current head df9ca564; both the test and unitroot implementation are unchanged here. The other three wheel-test jobs and both lint jobs pass.

Codecov reports 100% patch coverage. Project coverage is currently 98.93% versus 99.01% on the base, with one fewer reported file; other coverage/pipeline jobs are still pending.

@bashtage

Copy link
Copy Markdown
Owner

This feels a bit like protecting a user against things they shouldn't be doing. The other path would be to simply document this as a requirement for the output of the statistic function. I'm going to call this an ENH since I don't think it is a BUG.

@bashtage bashtage changed the title BUG: Snapshot statistic outputs before reusing callbacks ENH: Snapshot statistic outputs before reusing callbacks Oct 18, 2026
@antonsoo

Copy link
Copy Markdown
Contributor Author

Agreed, ENH fits. This adds support for callbacks that reuse an output buffer. A documented requirement that returned arrays remain unchanged is a reasonable alternative.

This branch has not been deployed

No deployments
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.

2 participants