Skip to content

BUG: Do not change the flags dictionary passed to MLEModel.fit - #11062

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-mlemodel-fit-flags-copy
Nov 25, 2026
Merged

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

Conversation

@bashtage

Copy link
Copy Markdown
Member

#11029 (the C10 coverage chunk) appends tests to the same test file, so whichever merges second needs a rebase (keep both test blocks). The other C10F PRs and #11043 also append to test_mlemodel.py: keep every appended block.

MLEModel.fit adds its own entries (transformed, includes_fixed,
score_method, approx_complex_step, average and hessian_method) to the
dictionary of flags that it passes to the optimizer. It added them to the
dictionary given as flags, so that after mod.fit(flags=flags), an empty
dictionary held {'transformed': False, 'includes_fixed': False,
'score_method': 'approx', 'approx_complex_step': True, 'average': False}.

Changes

  • fit adds its entries to a copy of flags.

Not changed

  • The flags passed to the optimizer and the estimates.

Tests

  • After fit, the dictionary given as flags (empty, or with an entry of
    its own) is unchanged; the dictionary passed to the optimizer is a
    different object with fit's entries and the caller's; the estimates
    equal those without flags. Both cases fail on main.

  • 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

@bashtage
bashtage force-pushed the wip-mlemodel-fit-flags-copy branch 2 times, most recently from d00a254 to b0d4ef4 Compare November 25, 2026 12:12
MLEModel.fit adds its own entries (transformed, includes_fixed,
score_method, approx_complex_step, average and hessian_method) to the
dictionary of flags that it passes to the optimizer. It added them to the
dictionary given as `flags`, so that after mod.fit(flags=flags), an empty
dictionary held {'transformed': False, 'includes_fixed': False,
'score_method': 'approx', 'approx_complex_step': True, 'average': False}.

Changes
- fit adds its entries to a copy of `flags`.

Not changed
- The flags passed to the optimizer and the estimates.

Tests
- After fit, the dictionary given as `flags` (empty, or with an entry of
  its own) is unchanged; the dictionary passed to the optimizer is a
  different object with fit's entries and the caller's; the estimates
  equal those without `flags`. Both cases fail on main.
@bashtage
bashtage force-pushed the wip-mlemodel-fit-flags-copy branch from b0d4ef4 to c288d13 Compare November 25, 2026 18:38
@bashtage
bashtage marked this pull request as ready for review November 25, 2026 19:06
@bashtage
bashtage merged commit 6aee533 into statsmodels:main Nov 25, 2026
10 of 11 checks passed
@bashtage
bashtage deleted the wip-mlemodel-fit-flags-copy branch November 27, 2026 10:02
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