Repository navigation
Conversation
Triangle adds together every input row that falls in the same index, origin and development cell. Transaction data needs that, but in data meant to hold one row per cell a repeated key is an error that the sum hides. duplicates="sum" (the default) keeps that behavior. duplicates="raise" raises a ValueError naming up to three repeated cells and their row counts, and duplicates="warn" gives the same message as a warning and then sums. The rows are counted where _aggregate_data groups them, at the triangle's grain, on both its branches. The keyword passes through _split_ult and cl.read_csv; cl.load_sample forwards it already. The user guide's triangle page gets a short paragraph on it. Refs casact#1567. Developed with an AI assistant (Árbol, running Muse).
clrd.csv and clrd2025.csv each give three company names to two group codes: Farmers Mut Ins Co (10323, 17124), Farmers Union Mut Ins Co (28436, 32670) and Madison Mut Ins Co (14443, 30449). With the samples' index ["GRNAME", "LOB"], load_sample summed the rows of the two companies in four name and line pairs. Five codes get new names: 10323 Eagle Mut and 32670 Agraria Ins Co, as in the NAIC listing; 17124, which the listing does not have, Farmers Mut Ins Co (defunct); and 14443 and 30449 Madison Mut Ins Co (IL) and Madison Mut Ins Co (NY). Only the GRNAME field of those codes' rows changes: 385 rows in clrd.csv and 690 in clrd2025.csv. clrd now has 779 triangles instead of 775 and clrd2025 772 instead of 768, and both load with duplicates="raise". The shape doctest in base.py, ClarkLDF's prose and output, and the standalone column of Development's example are updated, as are the stored triangle counts in six notebooks: the triangle and development tutorials, the user guide's triangle, development and workflow pages, and the triangle-from-pandas gallery example. The triangle tutorial's prose count changes with them. test_duplicates_multi_index builds its repeated rows itself now that clrd.csv has none, and test_clrd_samples_one_row_per_cell checks the new counts. Refs casact#1567. Developed with an AI assistant (Árbol, running Muse).
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): 84.6% fully typed (11 / 13)
Patch symbol details
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1580 +/- ##
==========================================
+ Coverage 94.59% 94.78% +0.18%
==========================================
Files 98 98
Lines 6233 6344 +111
Branches 799 810 +11
==========================================
+ Hits 5896 6013 +117
+ Misses 216 212 -4
+ Partials 121 119 -2
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:
|
| ``cl.options.AUTO_SPARSE`` is ``True``, the backend is instead | ||
| chosen automatically based on array size and density, regardless | ||
| of this argument's value. | ||
| duplicates: str, default 'sum' |
There was a problem hiding this comment.
Done in 12dd4e1. duplicates is now typed Literal["sum", "raise", "warn"] in Triangle.__init__, read_csv and the three internal helpers that pass it on, and both docstrings give the type as {'sum', 'raise', 'warn'}, as Triangle.drop does for errors.
(This reply was made with Árbol, an AI assistant, under my direction.)
| pattern=False, | ||
| trailing: bool = True, | ||
| age: Optional[str] = None, | ||
| duplicates: str = "sum", |
There was a problem hiding this comment.
Changed here too, in the same commit.
(This reply was made with Árbol, an AI assistant, under my direction.)
|
|
||
| def test_duplicates_transactions(monthly: Triangle) -> None: | ||
| """ | ||
| Transaction data put many rows in each cell. Built from prism.csv with no |
There was a problem hiding this comment.
small gripe. prism isn't what would conventionally be considered transactional data
There was a problem hiding this comment.
Fair point: prism.csv has one row per claim. In 12dd4e1 the test is renamed test_duplicates_claim_level and its docstring says the rows are claims, and the user guide paragraph that called prism transaction data now calls it claim-level data.
(This reply was made with Árbol, an AI assistant, under my direction.)
- duplicates is annotated Literal["sum", "raise", "warn"] in
Triangle.__init__, read_csv and the helpers that pass it on, and the
docstrings give its type as {'sum', 'raise', 'warn'}.
- prism.csv holds one row per claim, so the test and the user guide call
it claim-level data; the test is renamed test_duplicates_claim_level.
Developed with an AI assistant (Árbol, running Muse).
Summary of Changes
Trianglegets aduplicateskeyword for input rows that fall in the same index, origin and development cell:"sum"(default) adds them together, as before. With the first commit alone, all 54 bundled samples load bit-identical to main."raise"raises aValueErrornaming up to three repeated cells and their row counts."warn"gives the same message as a warning, then sums.cl.read_csvtakes the keyword too, andcl.load_samplepasses it on. The Triangle docstring and the user guide's triangle page document it.The second commit is the
GRNAMErename discussed in #1567, inclrd.csvandclrd2025.csv: 10323 →Eagle Mut, 32670 →Agraria Ins Co, 17124 →Farmers Mut Ins Co (defunct), 14443 →Madison Mut Ins Co (IL)and 30449 →Madison Mut Ins Co (NY). No other field changes.clrdgoes from 775 to 779 triangles andclrd2025from 768 to 772, and both load withduplicates="raise". Before the rename,clrdhas 220 repeated cells. The docstring examples and stored notebook counts are updated. Drop that commit to leave the samples as they are.Related GitHub Issue(s)
Closes #1567.
AI/LLM Usage
This change was made with Árbol, an AI assistant running on Muse, working under my direction. It wrote the change and the tests, ran the checks below and drafted this description.
Additional Context for Reviewers
_aggregate_datasums by, after dates move to their period's start or end, so two payment dates in one month of a monthly triangle count as repeated. The extragroupby(...).size()runs only whenduplicatesis not"sum"._split_ultpasses the keyword on, so ultimate rows are checked too.DevelopmentMLandread_jsonkeep"sum", since they rebuild triangles from the package's own one-row-per-cell output.PaidToIncratio column change in the seventh digit after the rename. They were left for the docs build, which re-executes the notebooks.test_triangle.pyandtest_utilities.pypass with numpy 2.5.4 and pandas 3.1.0 and with the uv.lock versions (numpy 2.3.3, pandas 2.3.3), and with the rename so do the tests that loadclrd. Doctest builds of the changed docstrings pass, and ruff is clean.Submitter's Checklist
[FIX],[FEAT],[DOCS],[TST],[CHORE], or[BRK]).Reviewer's Checklist