Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Each release links to full notes on the
verdict gets its reason from `ThresholdHelper.match_reason`
([#462](https://github.com/awslabs/stickler/issues/462)).

### Documentation

- The docs recipe for silencing the `auroc_confidence_metric`
`DeprecationWarning` never matched it (it filtered on the comparison engine
module). It now filters by message, adds the pytest `filterwarnings` form, and
names the second `UserWarning` that `compare_with(add_confidence_metrics=True)`
emits.

## [1.1.0] - 2026-12-04

### Added
Expand Down
26 changes: 23 additions & 3 deletions docs/docs/Guides/Evaluation/confidence-evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,39 @@ See [Bulk Evaluation: Map/Reduce](bulk-evaluation.md#mapreduce-single-doc-compar

## Silencing the legacy AUROC deprecation warning

The legacy single-document `auroc_confidence_metric` result key emits a `DeprecationWarning` to point callers at the structured `confidence_metrics["overall"]["auroc"]["value"]` shape. If you've already migrated and want to silence the warning until it's removed, target it by module:
`compare_with(add_confidence_metrics=True)` also writes a legacy `auroc_confidence_metric` key and emits a `DeprecationWarning`, whether or not you read that key. Read `confidence_metrics["overall"]["auroc"]["value"]` instead, and silence the warning by its message:

```python
import warnings

warnings.filterwarnings(
"ignore",
message="The 'auroc_confidence_metric' result key is deprecated",
category=DeprecationWarning,
module="stickler.structured_object_evaluator.models.comparison_engine",
)
```

This is scoped to the comparison engine, so unrelated `DeprecationWarning`s from other libraries (or other parts of stickler) still surface.
Under pytest, a `warnings.filterwarnings(...)` call at module import time is overridden by pytest's per-test filters. Set the filter inside a test or a function-scoped fixture (pytest restores the filters after each test, so a session- or module-scoped fixture covers only the first test in its scope), or use the pytest configuration below (including the separate `UserWarning` filter explained next):

```toml
[tool.pytest.ini_options]
filterwarnings = [
"ignore:The 'auroc_confidence_metric' result key is deprecated:DeprecationWarning",
"ignore:Single-document confidence metrics are a quick sanity check:UserWarning",
]
```

The same call also emits a `UserWarning` ("Single-document confidence metrics are a quick sanity check..."). The AUROC Python filter above does not cover it; silence it with its own filter:

```python
warnings.filterwarnings(
"ignore",
message="Single-document confidence metrics are a quick sanity check",
category=UserWarning,
)
```

Filtering by message keeps unrelated `DeprecationWarning`s from other libraries (or other parts of stickler) visible.

## Further Reading

Expand Down
56 changes: 56 additions & 0 deletions tests/test_confidence_warning_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""The warning filters documented in confidence-evaluation.md must silence the warnings."""

import warnings

import pytest

from stickler import StructuredModel
from stickler.utils import deprecation


class _Doc(StructuredModel):
a: str = "x"


@pytest.fixture(autouse=True)
def _fresh_sentinels(monkeypatch):
monkeypatch.setattr(deprecation, "_warned", set())


def _recorded(*filters):
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
for kwargs in filters:
warnings.filterwarnings("ignore", **kwargs)
_Doc().compare_with(_Doc(), add_confidence_metrics=True)
return caught


# Keep these filters aligned with docs/docs/Guides/Evaluation/
# confidence-evaluation.md, "Silencing the legacy AUROC deprecation warning".
AUROC = {
"message": "The 'auroc_confidence_metric' result key is deprecated",
"category": DeprecationWarning,
}
SINGLE_DOC = {
"message": "Single-document confidence metrics are a quick sanity check",
"category": UserWarning,
}


def test_without_filters_both_warnings_are_emitted():
messages = [str(w.message) for w in _recorded()]
for warning_filter in (AUROC, SINGLE_DOC):
assert any(m.startswith(warning_filter["message"]) for m in messages)


def test_documented_filters_silence_both_warnings():
messages = [str(w.message) for w in _recorded(AUROC, SINGLE_DOC)]
for warning_filter in (AUROC, SINGLE_DOC):
assert not any(m.startswith(warning_filter["message"]) for m in messages)


def test_auroc_filter_leaves_the_user_warning():
messages = [str(w.message) for w in _recorded(AUROC)]
assert not any(m.startswith(AUROC["message"]) for m in messages)
assert any(m.startswith(SINGLE_DOC["message"]) for m in messages)