forked from scverse/spatialdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved
concatenate()
for non-unique element names (scverse#720)
* accept Iterable in concatenate * concatenate: automatic non-unique names resolution * docs, changelog * add test for len 1 iterable (grst code review)
- Loading branch information
1 parent
3988452
commit c09f35a
Showing
4 changed files
with
154 additions
and
20 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
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,22 +1,27 @@ | ||
from collections.abc import Iterable | ||
|
||
from spatialdata._core.spatialdata import SpatialData | ||
|
||
|
||
def _find_common_table_keys(sdatas: list[SpatialData]) -> set[str]: | ||
def _find_common_table_keys(sdatas: Iterable[SpatialData]) -> set[str]: | ||
""" | ||
Find table keys present in more than one SpatialData object. | ||
Parameters | ||
---------- | ||
sdatas | ||
A list of SpatialData objects. | ||
An `Iterable` of SpatialData objects. | ||
Returns | ||
------- | ||
A set of common keys that are present in the tables of more than one SpatialData object. | ||
""" | ||
common_keys = set(sdatas[0].tables.keys()) | ||
common_keys: set[str] = set() | ||
|
||
for sdata in sdatas[1:]: | ||
common_keys.intersection_update(sdata.tables.keys()) | ||
for sdata in sdatas: | ||
if len(common_keys) == 0: | ||
common_keys = set(sdata.tables.keys()) | ||
else: | ||
common_keys.intersection_update(sdata.tables.keys()) | ||
|
||
return common_keys |
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
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