Skip to content

[TEST] Adding Sparse Triangle to Unittest - #1157

Draft
henrydingliu wants to merge 10 commits into
mainfrom
sparse_test
Draft

[TEST] Adding Sparse Triangle to Unittest#1157
henrydingliu wants to merge 10 commits into
mainfrom
sparse_test

Conversation

@henrydingliu

@henrydingliu henrydingliu commented Jul 26, 2026

Copy link
Copy Markdown
Member

Summary of Changes

Fixing test fixture to supply actual sparse triangles
sped up numpy conversion of prism in test_triangle
resolved failing tests in test_development
added numpy conversion in learning to satisfy skl requirement that sample_weight is dense
resolved failing test in cape_cod
added backend conversion in mack for sparse compatibility
added nanquantile and nanmedian to sparse
added new tests for nanquantile
added nan to nan_to_num in sparse

Related GitHub Issue(s)

fixes #1155

Additional Context for Reviewers

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

Note

Medium Risk
Changes Mack reserve uncertainty recursion and ML sample-weight preparation alongside new sparse reduction helpers; scope is moderate but touches numerically sensitive reserving code paths.

Overview
This PR fixes sparse triangle unittest coverage (#1155) by yielding real sparse-backed triangles from fixtures via set_backend instead of toggling global ARRAY_BACKEND, and runs large prism tests on sparse-only (with a trimmed prism_convert fixture for auto-sparse checks).

Sparse utilities gain nanquantile and nanmedian for COO arrays, plus a configurable nan fill in nan_to_num, with new unit tests.

Sparse compatibility fixes in MackChainladder align triangle backends before concatenation and Mack recursion (e.g. after sum triggers auto-sparse), and DevelopmentML._prep_w_ml forces dense numpy/cupy weights for scikit-learn.

Tests are updated to use Triangle equality and numpy assertions where sparse paths differ, and CapeCod uses at for sparse assignment.

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

@henrydingliu

Copy link
Copy Markdown
Member Author

@genedan can you take care of the 6 failing tests in test_slicing?

@github-actions

github-actions Bot commented Jul 26, 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): 15.1% of exported symbols fully typed (195 / 1294)

Known Ambiguous Unknown Total
Project (head) 195 110 989 1294

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: 315
  • Functions without default param: 0
  • Classes without docstring: 10

Patch (exported symbols added or changed by this PR): 28.6% fully typed (2 / 7); 2 no longer exported

Known Ambiguous Unknown Total
Patch 2 0 5 7
Patch symbol details
Symbol Status Change
chainladder.utils.sparse.nanmedian ❌ unknown new
chainladder.utils.sparse.nanquantile ❌ unknown new
chainladder.utils.tests.test_sparse.test_1D_nanquantile ✅ known new
chainladder.utils.tests.test_sparse.test_keepdims_nanquantile ✅ known new
chainladder.utils.tests.test_utilities.test_maximum_2 ❌ unknown new
chainladder.utils.tests.test_utilities.test_maximum_minimum_1 ❌ unknown new
chainladder.utils.tests.test_utilities.test_minimum_2 ❌ unknown new
chainladder.utils.tests.test_utilities.test_maximum no longer exported (was ❌ unknown)
chainladder.utils.tests.test_utilities.test_minimum no longer exported (was ❌ unknown)

* fixing fixture

expecting errors

* fixing prism

* trying another approach

* some fixes

* more fixes

* more fixes

* fix for learning

* more learning fix

* restoring test

still fails
Comment thread conftest.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7c8e5fe. Configure here.

Comment thread chainladder/utils/sparse.py
@henrydingliu

Copy link
Copy Markdown
Member Author

@genedan there are two more tests in test_triangle that you authored. i'm not sure if those tests should be sparse-compatible. could you please take a look?

@genedan genedan mentioned this pull request Jul 29, 2026
1 task
* further improving prism_convert

* capecod & mack fixes

* fixing test_utilities and removing sparse.testing

* more fixes

* implementing nanquantile and nanmedian

* improving comment, adding tests, fixing bugbot

* fixing test

* removing empty check
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.

[TEST] Sparse test fixtures not working

1 participant