-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement basic get_row_reorder_df
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Tuple | ||
|
||
if TYPE_CHECKING: | ||
from ._gt_data import RowGroups, Stub | ||
|
||
|
||
TupleStartFinal = Tuple[int, int] | ||
|
||
|
||
def get_row_reorder_df(groups: RowGroups, stub_df: Stub) -> list[TupleStartFinal]: | ||
if not len(groups): | ||
indices = range(len(stub_df)) | ||
|
||
# TODO: is this used in indexing? If so, we may need to use | ||
# ii + 1 for the final part? | ||
return [(ii, ii) for ii in indices] | ||
|
||
# where in the group each element is | ||
groups_pos = [groups.index(row.group_id) for row in stub_df] | ||
# the index that when used on the rows will sort them by the order in groups | ||
start_pos = list(range(len(groups_pos))) | ||
sort_indx = sorted(start_pos, key=lambda ii: groups_pos[ii]) | ||
|
||
return list(zip(start_pos, sort_indx)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from gt._gt_data import RowGroups, Stub, RowInfo | ||
from gt.utils_render_common import get_row_reorder_df | ||
|
||
|
||
def test_get_row_reorder_df_simple(): | ||
groups = RowGroups(["b", "a"]) | ||
stub = Stub([RowInfo(0, "a"), RowInfo(1, "b"), RowInfo(2, "a")]) | ||
|
||
start_end = get_row_reorder_df(groups, stub) | ||
|
||
assert start_end == [(0, 1), (1, 0), (2, 2)] | ||
|
||
|
||
def test_get_row_reorder_df_no_groups(): | ||
groups = RowGroups() | ||
stub = Stub([RowInfo(0, "a"), RowInfo(1, "b")]) | ||
|
||
start_end = get_row_reorder_df(groups, stub) | ||
assert start_end == [(0,0), (1,1)] |