Skip to content

Commit 35b4ecc

Browse files
authored
Merge pull request #66 from YosefLab/copy-speedup
better performance with many trees
2 parents 06a03aa + 414bf6a commit 35b4ecc

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ and this project adheres to [Semantic Versioning][].
1616

1717
### Fixed
1818

19+
## [0.2.3] - 2025-10-14
20+
21+
### Added
22+
23+
### Changed
24+
25+
- Optimized tree overlap detection to speed up copying and subsetting with many trees (#66)
26+
- Switch to hatch with v0.0.6 template update (#61)
27+
28+
### Fixed
29+
30+
- Fixed codecov configuration (#64)
31+
1932
## [0.2.2] - 2025-09-18
2033

2134
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = [ "hatchling" ]
44

55
[project]
66
name = "treedata"
7-
version = "0.2.2"
7+
version = "0.2.3"
88
description = "anndata with trees"
99
readme = "README.md"
1010
license = { file = "LICENSE" }

src/treedata/_core/aligned_mapping.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,9 @@ def _validate_tree(self, tree: nx.DiGraph, key: str) -> set[str]:
8181

8282
def _check_tree_overlap(self, nodes=()) -> bool:
8383
"""Check if the leaves overlap with other trees."""
84-
nodes = set(nodes)
85-
for _, tree_nodes in self._tree_to_node.items():
86-
if nodes.intersection(tree_nodes):
87-
return True
88-
else:
89-
nodes = nodes.union(tree_nodes)
90-
return False
84+
if not nodes:
85+
return any(len(tree_keys) > 1 for tree_keys in self._node_to_tree.values())
86+
return any(node in self._node_to_tree for node in nodes)
9187

9288
def _update_tree_labels(self):
9389
"""Update the tree labels in the parent object."""
@@ -176,6 +172,12 @@ def __setitem__(self, key: str, value: nx.DiGraph):
176172
self._check_uniqueness()
177173
nodes = self._validate_tree(value, key)
178174

175+
if key in self._tree_to_node:
176+
for node in self._tree_to_node[key]:
177+
self._node_to_tree[node].discard(key)
178+
if not self._node_to_tree[node]:
179+
del self._node_to_tree[node]
180+
179181
for node in nodes:
180182
self._node_to_tree[node].add(key)
181183
self._tree_to_node[key] = nodes

0 commit comments

Comments
 (0)