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 91.27% 91.66% +0.38%
==========================================
Files 91 91
Lines 5411 5411
Branches 692 692
==========================================
+ Hits 4939 4960 +21
+ Misses 338 329 -9
+ Partials 134 122 -12
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]?
There was a problem hiding this comment.
Added, but I'm not sure if this is desirable behavior. The two triangles have different index values, but testing their equality results in True:
clrd.iloc[:1].index
Out[3]:
GRNAME LOB
0 Adriatic Ins Co othliab
tri.loc["A"].index
Out[4]:
Company
0 A
tri.loc["A"] == clrd.iloc[:1]
Out[5]: np.True_There was a problem hiding this comment.
Hmmm nevermind. You can actually do this in Pandas. I guess I'm not a huge fan of this ability but we should be ok.
df = pd.DataFrame({"Sales": [100, 200, 300]}, index=["Apple", "Banana", "Cherry"])
# Relabel specific index values
df_new = df.rename(index={"Apple": "Green Apple", "Cherry": "Berry"})
df.loc['Apple'] == df_new.loc['Green Apple']
Out[2]:
Sales True
dtype: bool
There was a problem hiding this comment.
I guess I'm not a huge fan of this ability but we should be ok.
would it change your mind to consider this ability in this context?
df.loc["A"] = df.loc["B"]
assert df.loc["A"] == df.loc["B"]| val_tri = qtr.dev_to_val() | ||
| assert val_tri.is_val_tri | ||
|
|
||
| result = val_tri.dev_to_val(inplace=True) |
There was a problem hiding this comment.
It should be inplace=True, since the test is deliberately testing the inplace feature.
There was a problem hiding this comment.
but the assert in the next line would still pass if inplace=False?
| 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 ...|
@genedan checking in to see if you've had a chance to look through my comments? |
|
Still working on it - just wanted to prioritize the contributing guidelines and 0.10.0 release work, I'll get back to this once those are done. |
# Conflicts: # chainladder/core/tests/test_triangle.py
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fc400c2. Configure here.
|
|
||
| def test_quantile_vs_median(clrd): | ||
| xp = clrd.get_array_module() | ||
| clrd.get_array_module() |
There was a problem hiding this comment.
Dead leftover module call
Low Severity
test_quantile_vs_median now calls clrd.get_array_module() and discards the result. The call has no side effects used by the quantile/median assertion, so it is dead code left behind after the unused xp assignment was removed.
Reviewed by Cursor Bugbot for commit fc400c2. Configure here.


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 production code modifications; risk is limited to CI/runtime of the expanded test suite.
Overview
Expands
test_triangle.pyto lock in behavior for severalTriangleAPIs that lacked direct tests:link_ratio(pattern metadata, zero→NaN vianum_to_nan, idempotent whenis_pattern),index/set_index(DataFrame-only setter, length/type errors, inplace vs copy),trendandshiftinvalid-axis errors andshift(0)identity,sort_axison columns/origin/development (values permute with labels),dev_to_valno-op on valuation triangles, and__init__array-backend handling whenAUTO_SPARSE/ARRAY_BACKENDoptions apply.The rest of the diff is cosmetic in existing tests (spacing,
isvs==, boolean asserts,type(...) is str).Reviewed by Cursor Bugbot for commit fc400c2. Bugbot is set up for automated code reviews on this repo. Configure here.