-
Notifications
You must be signed in to change notification settings - Fork 107
[ENH] set partial triangle through loc #1103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
i copied it from line 66.
while trying to write an explanation, i realized that the explanation wouldn't be completely true, i.e. the slice doesn't actually need to be contiguous for axis 0 and 1 (lines 70-76). should we implement a setter that's as flexible (non-contig index and col) as the getter? |
||
| super().__setitem__(cast(tuple[_AxisKey, _AxisKey, _AxisKey, _AxisKey], contig_slice), values) | ||
|
|
||
| class Ilocation(_LocBase): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sparse parametrization breaks new testMedium Severity
Reviewed by Cursor Bugbot for commit de661e2. Configure here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @genedan cursor's explanation makes sense. but why did all tests pass?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a bug in the fixtures. Turns out
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to fix that fixture issue??
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we do, I think once raa is properly set to sparse, we might catch all kinds of stuff. It could be sizeable issue to tackle. If you do a manual run of the test code with the raa backend set to sparse and confirm that it's ok I can approve this. Then we can tackle the fixture issue separately.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it fails. i'm debating whether we should extend loc/iloc setting to sparse (i believe you had mentioned it on another issue/PR). it is definitely theoretically possible. but i kinda get why john explicitly didn't implement it. setting via a slice defeats the whole purpose of sparse, i.e. each 2D triangle only having a couple of valid values. so i'm torn between adding a sparse exception and move on or actually adding sparse support. |
||
|
|
||
| def test_invalid_iloc_sparse_assignment(prism) -> None: | ||
| """ | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I missed filling out a docstring when I annotated the file. Could you fill it out?