From b0713260336a93bc5fc29ed0e3be87f8291c82f2 Mon Sep 17 00:00:00 2001 From: colganwi Date: Wed, 21 Aug 2024 12:23:08 -0400 Subject: [PATCH] label after concat --- CHANGELOG.md | 3 ++- src/treedata/_core/merge.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b844926..a7f95db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,11 @@ and this project adheres to [Semantic Versioning][]. ### Changed - `obst` and `vart` create local copy of `nx.DiGraphs` that are added (#26) +- `TreeData.label` value remains the same after `td.concat` as long as all `label` values are the same (#27) ### Fixed -- Fixed bug which caused key to be listed twice in `tree_label` column after value update in `obst` or `vart` (#26) +- Fixed bug which caused key to be listed twice in `label` column after value update in `obst` or `vart` (#26) ## [0.0.2] - 2024-06-18 diff --git a/src/treedata/_core/merge.py b/src/treedata/_core/merge.py index 85516b6..35ae62b 100755 --- a/src/treedata/_core/merge.py +++ b/src/treedata/_core/merge.py @@ -3,6 +3,7 @@ from __future__ import annotations import typing +import warnings from collections.abc import ( Callable, Collection, @@ -100,7 +101,16 @@ def concat( fill_value=fill_value, pairwise=pairwise, ) - tdata = TreeData(adata, allow_overlap=True) + + # Create new TreeData object + label = {t.label for t in tdatas if t.label is not None} + if len(label) > 1: + warnings.warn("Multiple label values found. Setting to `tree`.", stacklevel=2) + label = "tree" + else: + label = next(iter(label), None) + allow_overlap = any(t.allow_overlap for t in tdatas) + tdata = TreeData(adata, allow_overlap=allow_overlap, label=label) # Trees for concatenation axis concat_trees = [getattr(t, f"{dim}t") for t in tdatas]