Skip to content

Common tests#1082

Open
genedan wants to merge 3 commits into
mainfrom
common_tests.py
Open

Common tests#1082
genedan wants to merge 3 commits into
mainfrom
common_tests.py

Conversation

@genedan

@genedan genedan commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary of Changes

Adds tests for Traingle.set_backend() and Triangle._validate_assumption().

Related GitHub Issue(s)

Additional Context for Reviewers

I left out testing dask because that is on the deprecation list.

  • I passed tests locally for both code (uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)

Note

Low Risk
Test and documentation-only changes; no behavioral changes to library code beyond docstrings.

Overview
Adds pytest coverage for Common.set_backend and Common._validate_assumption in test_triangle.py, with a small docstring update on _validate_assumption in common.py.

_validate_assumption tests now exercise scalars, sequences, dicts, callables, axis 2 vs 3 broadcasting shapes, invalid types, and a NumPy 2.x note for set inputs.

set_backend tests cover backend resolution via fitted ldf_, ValueError on unfitted estimators, in-place array_backend updates, deep recursion into nested Common attributes, values type changes (numpy ↔ sparse COO), invalid backend names, and numpy/sparse round-trip equality.

Also adds tests for has_zeta and cum_zeta_ on IncrementalAdditive vs Development. Dask backends are intentionally omitted.

Reviewed by Cursor Bugbot for commit adeca5b. Bugbot is set up for automated code reviews on this repo. Configure here.

@genedan genedan changed the title Common tests.py Common tests Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

Pyright Type Completeness

View the full pyright --verifytypes output for this commit

Project (full chainladder package, at this PR's head): 14.0% of exported symbols fully typed (176 / 1256)

Known Ambiguous Unknown Total
Project (head) 176 107 973 1256

Other symbols referenced but not exported by chainladder: 13

Known Ambiguous Unknown Total
Other (head) 3 1 9 13

Symbols without documentation:

  • Functions without docstring: 314
  • Functions without default param: 0
  • Classes without docstring: 10

Patch (exported symbols added or changed by this PR): 5.9% fully typed (1 / 17)

Known Ambiguous Unknown Total
Patch 1 0 16 17
Patch symbol details
Symbol Status Change
chainladder.core.tests.test_triangle.test_cum_zeta_raises_when_no_zeta ❌ unknown new
chainladder.core.tests.test_triangle.test_cum_zeta_returns_incr_to_cum ❌ unknown new
chainladder.core.tests.test_triangle.test_has_zeta_false ❌ unknown new
chainladder.core.tests.test_triangle.test_has_zeta_true ❌ unknown new
chainladder.core.tests.test_triangle.test_set_backend_deep_propagates_to_nested_common ❌ unknown new
chainladder.core.tests.test_triangle.test_set_backend_inplace_mutates_values ❌ unknown new
chainladder.core.tests.test_triangle.test_set_backend_inplace_updates_array_backend_attr ❌ unknown new
chainladder.core.tests.test_triangle.test_set_backend_invalid_raises ❌ unknown new
chainladder.core.tests.test_triangle.test_set_backend_no_array_backend_raises ✅ known new
chainladder.core.tests.test_triangle.test_set_backend_roundtrip ❌ unknown new
chainladder.core.tests.test_triangle.test_set_backend_via_ldf ❌ unknown new
chainladder.core.tests.test_triangle.test_validate_assumption_axis2 ❌ unknown new
chainladder.core.tests.test_triangle.test_validate_assumption_callable ❌ unknown new
chainladder.core.tests.test_triangle.test_validate_assumption_dict ❌ unknown new
chainladder.core.tests.test_triangle.test_validate_assumption_scalar ❌ unknown new
chainladder.core.tests.test_triangle.test_validate_assumption_sequence ❌ unknown new
chainladder.core.tests.test_triangle.test_validate_assumption_set ❌ unknown new

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.97%. Comparing base (921bfca) to head (adeca5b).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1082      +/-   ##
==========================================
+ Coverage   89.75%   89.97%   +0.22%     
==========================================
  Files          91       91              
  Lines        5408     5288     -120     
  Branches      696      671      -25     
==========================================
- Hits         4854     4758      -96     
+ Misses        389      376      -13     
+ Partials      165      154      -11     
Flag Coverage Δ
unittests 89.97% <100.00%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@genedan

genedan commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

I added tests for the zeta attribute, they seemed succinct enough to tack on to this PR. I'm relying on the prior work of another actuary by using the incrementals in the docs and converting them to cumulative for the scalars in the assert statement:

https://chainladder-python.readthedocs.io/stable/user_guide/development.html#incremental-calculation

Do I get professionalism CE for doing this?

@genedan genedan marked this pull request as ready for review July 1, 2026 16:11
@henrydingliu

Copy link
Copy Markdown
Collaborator

so these tests would be the first time we actually use set_backend on an estimator in the codebase. honestly not sure if it's something we should encourage, or even allow. many estimators have a xp attribute, which could conflict with a manually set backend during subsequent transforming or predicting.

imo we should just take out set_backend from common and put into base (i.e. remove it from estimators). it never made sense to have set_backend on an estimator.

@henrydingliu

Copy link
Copy Markdown
Collaborator

I added tests for the zeta attribute, they seemed succinct enough to tack on to this PR. I'm relying on the prior work of another actuary by using the incrementals in the docs and converting them to cumulative for the scalars in the assert statement:

https://chainladder-python.readthedocs.io/stable/user_guide/development.html#incremental-calculation

Do I get professionalism CE for doing this?

thanks for these tests. i made a lot of short-sighted edits to the zeta stuff a few years back. it was very hard to work with when i needed something similar but slightly different for disposalrate. we'll probably need to refactor incrementaladditive/zeta a bit for friedland chapter 16.

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.

2 participants