diff --git a/km3io/rootio.py b/km3io/rootio.py index 56a7fec97ee0597c5ee0e6dcb491167f3745e091..186fe5e43bf1e6a34c67fa92ce230376ef74a8be 100644 --- a/km3io/rootio.py +++ b/km3io/rootio.py @@ -354,6 +354,13 @@ class Branch: return unfold_indices(self._branch[key].array(), self._index_chain) + def __iter__(self): + raise NotImplementedError( + "iterating over a nested branch is not supported nor recommended. " + "If you really feel you need to do it, open an issue in " + "https://git.km3net.de/km3py/km3io" + ) + def __getitem__(self, key): return self.__class__( self._branch, self.fields, self._aliases, self._index_chain + [key] diff --git a/tests/test_offline.py b/tests/test_offline.py index 84d0cb6338d70b75e5d6e5126c35ea3ad4ab052c..9c114023da69e9c134ccf7339a168c6b7b6bfce8 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -235,6 +235,10 @@ class TestOfflineEvents(unittest.TestCase): with self.assertRaises(NotImplementedError): [e.id for e in self.events[2:8][2:4]] + def test_iteration_over_subbranches_raises(self): + with self.assertRaises(NotImplementedError): + [t for t in self.events[0].tracks] + def test_str(self): assert str(self.n_events) in str(self.events)