-
Notifications
You must be signed in to change notification settings - Fork 76
Add __setitem__ to tables. #1600
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
c2d1ffc
to
d33c0ec
Compare
Codecov Report
@@ Coverage Diff @@
## main #1600 +/- ##
=======================================
Coverage 93.67% 93.67%
=======================================
Files 27 27
Lines 23276 23287 +11
Branches 1079 1084 +5
=======================================
+ Hits 21804 21815 +11
Misses 1438 1438
Partials 34 34
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Missing some coverage here, will fix. |
d33c0ec
to
a4ad45a
Compare
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.
LGTM! Minor comments.
python/tskit/tables.py
Outdated
row-like object. Metadata, will be validated and encoded according to the table's | ||
:attr:`metadata_schema<tskit.IndividualTable.metadata_schema>`. | ||
|
||
:param index: the zero-index of the row to change |
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.
Maybe delete the zero here? All indexes are zero-based, might just be confusing.
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.
This was cut and pasted from __getitem__
so I've removed it there also.
index += len(self) | ||
if index < 0 or index >= len(self): | ||
raise IndexError("Index out of bounds") | ||
else: |
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.
Let's just think ahead here to make sure we're not painting ourselves into a corner. What would the semantics be for other types of updates? I guess we could support other types of assignment here.
If the index argument is a slice/boolean array, then the new_row
argument should be a Sequence of row_like values (of the same length as the index argument), and then we sequentially call update_row
on these? Wouldn't be particularly efficient, but we could push the implementation down into C if we wanted to, and it would allow us to do things like
tables.edges[:] = tables.edges[::-1]
which I'm sure would be handy.
I'm not suggesting we do this now, just making sure we leave the door open for it in the future. I think TypeError on anything that's not an Integral for the index value does this?
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.
Yep, that all makes sense. The code as-is raises TypeError
on anything non-Integral
.
python/tskit/tables.py
Outdated
if "_offset" not in column | ||
} | ||
|
||
# Encode the meatdata - note that if this becomes a perf bottleneck it is |
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.
"meatdata"
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.
Must have been hungry when writing this, fixed.
a4ad45a
to
1e769b8
Compare
Fixes #1545
Stacked on #1597