Skip to content

[ENH] set partial triangle through loc#1103

Open
henrydingliu wants to merge 1 commit into
mainfrom
loc_setter
Open

[ENH] set partial triangle through loc#1103
henrydingliu wants to merge 1 commit into
mainfrom
loc_setter

Conversation

@henrydingliu

@henrydingliu henrydingliu commented Jul 10, 2026

Copy link
Copy Markdown
Member

Summary of Changes

adding support to set triangle values a few origins or devs at a time

Related GitHub Issue(s)

closes #1069

Additional Context for Reviewers

the heavy lifting is done by the existing _contig_slice function, which is already used in the getter. not sure why it was never applied in the setter

  • I passed tests locally for both code (uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)

Note

Low Risk
Small, localized change to label-based assignment on the numpy backend, with tests; no API or sparse-path changes beyond existing restrictions.

Overview
Enables partial writes on origin and development via Triangle.loc[...] = ... when assigning a Triangle slice, by running label-derived integer keys through _LocBase._contig_slice before assignment—the same normalization already used on get.

Previously, setter paths could pass non-contiguous index arrays that NumPy assignment could not handle the same way as reads; contiguous slices (e.g. development ...,:60 and 72:, or origins through '1984' and from '1985') now assign correctly on the numpy backend.

Adds test_loc_setitem_partial_triangles to assert two-step dev and origin updates reproduce a fully scaled triangle. Sparse backend behavior is unchanged (still requires .at/.iat for assignment).

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

* enable loc setting on partial triangles

* fixing

* adding test
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.49%. Comparing base (6c9ce99) to head (de661e2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1103   +/-   ##
=======================================
  Coverage   90.48%   90.49%           
=======================================
  Files          91       91           
  Lines        5289     5291    +2     
  Branches      671      671           
=======================================
+ Hits         4786     4788    +2     
  Misses        359      359           
  Partials      144      144           
Flag Coverage Δ
unittests 90.49% <100.00%> (+<0.01%) ⬆️

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

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.6% of exported symbols fully typed (185 / 1270)

Known Ambiguous Unknown Total
Project (head) 185 106 979 1270

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

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

Known Ambiguous Unknown Total
Patch 0 0 1 1
Patch symbol details
Symbol Status Change
chainladder.core.tests.test_slicing.test_loc_setitem_partial_triangles ❌ unknown new

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

raa_new = raa.copy()
raa_new.loc[:,:,:'1984',:] = raa2.loc[:,:,:'1984',:]
raa_new.loc[:,:,'1985':,:] = raa2.loc[:,:,'1985':,:]
assert raa_new == raa2

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sparse parametrization breaks new test

Medium Severity

test_loc_setitem_partial_triangles assigns through Triangle.loc without checking array_backend. The raa fixture is parametrized with sparse_only_run, where _LocBase.__setitem__ always raises when setting via .loc. The sibling test_loc_setitem_triangle_value guards sparse; this test does not, so half the parametrized runs fail.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit de661e2. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@genedan cursor's explanation makes sense. but why did all tests pass?

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.

[BUG] Location setter erroring unexpectedly

1 participant