test(development): assert exclusions-ignored UserWarning in drop tests (#765)#777
Conversation
casact#765) Per casact#765, ~75 UserWarnings firing from chainladder/development/base.py during tests that deliberately exercise the drop/exclusion path were not being asserted. Wrapping each warning-producing call in `pytest.warns(UserWarning, match=...)` makes the contract explicit: the test fails if the warning stops firing OR if its message changes. Per @kennethshsu's preference on the issue thread, used the `pytest.warns` idiom uniformly (no blanket `@pytest.mark.filterwarnings`), so each individual call site that should warn does so observably. Affected tests (chainladder/development/tests/): - test_development.py: test_drophighlow (5 of 7 calls), test_new_drop_5, test_new_drop_5a (both _set_weight_func calls), test_new_drop_7, test_pipeline (both fits) - test_incremental.py: test_pipeline (both fits); added `import pytest` The two `test_drophighlow` calls that don't warn (`drop_high=0` and `drop_high=[T,F,T,F]`) were left untouched — wrapping them would incorrectly require a warning that doesn't fire. Verified locally: 671 passed, 12 xfailed (pre-existing). Targeted 6-test 'exclusions ignored' warning count drops from 10 to 4 in the pytest summary (the remaining 4 are pytest's source-line accounting from inside the `pytest.warns` blocks, not leaked warnings). Refs casact#765.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #777 +/- ##
=======================================
Coverage 86.08% 86.08%
=======================================
Files 86 86
Lines 4923 4924 +1
Branches 638 638
=======================================
+ Hits 4238 4239 +1
Misses 486 486
Partials 199 199
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
can we add a comment to the source code that the warning is tied to unit test and should not be modified without due consideration? |
Add an in-source comment above each warnings.warn(...) call for the 'Some exclusions have been ignored...' UserWarning, noting that the message is matched by pytest.warns(..., match=...) in the development test suite. Future edits to the warning text must update the corresponding test matchers. Addresses review feedback on casact#777.
|
Done in 44decd5. Added a NOTE comment above each of the four |
* REFACTOR: Reorganize type hierarchy of sparse.py. Move array-level functions to sparse.COO, and keep module-level functions to sp. Replaces xp() with xp.COO() to create sparse arrays when xp used to be callable and was used as a constructor. * FIX: Apply bugbot fixes. * FIX: Apply bugbot fixes. * FIX: Apply bugbot fixes. * TEST: Add unit tests to chainladder.utils.sparse to cover missing lines. * Expanded apriori docstring * Improved docstring and added examples * added code for doc tests * Added a new checkbox to remind PR to run tests * better command and surpressed some warnings * Added example, removed reference to chainladder * doctstrings with examples * Added covergence to the n_iters parameter. * docstring improvement and examples * Added expectedloss method * Improved docstrings and examples * New clrd from CAS * added load_sample * Build(deps): Bump mistune from 3.1.4 to 3.2.1 Bumps [mistune](https://github.com/lepture/mistune) from 3.1.4 to 3.2.1. - [Release notes](https://github.com/lepture/mistune/releases) - [Changelog](https://github.com/lepture/mistune/blob/main/docs/changes.rst) - [Commits](lepture/mistune@v3.1.4...v3.2.1) --- updated-dependencies: - dependency-name: mistune dependency-version: 3.2.1 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Improved docstring * Clarification * Update pyproject.toml * Updated the example in fit * v.0.9.2 release notes * Added a last minute PR * Added more releaes notes from older versions that were not included in the doc site * Bumping pandas to 2.3.3 in preparation of pandas 3.0 * Small typo, thanks AF! * One more approved PR (docstrings improvement) * bumping pandas * Fix Adjustments API page linking to chainladder.workflow (#762) Closes #757 The Adjustments section header in docs/library/api.md was a copy-paste of the Workflow section. The :mod: link and .. automodule:: directive both pointed at chainladder.workflow, so the rendered RTD page for Adjustments hyperlinked to the Workflow module page. The four classes listed under Adjustments (BootstrapODPSample, BerquistSherman, Trend, ParallelogramOLF) all live in chainladder.adjustments, which is the correct target. Co-authored-by: Nick Kinney <nkinney06@gmail.com> * Annotate matplotlib dependency as required for TriangleDisplay.heatmap() (#761) Per maintainer feedback on #758/#761: matplotlib is needed at runtime for TriangleDisplay.heatmap() even though it isn't imported directly, so it must remain a core dependency. Add an inline comment so future contributors don't try to move it again. Co-authored-by: Nick Kinney <nkinney06@gmail.com> * Build(deps): Bump urllib3 from 2.6.3 to 2.7.0 Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.6.3 to 2.7.0. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](urllib3/urllib3@2.6.3...2.7.0) --- updated-dependencies: - dependency-name: urllib3 dependency-version: 2.7.0 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Updated date and some final merged PRs * Add more installation options * Added uv run in the pytest * feat(data): wire clrd2025 into load_sample, docs, and tests (#745) Adds the clrd2025 branch in load_sample mirroring the existing clrd config, but using the modernized CAS Schedule P column names (IncurredLosses rather than IncurLoss). Updates the docstring's complete dataset list and the sample-data documentation page. Adds a targeted test asserting the six LOBs, modern column names, and origin starting at 1998. The underlying clrd2025.csv was added by @kennethshsu on branch #745. Closes part of #745. * Added the new clrd2025 * test(development): assert exclusions-ignored UserWarning in drop tests (#765) (#777) * test(development): assert exclusions-ignored UserWarning in drop tests (#765) Per #765, ~75 UserWarnings firing from chainladder/development/base.py during tests that deliberately exercise the drop/exclusion path were not being asserted. Wrapping each warning-producing call in `pytest.warns(UserWarning, match=...)` makes the contract explicit: the test fails if the warning stops firing OR if its message changes. Per @kennethshsu's preference on the issue thread, used the `pytest.warns` idiom uniformly (no blanket `@pytest.mark.filterwarnings`), so each individual call site that should warn does so observably. Affected tests (chainladder/development/tests/): - test_development.py: test_drophighlow (5 of 7 calls), test_new_drop_5, test_new_drop_5a (both _set_weight_func calls), test_new_drop_7, test_pipeline (both fits) - test_incremental.py: test_pipeline (both fits); added `import pytest` The two `test_drophighlow` calls that don't warn (`drop_high=0` and `drop_high=[T,F,T,F]`) were left untouched — wrapping them would incorrectly require a warning that doesn't fire. Verified locally: 671 passed, 12 xfailed (pre-existing). Targeted 6-test 'exclusions ignored' warning count drops from 10 to 4 in the pytest summary (the remaining 4 are pytest's source-line accounting from inside the `pytest.warns` blocks, not leaked warnings). Refs #765. * Annotate exclusions-ignored warning as test-asserted Add an in-source comment above each warnings.warn(...) call for the 'Some exclusions have been ignored...' UserWarning, noting that the message is matched by pytest.warns(..., match=...) in the development test suite. Future edits to the warning text must update the corresponding test matchers. Addresses review feedback on #777. * Fixed readme failed tests, improved badges and words #768 (#776) * uncomment the test runs on push * badges, rearrangement, words * #686 (#772) * Implemented policy_length * undo the refactor * added tests for policy_length * Fixed bug to round D to int * Fixed an issue on the tests * Removed blank line * Formatted with black * Added more tests * clarification * Moved the parallelogram tests from utilities to parallelogram file * Refactored leap and nonleap * Improved docstring with assumption * Refactored, all bugs resolved * Cleaned up debugger * Clean up, removed debugger * Added a guard to prevent averaging nothing * Added another simple example * Added Henry's tests * Fixed bugbot errors * Added 2 new tests * Removed the fstring * Improved docstring and added two examples (#788) * Improved docstring and added two examples * Added a new test iat exceptions - thanks HL * Allowing project to drop a threshold of 0.1% --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Gene Dan <genedan@gmail.com> Co-authored-by: Kenneth Hsu <kennethshsu@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: wendy-w2029z <wj78919@gmail.com> Co-authored-by: Kevin <74339271+SaguaroDev@users.noreply.github.com> Co-authored-by: Nick Kinney <nkinney06@gmail.com> Co-authored-by: Nick Kinney <Nick.Kinney4@gmail.com>
Closes #765.
Per @kennethshsu's call on the issue thread to use
pytest.warnsuniformly and not blanket-silence with@pytest.mark.filterwarnings, this wraps each.fit()/._set_weight_func()call that emitsUserWarning: "Some exclusions have been ignored..."inpytest.warns(UserWarning, match="exclusions have been ignored").This makes the contract explicit at each call site: the test fails if the warning stops firing OR if its message changes. The two calls in
test_drophighlowthat don't warn (drop_high=0anddrop_high=[T,F,T,F]) were left untouched, since wrapping them would assert a warning that doesn't fire.Affected tests
chainladder/development/tests/test_development.py:test_drophighlow— wrapped 5 of 7.fit()calls (the two that don't warn left as-is)test_new_drop_5— wrapped the single.fit()test_new_drop_5a— wrapped both_set_weight_funccalls (factored out lhs/rhs locals for thepytest.warnsblocks)test_new_drop_7— wrapped the single.fit()test_pipeline— wrapped bothdev1and pipeline.fit()chainladder/development/tests/test_incremental.py:test_pipeline— wrapped bothdev1and pipeline.fit(); addedimport pytestVerification
Local run on the branch:
Targeted
pytest chainladder/development/tests/warning-summary count for"exclusions have been ignored"drops from 10 to 4. The remaining 4 are pytest's source-line accounting from inside thepytest.warnsblocks (deduplicated by warning location), not leaked warnings — runningpytest -W "error::UserWarning"on the targeted set still passes, confirming no warnings escape the context managers.Out of scope
Other warning families flagged in #765 (e.g.
X and sample_weight not aligned, accumulate-overflow RuntimeWarnings, infer-format) are deliberately not touched here. Happy to file follow-up issues if the maintainers want them addressed individually.Note
Low Risk
Low risk: changes are limited to tests and clarifying comments around an existing
UserWarningmessage, with no changes to development calculation logic.Overview
Tests now explicitly assert the existing
UserWarningemitted whenpreserveforces exclusions to be ignored by wrapping affected.fit()/._set_weight_func()calls inpytest.warns(..., match="exclusions have been ignored")(including pipeline tests for bothDevelopmentandIncrementalAdditive).DevelopmentBaseadds inline notes next to each warning site to prevent accidental edits to the warning text or removal ofwarnings.warn(...)without updating the test matchers.Reviewed by Cursor Bugbot for commit 44decd5. Bugbot is set up for automated code reviews on this repo. Configure here.