From a38dae6f8126b266a425b6bae4c7869519c2c4ad Mon Sep 17 00:00:00 2001 From: Caleb Robinson Date: Fri, 8 Nov 2024 04:14:26 -0800 Subject: [PATCH] Attempting to remove defaultdict from the collation functions (#2398) * Attempting to remove defaultdict from the collation functions * Any(thing) goes --- torchgeo/datasets/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/torchgeo/datasets/utils.py b/torchgeo/datasets/utils.py index e668e749840..7ddbe08e597 100644 --- a/torchgeo/datasets/utils.py +++ b/torchgeo/datasets/utils.py @@ -378,9 +378,11 @@ def _list_dict_to_dict_list( .. versionadded:: 0.2 """ - collated = collections.defaultdict(list) + collated: dict[Any, list[Any]] = dict() for sample in samples: for key, value in sample.items(): + if key not in collated: + collated[key] = [] collated[key].append(value) return collated