Skip to content

docs: fix DevelopmentConstant patterns dict in friedland chapter_8#897

Draft
SaguaroDev wants to merge 1 commit into
casact:mainfrom
SaguaroDev:890-chapter8-developmentconstant-fix
Draft

docs: fix DevelopmentConstant patterns dict in friedland chapter_8#897
SaguaroDev wants to merge 1 commit into
casact:mainfrom
SaguaroDev:890-chapter8-developmentconstant-fix

Conversation

@SaguaroDev
Copy link
Copy Markdown
Contributor

@SaguaroDev SaguaroDev commented May 31, 2026

What

The final code cell of docs/friedland/chapter_8.ipynb errors during the docs build, failing the Doctest CI job:

cl.DevelopmentConstant(patterns=patterns, style='cdf').fit(auto_bi["Paid Claims"]).ldf_
KeyError: 12
  File chainladder/development/constant.py:78, in DevelopmentConstant.fit
    ldf = xp.array([float(self.patterns[item]) for item in obj.ddims])

Why

patterns is defined as a nested dict:

patterns = {
    'reported': {12: 4.0, 24: 2.9, ...},
    'paid':     {12: 90.0, 24: 15.0, ...},
}

But the non-callable patterns path in DevelopmentConstant.fit (and the docstring: "A dictionary key:value representation of age(in months):value") expects a flat {age: value} dict. fit indexes self.patterns[item] for each item in obj.ddims ([12, 24, ...]), so with the nested dict it looks up patterns[12] and raises KeyError.

Fix

Pass the 'paid' sub-dict in the fit cell, since it fits auto_bi["Paid Claims"]. The nested patterns definition is left intact for the preceding cell (which shows the full reported+paid pattern set). One-line change to the notebook source.

Verification

Executed the notebook end-to-end locally (jupyter nbconvert --execute, 120s timeout) — it now completes with no CellExecutionError, and the fit cell produces a clean execute_result with the expected LDFs (12-24: 6.0, 24-36: 3.0, ... matching the Friedland exhibit).

The bug is present on both main and experimental; targeting main.


Note

Low Risk
Documentation-only notebook one-liner; no library or production code paths change.

Overview
Fixes a docs notebook cell that broke Doctest / nbconvert execution: the Friedland chapter 8 example passed the full nested patterns dict into DevelopmentConstant.fit on Paid Claims, but the non-callable patterns path indexes {age_in_months: value} directly (self.patterns[item] for each obj.ddims entry), which raised KeyError: 12.

The change passes patterns['paid'] so the fit uses the paid CDF pattern that matches auto_bi["Paid Claims"], while the earlier cell can still display the nested reported+paid pattern set.

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

…asact#890)

The final cell of docs/friedland/chapter_8.ipynb passed a nested
{'reported': {...}, 'paid': {...}} dict to DevelopmentConstant, but the
non-callable patterns path expects a flat {age: value} dict (per the
docstring). fit() did self.patterns[12] against the top-level keys and
raised KeyError, failing the Doctest CI job (execution_mode='force').

Pass patterns['paid'] in the fit cell since it fits auto_bi['Paid Claims'].
The nested definition is kept for the preceding pedagogical cell. Verified
the notebook now executes end-to-end with no CellExecutionError.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.90%. Comparing base (8a9a46e) to head (de9b0dc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #897   +/-   ##
=======================================
  Coverage   86.90%   86.90%           
=======================================
  Files          87       87           
  Lines        4932     4932           
  Branches      624      624           
=======================================
  Hits         4286     4286           
  Misses        456      456           
  Partials      190      190           
Flag Coverage Δ
unittests 86.90% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@henrydingliu
Copy link
Copy Markdown
Collaborator

kenneth is actively working on this. this may conflict with his complete version. mind keeping this as draft for now?

@SaguaroDev SaguaroDev marked this pull request as draft June 1, 2026 08:40
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