Skip to content

ENH: Accept 0 and 1 as flags, negative positions and the horizon alias of align - #956

Merged
bashtage merged 6 commits into
mainfrom
a90-val2-bool-positions-alias
Oct 17, 2026
Merged

bashtage merged 6 commits into
mainfrom
a90-val2-bool-positions-alias

Conversation

@bashtage

Copy link
Copy Markdown
Owner

Branch a90-val2-bool-positions-alias, 2 commits on a90-fix-main-tests.
Merge #953 first. It is independent of #955 (they merge cleanly). This PR
covers release decisions 66, 71 and 75.

  • Flags accept 0 and 1 (decision 66). "Accept bool, np.bool_ ... and 1/0
    (int, np.integer types). Anything else is not bool enough."
    • check_bool accepts bool, np.bool_ and Python or NumPy integers equal to
      0 or 1, and returns a Python bool.
    • Another integer raises ValueError. Floats (including 1.0), strings, arrays
      and None (where it is not the documented default) raise TypeError. The
      message is now "must be True, False, 0 or 1".
    • This applies to the 42 flags of the package, among them rescale,
      low_memory (both still accept None), disp (which also keeps "off" and
      "final") and center.
    • arch.test(exit=..., append=...) now checks its flags too. Before, exit=2
      ran the whole test suite.
  • Negative positions count from the end (decision 71). "(b), which is a
    superset of (a). Also document this in docstrings and make sure there is a
    release note."
    • A negative integer position p means nobs + p, as in Python; positions
      outside [-nobs, nobs] raise ValueError. Dates are unchanged.
    • first_obs and last_obs of fit and fix, and cutoff_to_index, act as
      slice bounds: last_obs=-1 drops the last observation and first_obs=-100
      uses the last 100.
    • start of forecast (model, results and volatility process),
      hedgehog_plot and find_index is an observation index: start=-1 is the
      last observation.
    • Every docstring states the rule.
  • align="horizon" (decision 75). "Document it and make it an official
    alias."
    • It is documented in every forecast with align and in
      ARCHModelForecast.
    • The model forecast, which used to reject it, now accepts it through a
      shared check.
    • A ForecastAlignment alias is added to arch._typing.

The contributing guide and the release notes are updated: one entry for the
flags, and entries for negative positions and the alias in New features.

Tests:

  • arch/tests/univariate/test_positions_and_alias.py (46 tests) compares each
    negative position with the equivalent positive one, with Python slicing, and
    with a hand-computed ARCH(1) forecast. 37 of them fail on the base.
  • The flag and position rows of the validation tables are updated (471 changed
    rows fail on the base).

Fast suite 24,738 passed. The only failures are the 7 covariance dtype tests that
also fail on main; a separate PR fixes them. The golden battery is identical.
numpydoc lint 0; style clean.

🤖 Generated with Claude Code

…s of align

Flags (decision 66): check_bool accepts bool, np.bool_ and the Python and NumPy
integers 0 and 1, and returns a Python bool. Other integers raise a ValueError;
floats (including 1.0), strings, arrays and None (where it is not the default) raise
a TypeError. fit(disp=...) keeps "off", "final" and bool, with 0 and 1 now bool.
arch.test now checks its exit and append flags.

Positions (decision 71): check_index, and so first_obs and last_obs of fit and fix and
start of forecast and hedgehog_plot, accept negative integers counted from the end.
first_obs and last_obs are slice bounds (last_obs=-1 drops the last observation) and
start is the index of an observation (start=-1 is the last). The same applies to start
of VolatilityProcess.forecast, cutoff_to_index and find_index. Positions outside
[-nobs, nobs] raise a ValueError, and dates are unchanged. The docstrings say so.

Alias (decision 75): align="horizon" is documented as an alias of "target" in every
forecast docstring and ARCHModelForecast, listed in the error message, and accepted by
the forecast method of the models, which rejected it. It is part of the new
ForecastAlignment type.

The contributing guide and the 9.0 release notes describe the three rules.
The message of check_bool is now "must be True, False, 0 or 1" ("True, False, 0, 1
or None" where None is allowed), since 0 and 1 are accepted.
The maintainer answered decisions 63 and 66-73, so the contributing guide and the
validation module no longer call them provisional.
@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.02%. Comparing base (a93ff73) to head (72acc6b).

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #956    +/-   ##
========================================
  Coverage   99.01%   99.02%            
========================================
  Files         134      135     +1     
  Lines       29563    29859   +296     
  Branches     2290     2303    +13     
========================================
+ Hits        29271    29567   +296     
  Misses        239      239            
  Partials       53       53            
Flag Coverage Δ
adder 98.96% <100.00%> (+0.01%) ⬆️
subtractor 98.96% <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.

@bashtage
bashtage merged commit e677722 into main Oct 17, 2026
24 of 25 checks passed
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.

1 participant