Sitelet https://github.com/statsmodels/statsmodels/pull/10434
Skip to content

BUG: Keep array arguments working in the validated stats functions - #10434

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:fix-validation-broadcasting
Oct 5, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:fix-validation-broadcasting

Conversation

@bashtage

@bashtage bashtage commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

The checks added in GH-10379, GH-10386, GH-10388, GH-10392, GH-10393,
GH-10399, GH-10405, GH-10406, GH-10411, GH-10420, GH-10421, GH-10423,
GH-10425, GH-10426 and GH-10431 compare the arguments with scalars,
for example if not 0 < alpha < 1, if low > upp or if dispersion < 0.
These raise "The truth value of an array with more than one element is
ambiguous" for arrays and Series. The functions broadcast over these
arguments and return the same values as the calls for the elements in
0.15.0, for example a confidence interval for several alpha, the power
for several equivalence margins or a table of sample sizes.

Test with np.all and the comparison ufuncs instead, which work for
scalars, lists, arrays and Series, and which also reject NaN. The
error messages are unchanged. A new test checks for 50 arguments that an
array of two valid values gives the same result as the two calls with the
scalars, and that one invalid element (including NaN) is rejected.

Follow-up to GH-10379, GH-10386, GH-10388, GH-10392, GH-10393, GH-10399,
GH-10405, GH-10406, GH-10411, GH-10420, GH-10421, GH-10423, GH-10425,
GH-10426, GH-10431

  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

AI Disclosure

Contributions must comply with the statsmodels AI Policy.

Tick exactly one of the following. If AI tools were used, replace the <...>
placeholders in the second option with the tool name(s) and how the tool's output was
used.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude Sonnet
    Used for: Automated site detection and doc string correction
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.
Details

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass ruff. You can
    verify your changes are well formatted by running
    ruff check . --fix
    
    assuming ruff is installed. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.
  • If AI tools were used to help write this PR, see the
    AI Policy for what disclosure
    and review is expected of you before submitting.

bashtage and others added 2 commits October 4, 2026 19:42
The checks added in statsmodelsGH-10379, statsmodelsGH-10386, statsmodelsGH-10388, statsmodelsGH-10392, statsmodelsGH-10393,
statsmodelsGH-10399, statsmodelsGH-10405, statsmodelsGH-10406, statsmodelsGH-10411, statsmodelsGH-10420, statsmodelsGH-10421, statsmodelsGH-10423,
statsmodelsGH-10425, statsmodelsGH-10426 and statsmodelsGH-10431 compare the arguments with scalars,
for example `if not 0 < alpha < 1`, `if low > upp` or `if dispersion < 0`.
These raise "The truth value of an array with more than one element is
ambiguous" for arrays and Series. The functions broadcast over these
arguments and return the same values as the calls for the elements in
0.15.0, for example a confidence interval for several alpha, the power
for several equivalence margins or a table of sample sizes.

Test with np.all and the comparison ufuncs instead, which work for
scalars, lists, arrays and Series, and which also reject NaN. The
error messages are unchanged. A new test checks for 50 arguments that an
array of two valid values gives the same result as the two calls with the
scalars, and that one invalid element (including NaN) is rejected.

Follow-up to statsmodelsGH-10379, statsmodelsGH-10386, statsmodelsGH-10388, statsmodelsGH-10392, statsmodelsGH-10393, statsmodelsGH-10399,
statsmodelsGH-10405, statsmodelsGH-10406, statsmodelsGH-10411, statsmodelsGH-10420, statsmodelsGH-10421, statsmodelsGH-10423, statsmodelsGH-10425,
statsmodelsGH-10426, statsmodelsGH-10431

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The arguments that broadcast are documented as float or int, but arrays
work, and the previous commit keeps them working. Document them as
float or array_like in the functions of the previous commit and in
chisquare_power, which says in its Notes that it works vectorized.

Follow-up to statsmodelsGH-10379, statsmodelsGH-10386, statsmodelsGH-10388, statsmodelsGH-10392, statsmodelsGH-10393, statsmodelsGH-10399,
statsmodelsGH-10405, statsmodelsGH-10406, statsmodelsGH-10411, statsmodelsGH-10420, statsmodelsGH-10421, statsmodelsGH-10423, statsmodelsGH-10425,
statsmodelsGH-10426, statsmodelsGH-10431

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Thanks, the AI Disclosure section looks complete.

@bashtage
bashtage merged commit c7bcfe9 into statsmodels:main Oct 5, 2026
10 of 12 checks passed
@bashtage
bashtage deleted the fix-validation-broadcasting branch October 5, 2026 10:58
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