Skip to content

Commit 33a0d61

Browse files
committed
Fix KeyError on open
1 parent 0386b3b commit 33a0d61

File tree

1 file changed

+5
-3
lines changed
  • src/opencosmo/collection/structure

1 file changed

+5
-3
lines changed

src/opencosmo/collection/structure/io.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def build_structure_collection(targets: list[io.io.OpenTarget], ignore_empty: bo
167167
if link_sources["galaxy_properties"]:
168168
galaxy_properties_target = link_sources["galaxy_properties"][0]
169169

170-
input_link_targets = {}
170+
input_link_targets: dict[str, dict[str, d.Dataset | sc.StructureCollection]] = (
171+
defaultdict(dict)
172+
)
171173
for source_type, source_targets in link_targets.items():
172174
if any(len(ts) > 1 for ts in source_targets.values()):
173175
raise ValueError("Found more than one linked file of a given type!")
@@ -215,7 +217,7 @@ def __build_structure_collection(
215217
link_targets: dict[str, dict[str, d.Dataset | sc.StructureCollection]],
216218
ignore_empty: bool,
217219
):
218-
if galaxy_properties_target is not None and link_targets["galaxy_targets"]:
220+
if galaxy_properties_target is not None and "galaxy_targets" in link_targets:
219221
handlers = get_link_handlers(
220222
galaxy_properties_target.group,
221223
list(link_targets["galaxy_targets"].keys()),
@@ -242,7 +244,7 @@ def __build_structure_collection(
242244
if (
243245
halo_properties_target is not None
244246
and galaxy_properties_target is not None
245-
and not link_targets["galaxy_targets"]
247+
and "galaxy_targets" not in link_targets
246248
):
247249
galaxy_properties = io.io.open_single_dataset(
248250
galaxy_properties_target, bypass_lightcone=True

0 commit comments

Comments
 (0)