Skip to content

Commit 7927e2c

Browse files
jeromekellehermergify[bot]
authored andcommitted
High-level interface for keep_rows
1 parent 876f192 commit 7927e2c

File tree

5 files changed

+500
-3
lines changed

5 files changed

+500
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Updates this table in-place according to the specified boolean
2+
array, and returns the resulting mapping from old to new row IDs.
3+
For each row ``j``, if ``keep[j]`` is True, that row will be
4+
retained in the output; otherwise, the row will be deleted.
5+
Rows are retained in their original ordering.
6+
7+
The returned ``id_map`` is an array of the same length as
8+
this table before the operation, such that ``id_map[j] = -1``
9+
(:data:`tskit.NULL`) if row ``j`` was deleted, and ``id_map[j]``
10+
is the new ID of that row, otherwise.
11+
12+
.. todo::
13+
This needs some examples to link to. See
14+
https://github.com/tskit-dev/tskit/issues/2708

python/CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
- Add ``__repr__`` for variants to return a string representation of the raw data
88
without spewing megabytes of text (:user:`chriscrsmith`, :pr:`2695`, :issue:`2694`)
99

10-
10+
- Add ``keep_rows`` method to table classes to support efficient in-place
11+
table subsetting (:user:`jeromekelleher`, :pr:`2700`)
12+
1113
--------------------
1214
[0.5.4] - 2023-01-13
1315
--------------------

python/_tskitmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,12 +993,14 @@ table_keep_rows(
993993
PyArrayObject *keep = NULL;
994994
PyArrayObject *id_map = NULL;
995995
npy_intp n = (npy_intp) num_rows;
996+
npy_intp array_len;
996997
int err;
997998

998999
if (!PyArg_ParseTuple(args, "O&", &bool_array_converter, &keep)) {
9991000
goto out;
10001001
}
1001-
if (PyArray_DIMS(keep)[0] != n) {
1002+
array_len = PyArray_DIMS(keep)[0];
1003+
if (array_len != n) {
10021004
PyErr_SetString(PyExc_ValueError, "keep array must be of length Table.num_rows");
10031005
goto out;
10041006
}

0 commit comments

Comments
 (0)