Skip to content

Commit 447137a

Browse files
committed
get_instances: one row per instance with a multi-template thumbnail carousel
The registration MATCH returns one row per (instance, template), so a multi-template instance appeared as several rows each with a single thumbnail. Group by instance and join every alignment's thumbnail into the '; '-joined multi-image carousel the V2 Images column renders, so the frontend can bring the loaded template's thumbnail to the front. Mirrors the existing groupby collapse in TransgeneExpressionHere and the multi-thumbnail carousel the shared _owlery_query_to_results helper already emits.
1 parent 68c3edc commit 447137a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/vfbquery/vfb_queries.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,6 +2461,17 @@ def get_instances(short_form: str, return_dataframe=True, limit: int = -1):
24612461
# Convert the results to a DataFrame
24622462
df = pd.DataFrame.from_records(get_dict_cursor()(results))
24632463

2464+
# The registration MATCH yields one row per (instance, template). Collapse
2465+
# to one row per instance, joining every alignment's thumbnail into the
2466+
# "; "-joined multi-image carousel the V2 Images column renders (the
2467+
# frontend then brings the loaded template's thumbnail to the front). Other
2468+
# columns take the first (representative) value; the ORDER BY id is kept.
2469+
if not df.empty and 'id' in df.columns and 'thumbnail' in df.columns:
2470+
other_cols = [c for c in df.columns if c not in ('id', 'thumbnail')]
2471+
agg = {c: 'first' for c in other_cols}
2472+
agg['thumbnail'] = lambda s: '; '.join(t for t in s if isinstance(t, str) and t)
2473+
df = df.groupby('id', as_index=False, sort=False).agg(agg)
2474+
24642475
columns_to_encode = ['label', 'parent', 'source', 'source_id', 'template', 'dataset', 'license', 'thumbnail']
24652476
df = encode_markdown_links(df, columns_to_encode)
24662477

0 commit comments

Comments
 (0)