Skip to content

docs: fix the filter that silences the auroc_confidence_metric warning - #504

Open
pcbeingused333 wants to merge 10 commits into
awslabs:devfrom
pcbeingused333:c0792-docs-warning-filter
Open

pcbeingused333 wants to merge 10 commits into
awslabs:devfrom
pcbeingused333:c0792-docs-warning-filter

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #493

Description of Changes

The documented AUROC warning recipe now filters by message rather than the comparison engine module. It includes Python and pytest configuration forms for both the legacy AUROC DeprecationWarning and the single-document confidence UserWarning.

A filter installed at module import time is overridden by pytest's per-test filters; installing it inside a test or fixture also works. The wording avoids relying on the warning's stacklevel attribution or frequency. A CHANGELOG.md entry is included.

Testing

The three warning-filter tests pass. Their assertion checks that neither documented message is recorded while allowing unrelated warnings. An additional probe injecting an unrelated warning failed before this follow-up and passes afterward. Filter constants point to the corresponding documentation section.

Additional Notes

This PR was prepared with assistance from AI coding agents (Claude Code and Codex).

The documented filter matched module comparison_engine, but the warning
is attributed to structured_model.py, so it never silenced anything.
Filter by message instead, and drop the 'already migrated' framing: the
warning fires on any compare_with(add_confidence_metrics=True) call.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@sromoam sromoam self-assigned this Nov 4, 2026

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @pcbeingused333! This is a real improvement. The message= filter does match the warning, which the old module= filter never did, and the diagnosis in your description is spot on. A few things still need to change before this fully fixes #493.

Needs changes

  1. Add the pytest form. Under pytest, a module-level warnings.filterwarnings("ignore", ...) doesn't silence the warning. pytest wraps each test in its own warnings context and shows DeprecationWarnings regardless. Most users see this warning in their test suite, so please give the config form next to the code form, for example:

    [tool.pytest.ini_options]
    filterwarnings = [
        "ignore:The 'auroc_confidence_metric' result key is deprecated:DeprecationWarning",
    ]
  2. Remove the sentence saying the warning is attributed to structured_model.py (around :141). That attribution is a bug in how the warning is raised (its stacklevel), not intended behaviour. Once that bug is fixed, the sentence would be wrong. The message= advice stands without it.

  3. Correct "once per process" (:129). With Python's default filters the warning isn't shown at all, because it's attributed to library code. Under -W error or pytest's filterwarnings = error, it raises on every call, not just the first. Saying "emits a DeprecationWarning" without the frequency is accurate.

  4. Mention the second warning. The same add_confidence_metrics=True call also emits a UserWarning ("Single-document confidence metrics are a quick sanity check..."). A reader who applies your filter will still see that one and think the recipe is broken. One sentence naming it, with its own message= filter, would cover it.

  5. Add a CHANGELOG entry under [Unreleased], since people pasted the old filter and it never worked (see RELEASING.md).

Would be great, but optional: a test that installs the documented filter and asserts no DeprecationWarning is recorded from compare_with(add_confidence_metrics=True). That would stop the recipe from silently breaking again when the message changes.

The stacklevel bug itself is out of scope here. We'll track it in a separate issue, so please don't feel you need to fix it in this PR.

Also, a heads-up: #525 targets the same issue. Whichever lands first, we'll close the other, so it's worth a quick look to avoid duplicate effort.

On timing: I'm away until Tuesday, November 10, so my next review will be after that. Thanks again!

@sromoam

sromoam commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

As mentioned in the review, the stacklevel bug is now tracked in #541. Nothing to do for it in this PR.

Add the pytest filterwarnings form, drop the structured_model.py
attribution and the 'once per process' claim, document the second
UserWarning with its own filter, add a CHANGELOG entry and a test that
the documented filters silence both warnings.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the review, all points addressed in 81e87cf:

  1. Added the pytest form (filterwarnings in pyproject.toml) next to the warnings.filterwarnings snippet, since the latter does not silence the warning under pytest.
  2. Removed the sentence attributing the warning to structured_model.py.
  3. Corrected the "once per process" wording: with no filter it is shown once, and under -W error it raises every time.
  4. Documented the second UserWarning ("Single-document confidence metrics ...") with its own message= filter.
  5. Added a CHANGELOG.md entry under [Unreleased], and a test (tests/test_confidence_warning_filter.py) checking that the documented filters silence both warnings.

The PR body's "No CHANGELOG entry" note is now outdated; the entry is in.

This comment was drafted with Claude Code.

Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>

# Conflicts:
#	CHANGELOG.md

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @pcbeingused333, this is a really thorough follow-up! Every point from the last review is addressed, and the optional test is a great addition. Three small things before we merge:

  1. Narrow the pytest claim (around confidence-evaluation.md:141). Under pytest, only a filter set at module import time is overridden by pytest's per-test filters. A warnings.filterwarnings(...) call inside a test or a fixture works fine (we checked with a probe test). Something like "a filter set at module level does not apply under pytest; set it in a fixture, or use the filterwarnings config below" keeps readers away from a dead end without steering them off a fix that works.

  2. Add the pytest form for the UserWarning too (around :150). Right now it only has the Python form, just after the doc explains why the Python form isn't enough under pytest. One more line in the TOML block covers it, for example:

    "ignore:Single-document confidence metrics are a quick sanity check:UserWarning",
  3. Loosen the test assertion (tests/test_confidence_warning_filter.py:45). assert _recorded(AUROC, SINGLE_DOC) == [] fails if compare_with ever emits any unrelated warning. Please assert that neither of the two messages appears in the recorded warnings instead.

Optional, only if you have time:

  • The test copies the filter strings rather than reading them from the doc, so the two could drift apart. A comment pointing at the doc section would be enough.
  • tests/structured_object_evaluator/conftest.py already resets deprecation._warned automatically. Moving the test into tests/structured_object_evaluator/ (next to the existing deprecation tests in test_confidence_metrics.py) would let you drop the local fixture.
  • The PR description still says there's no CHANGELOG entry. A quick refresh would help the next reviewer.

Thanks again, this is very close!

Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The pytest wording now distinguishes import-time filters from filters installed inside tests or fixtures, and the TOML example includes the separate UserWarning filter. The test now checks only the two documented message prefixes, so unrelated warnings do not fail it; a comment links the filter constants to the documentation section. All three warning-filter tests and an unrelated-warning probe pass. The refreshed description also records the existing CHANGELOG entry. The UserWarning paragraph now explicitly refers to the AUROC Python filter, since the TOML example already covers both warnings. The test stays at the top level of tests/ for now; happy to move it under tests/structured_object_evaluator/ and drop the local fixture if you prefer.

This response was drafted with Codex.

Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The pytest wording now distinguishes import-time filters from filters installed inside tests or fixtures, and the TOML example includes the separate UserWarning filter. The test now checks only the two documented message prefixes, so unrelated warnings do not fail it; a comment links the filter constants to the documentation section. All three warning-filter tests and an unrelated-warning probe pass. The refreshed description also records the existing CHANGELOG entry. The UserWarning paragraph now explicitly refers to the AUROC Python filter, since the TOML example already covers both warnings. The test stays at the top level of tests/ for now; happy to move it under tests/structured_object_evaluator/ and drop the local fixture if you prefer.

This response was drafted with Codex.

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.

Fix the warnings filter that claims to silence the auroc_confidence_metric deprecation

2 participants