From 5fe84793838bdcf3ad5d0840450680be25e913ad Mon Sep 17 00:00:00 2001 From: leufen1 <l.leufen@fz-juelich.de> Date: Mon, 7 Dec 2020 17:57:08 +0100 Subject: [PATCH] fixed iterator bug when indexing causing the nan error during postprocessing --- mlair/data_handler/iterator.py | 2 +- test/test_data_handler/test_iterator.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mlair/data_handler/iterator.py b/mlair/data_handler/iterator.py index 49569405..39e20020 100644 --- a/mlair/data_handler/iterator.py +++ b/mlair/data_handler/iterator.py @@ -55,7 +55,7 @@ class DataCollection(Iterable): def add(self, element): self._collection.append(element) - self._mapping[str(element)] = len(self._collection) + self._mapping[str(element)] = len(self._collection) - 1 def _set_mapping(self): for i, e in enumerate(self._collection): diff --git a/test/test_data_handler/test_iterator.py b/test/test_data_handler/test_iterator.py index ec224c06..678f3d36 100644 --- a/test/test_data_handler/test_iterator.py +++ b/test/test_data_handler/test_iterator.py @@ -52,6 +52,13 @@ class TestDataCollection: for e, i in enumerate(data_collection): assert i == e + def test_add(self): + data_collection = DataCollection() + data_collection.add("first_element") + assert len(data_collection) == 1 + assert data_collection["first_element"] == "first_element" + assert data_collection[0] == "first_element" + class DummyData: -- GitLab