TEST: Add tests for triangle.py.#1088
Conversation
Pyright Type CompletenessView the full Project (full
Other symbols referenced but not exported by
Symbols without documentation:
Patch (exported symbols added or changed by this PR): 23.5% fully typed (4 / 17)
Patch symbol details
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1088 +/- ##
==========================================
+ Coverage 90.18% 90.46% +0.28%
==========================================
Files 91 91
Lines 5409 5287 -122
Branches 696 671 -25
==========================================
- Hits 4878 4783 -95
+ Misses 375 361 -14
+ Partials 156 143 -13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| assert tri.key_labels == ["Company"] | ||
| np.testing.assert_array_equal(tri.kdims, new_index.values) | ||
| # _set_slicers() must have rebuilt .loc against the new key label. | ||
| assert tri.loc["A"].kdims.tolist() == [["A"]] |
There was a problem hiding this comment.
would a stronger test be tri.loc["A"] == clrd.iloc[:1]?
| val_tri = qtr.dev_to_val() | ||
| assert val_tri.is_val_tri | ||
|
|
||
| result = val_tri.dev_to_val(inplace=True) |
|
|
||
| def test_init_defaults_array_backend_to_option() -> None: | ||
| """ | ||
| When array_backend is not passed to the constructor (i.e. it is None), |
There was a problem hiding this comment.
why does this test feel like a deja vu?
| cl.options.reset_option("ARRAY_BACKEND") | ||
|
|
||
|
|
||
| def test_init_calls_set_backend_when_auto_sparse_disabled() -> None: |
There was a problem hiding this comment.
the implementation is kinda messy (maybe a small refactor is in order). i think we can benefit from a more consolidated test, i.e.
#the parameter supplied to the constructor will always override everything else (no idea if this is true, just making up something
assert cl.Triangle(backend = 'numpy').array_backend == 'numpy'
#if parameter is left out, cl.options.AUTO_SPARSE takes precedence
assert ...
Summary of Changes
Add tests for uncovered lines in
triangle.py.@henrydingliu, could you submit a PR testing for these lines for the disposal rate method? I think you'd be able to create a better test than I can:
chainladder-python/chainladder/core/triangle.py
Lines 1193 to 1195 in c45d10b
Related GitHub Issue(s)
Additional Context for Reviewers
I left any lines dealing with dask/cupy uncovered.
uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)Note
Low Risk
Test-only changes with no modifications to
triangle.pyor runtime behavior; risk is limited to CI/runtime of the expanded test suite.Overview
Adds a large batch of pytest coverage in
test_triangle.pyfor previously untested branches intriangle.py(dask/cupy paths are explicitly left out per the PR description).New tests lock in
link_ratiobehavior: pattern metadata (is_pattern, shape shrink), zero ratios converted to NaN (GH#181), and identity when called on an existing pattern triangle.index/set_indexare covered for DataFrame assignment (including slicer rebuild), length/type validation, and inplace vs copy semantics.sort_axistests assert that sortingcolumns,origin, ordevelopmentpermutes values with labels, not just axis metadata, and is a no-op when already sorted.shiftandtrendgain tests for zero-period identity, invalid-axis errors, and unsupported trending axes.dev_to_valon an already valuation triangle returns self wheninplace=True.Triangle.__init__withAUTO_SPARSEdisabled is tested for defaultingarray_backendfromcl.options.ARRAY_BACKENDand routing throughset_backendwhen a backend is requested.Reviewed by Cursor Bugbot for commit cce1937. Bugbot is set up for automated code reviews on this repo. Configure here.