Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chainladder/core/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ def key_to_slice(self, key: _LabelKey) -> tuple[_AxisKey, _AxisKey, _AxisKey, _A
return out

def __setitem__(self, key: _LabelKey, values: int | float | TriangleSlicer) -> None:
super().__setitem__(cast(tuple[_AxisKey, _AxisKey, _AxisKey, _AxisKey], self.key_to_slice(key)), values)
raw_slice = self.key_to_slice(key)
contig_slice = [_LocBase._contig_slice(x) for x in raw_slice]
super().__setitem__(cast(tuple[_AxisKey, _AxisKey, _AxisKey, _AxisKey], contig_slice), values)

class Ilocation(_LocBase):
"""
Expand Down
22 changes: 22 additions & 0 deletions chainladder/core/tests/test_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,29 @@ def test_loc_setitem_triangle_value(clrd: Triangle) -> None:
tri.loc["Aegis Grp", "comauto"] = sub * 2
assert tri.loc["Aegis Grp", "comauto"] == sub * 2

def test_loc_setitem_partial_triangles(raa: Triangle) -> None:
"""
Use Triangle.loc to set a few origin or develop period via a TriangleSlicer.

Parameters
----------
raa: Triangle
The raa sample data set fixture.

Returns
-------
None

"""
raa2 = raa * 2
raa_new = raa.copy()
raa_new.loc[:,:,:,:60] = raa2.loc[:,:,:,:60]
raa_new.loc[:,:,:,72:] = raa2.loc[:,:,:,72:]
assert raa_new == raa2
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?


def test_invalid_iloc_sparse_assignment(prism) -> None:
"""
Expand Down
Loading