Skip to content

Allow Triangle.drop() to drop origin levels - #1163

Open
priyam0k wants to merge 2 commits into
casact:mainfrom
priyam0k:feature/drop-origin-levels
Open

Allow Triangle.drop() to drop origin levels#1163
priyam0k wants to merge 2 commits into
casact:mainfrom
priyam0k:feature/drop-origin-levels

Conversation

@priyam0k

@priyam0k priyam0k commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary of Changes

Implements origin-level dropping in Triangle.drop(), so origin periods can be removed via origin= or axis=2 / axis='origin', building on the axis routing added in #1131.

  • tri.drop(origin='1990') and tri.drop(labels='1990', axis=2) are equivalent
  • dropping reduces the origin axis through the existing odims slicing path, so odims and values stay in sync
  • only the first or last origin period(s) may be dropped, so the triangle stays contiguous; dropping an interior period raises ValueError
  • unknown origin labels raise KeyError
  • added tests for dropping the first/last period, the axis equivalents, the interior guard, and the missing-label case
  • added a doctest example to the drop() docstring

Related GitHub Issue(s)

closes #1055, part of #1052

Additional Context for Reviewers


Note

Low Risk
Localized API extension in Triangle.drop() with explicit validation and thorough tests; no auth, persistence, or broad behavioral changes outside origin slicing.

Overview
Triangle.drop() now supports removing origin periods via origin= or axis=2 / axis='origin', alongside the existing column axis. Dropping uses boolean origin slicing so odims and values stay aligned.

Only first or last origin label(s) can be removed; interior drops that would leave a gap raise ValueError. Missing labels raise KeyError. Label handling is broadened with pd.api.types.is_list_like (including native pd.Period labels).

Docs add an origin-drop doctest; tests cover first/last drop, axis equivalents, interior guard, and missing labels. Index and development axes still raise NotImplementedError.

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

Implement origin-axis dropping (axis=2 / origin=). Only the first or last origin period(s) may be dropped so the triangle stays contiguous; interior drops raise ValueError and unknown labels raise KeyError. Closes casact#1055.
@github-actions

github-actions Bot commented Jul 29, 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.9% of exported symbols fully typed (195 / 1307)

Known Ambiguous Unknown Total
Project (head) 195 110 1002 1307

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

Patch (exported symbols added or changed by this PR): 14.3% fully typed (1 / 7)

Known Ambiguous Unknown Total
Patch 1 0 6 7
Patch symbol details
Symbol Status Change
chainladder.core.tests.test_triangle.origin_tri ✅ known new
chainladder.core.tests.test_triangle.test_drop_origin_axis_equivalents ❌ unknown new
chainladder.core.tests.test_triangle.test_drop_origin_first ❌ unknown new
chainladder.core.tests.test_triangle.test_drop_origin_interior_raises ❌ unknown new
chainladder.core.tests.test_triangle.test_drop_origin_last ❌ unknown new
chainladder.core.tests.test_triangle.test_drop_origin_missing_raises ❌ unknown new
chainladder.core.tests.test_triangle.test_drop_origin_period_label ❌ unknown new

@priyam0k
priyam0k marked this pull request as ready for review July 29, 2026 00:31

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

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 82fb260. Configure here.

Comment thread chainladder/core/pandas.py
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.97%. Comparing base (a9f45e1) to head (82eb1a9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1163      +/-   ##
==========================================
+ Coverage   90.94%   90.97%   +0.02%     
==========================================
  Files          91       91              
  Lines        5325     5339      +14     
  Branches      675      678       +3     
==========================================
+ Hits         4843     4857      +14     
  Misses        344      344              
  Partials      138      138              
Flag Coverage Δ
unittests 90.97% <100.00%> (+0.02%) ⬆️

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.

Use pd.api.types.is_list_like instead of np.isscalar so a pd.Period (the origin axis native label type, e.g. tri.origin[-1]) is treated as a scalar rather than crashing on list(). None still flows through list() to preserve bare drop() behavior. Addresses Bugbot review on casact#1163.
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.

Allow Triangle.drop() to drop origin levels

1 participant