Skip to content

[FEAT] Add base_period and full_triangle arguments to trend. - #1377

Draft
genedan wants to merge 3 commits into
mainfrom
#1376-trend
Draft

genedan wants to merge 3 commits into
mainfrom
#1376-trend

Conversation

@genedan

@genedan genedan commented Sep 17, 2026

Copy link
Copy Markdown
Member

Summary of Changes

Adds two arguments to cl.Trend():

  • base_period: change the base period all the trend factors are relative to
  • full_triangle: returns a full triangle of trend factors instead of just a regular triangle

Related GitHub Issue(s)

closes #1375
closes #1376

#1370

AI/LLM Usage

Claude

Additional Context for Reviewers

Submitter's Checklist

  • I have reviewed and am adhering to the standards outlined in the project Governing Doc.
  • The PR subject title summarizes the changes, with one proper prefix ([FIX], [FEAT], [DOCS], [TST], [CHORE], or [BRK]).
  • I am a human (not a bot), and this PR form is written by a human.

Reviewer's Checklist

  • The implementation addresses the associated issue(s).
  • The implementation is appropriate, maintainable, and follows ARCHITECTURE.md.
  • PR subject title has the proper prefix and the subject is appropriate.
  • Relevant issue(s) are linked.
  • AI/LLM usage is disclosed and appropriate.
  • Documentation and tests are appropriate.
  • CI tests passed, or any failures are acceptable.
  • Leave a comment with the final recommendation (e.g. approve as is, request a secondary review, or flag an area for more review).

Note

Medium Risk
Changes core reserve-adjustment factor math and default vs full-triangle behavior; extensive tests reduce regression risk but downstream CapeCod/pipeline users should verify factor surfaces match expectations.

Overview
cl.Trend gains base_period (re-anchor so that period’s factor is 1.0) and full_triangle (emit factors for the full origin×development rectangle, including cells past the valuation date that default masking leaves NaN).

fit is reworked: trend factors are built by compounding segment trends on a dense grid of 1s (_grid / _accumulate), then divided by the factor at the anchor period (_latest_period or base_period via _get_rebasing_factor). Invalid base_period values raise ValueError. Default output still matches the input triangle’s NaN pattern; full_triangle=True skips that mask and restores the caller’s array backend when needed.

Docs add examples for rebasing and full triangles. test_trend.py expands with parametrized coverage of axes, piecewise segments, gaps, rebasing rules (including quarterly grain), backend preservation, and sklearn clone/get_params for the new arguments.

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

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.96%. Comparing base (3769788) to head (24f60c2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1377      +/-   ##
==========================================
+ Coverage   91.89%   91.96%   +0.07%     
==========================================
  Files          97       97              
  Lines        5516     5566      +50     
  Branches      704      709       +5     
==========================================
+ Hits         5069     5119      +50     
  Misses        325      325              
  Partials      122      122              
Flag Coverage Δ
unittests 91.96% <100.00%> (+0.07%) ⬆️

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.

@github-actions

github-actions Bot commented Sep 17, 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.0% of exported symbols fully typed (211 / 1408)

Known Ambiguous Unknown Total
Project (head) 211 109 1088 1408

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

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

Known Ambiguous Unknown Total
Patch 4 0 17 21
Patch symbol details
Symbol Status Change
chainladder.adjustments.tests.test_trend.test_trend_base_period_at_latest_origin_is_a_noop ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_base_period_coarser_than_grain_takes_earliest ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_base_period_defined_where_data_is_missing ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_base_period_ignores_the_development_grain ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_base_period_moves_the_anchor ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_base_period_outside_the_triangle_raises ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_base_period_rescales_uniformly ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_full_agrees_with_default_where_both_defined ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_full_fills_the_rectangle ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_full_keeps_accruing_past_the_valuation_date ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_is_shaped_like_the_triangle ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_leaves_internal_gaps_empty ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_new_params_survive_sklearn_clone ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_origin_factors_compound_to_the_latest_origin ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_preserves_backend ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_segments_apply_over_their_own_date_ranges ❌ unknown new
chainladder.adjustments.tests.test_trend.test_trend_valuation_factors_compound_to_the_valuation_date ❌ unknown new
chainladder.adjustments.trend.Trend.axis ✅ known changed (was ⚠️ ambiguous)
chainladder.adjustments.trend.Trend.base_period ✅ known new
chainladder.adjustments.trend.Trend.full_triangle ✅ known new
chainladder.adjustments.trend.Trend.trends ✅ known changed (was ⚠️ ambiguous)

@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 acb4cbb. Configure here.

if self.axis in ["origin", 2, -2]:
starts = factors.origin.to_timestamp(how="s")
matches = np.where((starts >= lo) & (starts <= hi))[0]
position = (int(matches[0]), 0) if len(matches) else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rebasing drops origin frequency

Medium Severity

_get_rebasing_factor builds the match window with pd.Period(str(base_period)), which discards the triangle's origin frequency. Fiscal-year origins such as Y-JUN become calendar Y-DEC, so the default latest-origin anchor from _latest_period matches nothing or the wrong year. Trend.fit can raise or emit factors relative to the wrong period on valid fiscal-year triangles, including when base_period is omitted.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit acb4cbb. Configure here.

@genedan
genedan added this pull request to stack #1390 September 17, 2026 23:15
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.

[FEAT] Enable full Triangle for cl.Trend() [FEAT] Add base year parameter to cl.Trend()

1 participant