Skip to content

Allow tables to be subset using numpy indexing #1221

@hyanwong

Description

@hyanwong

We have tables.edges.truncate(up_to_row_n), but for #1220 it would be useful to be able to subset the edges to a selection to keep. At least in the case of edges, I think in so doing we would always create a valid tree sequence, right?

I'm guessing it would look something like this (untested) method of an edge table, but done using the [] operator (see @jeromekelleher's comment below)

def subset(self, keep):
    metadata, metadata_offset = keep_with_offset(keep, self.metadata, self.metadata_offset)
    self.set_columns(
        left = self.left[keep],
        right=self.right[keep],
        parent=self.parent[keep],
        child=self.child[keep],
        metadata=metadata
        metadata_offset=metadata_offset)

The fiddling with metadata is probably tricky enough to want to incorporate this as a tskit method, rather than expect the user to write it from scratch, IMO. Does this seem worth incorporating into tskit? I suggest it as I imagine it might be a generally useful method, and I can't see it causing any tricky edge cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Python APIIssue is about the Python APIenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions