Skip to content

[ENH] Accept Series and Triangles in DevelopmentConstant patterns - #1484

Open
priyam0k wants to merge 2 commits into
mainfrom
feature/issue-1483-development-constant-patterns
Open

priyam0k wants to merge 2 commits into
mainfrom
feature/issue-1483-development-constant-patterns

Conversation

@priyam0k

@priyam0k priyam0k commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

Extends cl.DevelopmentConstant to natively accept development patterns in tabular and object formats without requiring manual dictionary conversions:

  • pd.Series indexed by development ages or interval strings (e.g., '12-24')
  • 1-row or 1-column pd.DataFrame
  • 1D cl.Triangle objects (e.g., estimator.ldf_ or estimator.cdf_)
  • Fitted estimators exposing ldf_ or cdf_ attributes
  • Added unit tests in test_constant.py covering all supported input formats and validation guards.

Related GitHub Issue(s)

Closes #1483

AI/LLM Usage

Used basic model for drafting unit test cases.

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.
  • 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 how external development patterns are parsed and mapped to ages; mistakes could skew LDF/CDF outputs, though dict/callable paths are preserved and coverage is broad.

Overview
DevelopmentConstant can take external development patterns as pd.Series, 1-row/1-column DataFrame, single-origin Triangle (e.g. another model’s ldf_ / cdf_), or fitted estimators with those attributes—not only a plain dict or callable.

Non-callable inputs are converted via new _normalize_patterns, which resolves ldf_/cdf_ from estimators per style, parses development ages from labels like 12-24, and rejects invalid shapes (multi-origin triangles, 2D DataFrames, unsupported types). Constructor typing and docs are updated; fit behavior for callables is unchanged.

Tests cover each accepted format, index parsing, estimator fallbacks, and the new validation errors.

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

@github-actions

github-actions Bot commented Oct 11, 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.9% of exported symbols fully typed (232 / 1461)

Known Ambiguous Unknown Total
Project (head) 232 106 1123 1461

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

Patch (exported symbols added or changed by this PR): 50.0% fully typed (5 / 10)

Known Ambiguous Unknown Total
Patch 5 0 5 10
Patch symbol details
Symbol Status Change
chainladder.development.constant.DevelopmentConstant.__init__ ✅ known changed (was ❌ unknown)
chainladder.development.constant.DevelopmentConstant.callable_axis ✅ known changed (was ⚠️ ambiguous)
chainladder.development.constant.DevelopmentConstant.groupby ✅ known changed (was ❌ unknown)
chainladder.development.constant.DevelopmentConstant.patterns ✅ known changed (was ❌ unknown)
chainladder.development.constant.DevelopmentConstant.style ✅ known changed (was ⚠️ ambiguous)
chainladder.development.tests.test_constant.test_constant_dataframe_pattern ❌ unknown new
chainladder.development.tests.test_constant.test_constant_estimator_pattern ❌ unknown new
chainladder.development.tests.test_constant.test_constant_invalid_pattern_types ❌ unknown new
chainladder.development.tests.test_constant.test_constant_series_pattern ❌ unknown new
chainladder.development.tests.test_constant.test_constant_triangle_pattern ❌ unknown new

@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.19%. Comparing base (856f87b) to head (f9fd483).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1484      +/-   ##
==========================================
+ Coverage   94.15%   94.19%   +0.03%     
==========================================
  Files          96       96              
  Lines        5852     5890      +38     
  Branches      739      751      +12     
==========================================
+ Hits         5510     5548      +38     
  Misses        221      221              
  Partials      121      121              
Flag Coverage Δ
unittests 94.19% <100.00%> (+0.03%) ⬆️

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.

@priyam0k
priyam0k marked this pull request as ready for review October 11, 2026 19:51

@henrydingliu henrydingliu left a comment

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.

small nits

patterns = patterns.cdf_
elif hasattr(patterns, "ldf_") and style == "ldf":
patterns = patterns.ldf_
elif hasattr(patterns, "cdf_") and not hasattr(patterns, "ldf_"):

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.

this is a neat convenience feature. could you please either document it in the docstring or throw a warning?

elif hasattr(patterns, "ldf_") and not hasattr(patterns, "cdf_"):
patterns = patterns.ldf_

if hasattr(patterns, "values") and hasattr(patterns, "ddims"):

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.

a transformed triangle may have ldf_ and wouldn't get here

@henrydingliu henrydingliu self-assigned this Oct 11, 2026
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.

[ENH] DevelopmentConstant to natively accept Series, DataFrames, and Triangles

2 participants