[ENH] set partial triangle through loc - #1103
Conversation
* enable loc setting on partial triangles * fixing * adding test
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1103 +/- ##
==========================================
+ Coverage 90.48% 91.79% +1.30%
==========================================
Files 91 91
Lines 5289 6252 +963
Branches 671 889 +218
==========================================
+ Hits 4786 5739 +953
- Misses 359 363 +4
- Partials 144 150 +6
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:
|
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): 0.0% fully typed (0 / 5)
Patch symbol details
|
| 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) |
There was a problem hiding this comment.
Looks like I missed filling out a docstring when I annotated the file. Could you fill it out?
|
How are we doing here with this PR? Can I help? |
|
@kennethshsu that comment I made about the dense version of |
|
@kennethshsu pausing till the sparse test fixture is fixed @genedan i'd like your feedback on
|
|
generalizing across iloc
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 64329cc. Configure here.
| cast(np.ndarray, cast(object, self.obj.values)).__setitem__(norm_key, values) | ||
| else: | ||
| #the getter uses arr[idx,:][:,idx] to get the Cartesian product, using np.ix_ on the setter to match | ||
| cast(np.ndarray, cast(object, self.obj.values)).__setitem__(np.ix_(norm_key[0], norm_key[1])+(norm_key[2], norm_key[3]), values) |
There was a problem hiding this comment.
Stepped slice step dropped
Medium Severity
The new setter runs _contig_slice and then _normalize_index, unlike get_idx, which uses the contig result directly. When an arithmetic index sequence spans a full axis, _contig_slice builds a stepped slice, and _normalize_index then clears both bounds and drops the step, so assignment can write the entire axis instead of the selected positions.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 64329cc. Configure here.


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
uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)Note
Medium Risk
Touches core 4-D indexing assignment in
slice.py, which can silently mis-assign data ifnp.ix_or contiguous-key logic is wrong; scope is numpy-only with explicit guards and new tests.Overview
Extends
Triangle.locandTriangle.ilocassignment on the numpy backend so you can write partial slices of origin/development periods and non-contiguous index/column selections, matching behavior that getters already supported.The setter now runs keys through
_contig_slice(same asget_idx) before writing values. For fancy index lists on the index/column axes, writes usenp.ix_so assignments align with the getter’s Cartesian-product selection. Fancy indexing on origin or development when setting still raisesValueError; sparse backends remain limited to.at/.iat.New tests cover partial origin/dev updates, non-contiguous
loc/ilocwrites, and the new error paths.Reviewed by Cursor Bugbot for commit 64329cc. Bugbot is set up for automated code reviews on this repo. Configure here.