Skip to content

TEST: Add tests for triangle.py.#1088

Open
genedan wants to merge 1 commit into
mainfrom
triangle_tests
Open

TEST: Add tests for triangle.py.#1088
genedan wants to merge 1 commit into
mainfrom
triangle_tests

Conversation

@genedan

@genedan genedan commented Jul 7, 2026

Copy link
Copy Markdown
Member

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:

if not obj.is_full:
obj = obj[obj.valuation <= obj.valuation_date]
if hasattr(obj, "disposal_w_"):

Related GitHub Issue(s)

Additional Context for Reviewers

I left any lines dealing with dask/cupy uncovered.

  • 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-only changes with no modifications to triangle.py or runtime behavior; risk is limited to CI/runtime of the expanded test suite.

Overview
Adds a large batch of pytest coverage in test_triangle.py for previously untested branches in triangle.py (dask/cupy paths are explicitly left out per the PR description).

New tests lock in link_ratio behavior: pattern metadata (is_pattern, shape shrink), zero ratios converted to NaN (GH#181), and identity when called on an existing pattern triangle.

index / set_index are covered for DataFrame assignment (including slicer rebuild), length/type validation, and inplace vs copy semantics.

sort_axis tests assert that sorting columns, origin, or development permutes values with labels, not just axis metadata, and is a no-op when already sorted.

shift and trend gain tests for zero-period identity, invalid-axis errors, and unsupported trending axes.

dev_to_val on an already valuation triangle returns self when inplace=True.

Triangle.__init__ with AUTO_SPARSE disabled is tested for defaulting array_backend from cl.options.ARRAY_BACKEND and routing through set_backend when a backend is requested.

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

@github-actions

github-actions Bot commented Jul 7, 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.8% of exported symbols fully typed (188 / 1269)

Known Ambiguous Unknown Total
Project (head) 188 106 975 1269

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

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

Known Ambiguous Unknown Total
Patch 4 0 13 17
Patch symbol details
Symbol Status Change
chainladder.core.tests.test_triangle.test_dev_to_val_inplace_on_val_tri_returns_self ❌ unknown new
chainladder.core.tests.test_triangle.test_index_setter_length_mismatch_raises ❌ unknown new
chainladder.core.tests.test_triangle.test_index_setter_non_dataframe_raises ❌ unknown new
chainladder.core.tests.test_triangle.test_index_setter_with_dataframe ❌ unknown new
chainladder.core.tests.test_triangle.test_init_calls_set_backend_when_auto_sparse_disabled ✅ known new
chainladder.core.tests.test_triangle.test_init_defaults_array_backend_to_option ✅ known new
chainladder.core.tests.test_triangle.test_link_ratio_converts_zero_ratios_to_nan ✅ known new
chainladder.core.tests.test_triangle.test_link_ratio_on_pattern_returns_self ❌ unknown new
chainladder.core.tests.test_triangle.test_link_ratio_sets_pattern_metadata ❌ unknown new
chainladder.core.tests.test_triangle.test_set_index_inplace ❌ unknown new
chainladder.core.tests.test_triangle.test_set_index_not_inplace ❌ unknown new
chainladder.core.tests.test_triangle.test_shift_invalid_axis_raises ❌ unknown new
chainladder.core.tests.test_triangle.test_shift_zero_periods_returns_self ❌ unknown new
chainladder.core.tests.test_triangle.test_sort_axis_columns_reorders_values ✅ known new
chainladder.core.tests.test_triangle.test_sort_axis_development_reorders_values ❌ unknown new
chainladder.core.tests.test_triangle.test_sort_axis_origin_reorders_values ❌ unknown new
chainladder.core.tests.test_triangle.test_trend_invalid_axis_raises ❌ unknown new

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.46%. Comparing base (55f9524) to head (cce1937).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
unittests 90.46% <ø> (+0.28%) ⬆️

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.

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"]]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would a stronger test be tri.loc["A"] == clrd.iloc[:1]?

Comment thread chainladder/core/tests/test_triangle.py
val_tri = qtr.dev_to_val()
assert val_tri.is_val_tri

result = val_tri.dev_to_val(inplace=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

inplace=False?


def test_init_defaults_array_backend_to_option() -> None:
"""
When array_backend is not passed to the constructor (i.e. it is None),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 ...

Comment thread chainladder/core/tests/test_triangle.py
@henrydingliu henrydingliu mentioned this pull request Jul 10, 2026
1 task
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