Skip to content

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

Merged
merged 1 commit into from
Aug 3, 2021
Merged

Conversation

benjeffery
Copy link
Member

@benjeffery benjeffery commented Jul 30, 2021

Fixes #1545
Stacked on #1597

@benjeffery benjeffery force-pushed the replace-row-2 branch 3 times, most recently from c2d1ffc to d33c0ec Compare July 30, 2021 11:07
@codecov
Copy link

codecov bot commented Jul 30, 2021

Codecov Report

Merging #1600 (a4ad45a) into main (7343b80) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head a4ad45a differs from pull request most recent head 1e769b8. Consider uploading reports for the commit 1e769b8 to get more accurate results
Impacted file tree graph

@@           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           
Flag Coverage Δ
c-tests 91.85% <ø> (ø)
lwt-tests 93.40% <ø> (ø)
python-c-tests 95.41% <100.00%> (+<0.01%) ⬆️
python-tests 98.80% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
python/tskit/tables.py 98.92% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7343b80...1e769b8. Read the comment docs.

@benjeffery benjeffery marked this pull request as draft July 30, 2021 21:00
@benjeffery
Copy link
Member Author

Missing some coverage here, will fix.

@benjeffery benjeffery marked this pull request as ready for review August 2, 2021 20:19
Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

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

LGTM! Minor comments.

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
Copy link
Member

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.

Copy link
Member Author

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:
Copy link
Member

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?

Copy link
Member Author

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.

if "_offset" not in column
}

# Encode the meatdata - note that if this becomes a perf bottleneck it is
Copy link
Member

Choose a reason for hiding this comment

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

"meatdata"

Copy link
Member Author

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.

@benjeffery benjeffery added the AUTOMERGE-REQUESTED Ask Mergify to merge this PR label Aug 3, 2021
@mergify mergify bot merged commit fe295a1 into tskit-dev:main Aug 3, 2021
@mergify mergify bot removed the AUTOMERGE-REQUESTED Ask Mergify to merge this PR label Aug 3, 2021
@benjeffery benjeffery mentioned this pull request Aug 6, 2021
@benjeffery benjeffery mentioned this pull request Sep 16, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update a single row
2 participants