Skip to content

BUG: Accept leading flags positionally in MLEModel loglike, score, hessian - #11043

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-mlemodel-positional-flags
Nov 27, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-mlemodel-positional-flags

Conversation

@bashtage

@bashtage bashtage commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Fixes a regression in 0.15.0. #11029 (the C10 coverage chunk) appends tests to the same test file, so whichever merges second needs a rebase (keep both test blocks).

MLEModel.loglike, score and hessian take their flags (transformed,
includes_fixed, ...) as *args, so that fit can pass them to the optimizer
as a single dictionary. Since 0.15.0, a positional call with fewer flags
than the method has, such as mod.loglike(params, False), raised
"ValueError: zip() argument 2 is shorter than argument 1", because the zip
that maps the positional values to the flag names was made strict.
statsmodels 0.14 accepted any number of leading flags. This is a
regression in 0.15.0.

Changes

  • Any number of leading flags can again be given positionally; the other
    flags take their defaults.
  • The flags after the positional ones can be given by keyword, as for an
    ordinary function: mod.loglike(params, False, complex_step=True). Once
    any flag was positional, the keyword flags were not read: 0.14 and 0.15.0
    passed them on and raised a TypeError further down ("got multiple values
    for keyword argument 'complex_step'", or "unexpected keyword argument
    'approx_centered'" from score).
  • More positional flags than the method has raise a TypeError that names
    the flags. statsmodels 0.14 silently ignored the extra values, and
    0.15.0 raised the ValueError from zip.
  • A flag given both positionally and by keyword raises "got multiple values
    for keyword argument ''" from score and hessian as well; the
    message started with "loglike()" for all three methods.

Not changed

  • Calls with the flags by keyword, with all of the flags positionally, or
    with the dictionary that fit passes.
  • loglikeobs and score_obs, which have ordinary signatures.

Tests

  • For loglike, loglikeobs, score, score_obs and hessian, every number of
    leading positional flags, with values that differ from the defaults,
    gives the same result as the keyword form, with the remaining flags
    either left at their defaults or given by keyword. The calls of loglike,
    score and hessian with some but not all flags fail on main.

  • One flag too many raises a TypeError for each method;
    test_hessian_positional_flags expects the TypeError instead of the
    ValueError from zip.

  • A flag given both ways raises the TypeError for each method.

  • 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 Code (Claude Opus 5.5).
    Used for: finding the bug in a contract audit, writing the fix and its tests, and checking them (tests failing on main, mutation check).
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.

🤖 Generated with Claude Code

…ssian

MLEModel.loglike, score and hessian take their flags (transformed,
includes_fixed, ...) as *args, so that fit can pass them to the optimizer
as a single dictionary. Since 0.15.0, a positional call with fewer flags
than the method has, such as mod.loglike(params, False), raised
"ValueError: zip() argument 2 is shorter than argument 1", because the zip
that maps the positional values to the flag names was made strict.
statsmodels 0.14 accepted any number of leading flags. This is a
regression in 0.15.0.

Changes
- Any number of leading flags can again be given positionally; the other
  flags take their defaults.
- The flags after the positional ones can be given by keyword, as for an
  ordinary function: mod.loglike(params, False, complex_step=True). Once
  any flag was positional, the keyword flags were not read: 0.14 and 0.15.0
  passed them on and raised a TypeError further down ("got multiple values
  for keyword argument 'complex_step'", or "unexpected keyword argument
  'approx_centered'" from score).
- More positional flags than the method has raise a TypeError that names
  the flags. statsmodels 0.14 silently ignored the extra values, and
  0.15.0 raised the ValueError from zip.
- A flag given both positionally and by keyword raises "got multiple values
  for keyword argument '<name>'" from score and hessian as well; the
  message started with "loglike()" for all three methods.

Not changed
- Calls with the flags by keyword, with all of the flags positionally, or
  with the dictionary that fit passes.
- loglikeobs and score_obs, which have ordinary signatures.

Tests
- For loglike, loglikeobs, score, score_obs and hessian, every number of
  leading positional flags, with values that differ from the defaults,
  gives the same result as the keyword form, with the remaining flags
  either left at their defaults or given by keyword. The calls of loglike,
  score and hessian with some but not all flags fail on main.
- One flag too many raises a TypeError for each method;
  test_hessian_positional_flags expects the TypeError instead of the
  ValueError from zip.
- A flag given both ways raises the TypeError for each method.
@bashtage
bashtage force-pushed the wip-mlemodel-positional-flags branch from ca0cf3d to 1e53e37 Compare November 27, 2026 00:30
@bashtage
bashtage marked this pull request as ready for review November 27, 2026 21:34
@bashtage
bashtage merged commit b0dcaa0 into statsmodels:main Nov 27, 2026
14 checks passed
@bashtage
bashtage deleted the wip-mlemodel-positional-flags branch November 27, 2026 21: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