Skip to content
Snippets Groups Projects
Commit 225970fb authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

make yapf

parent c44fabcb
No related branches found
No related tags found
1 merge request!24Refactor offline
Pipeline #10188 passed
...@@ -151,7 +151,9 @@ class Usr: ...@@ -151,7 +151,9 @@ class Usr:
def __getitem_flat__(self, item): def __getitem_flat__(self, item):
if self._index_chain: if self._index_chain:
return _unfold_indices(self._usr_data, self._index_chain)[:, self._usr_idx_lookup[item]] return _unfold_indices(
self._usr_data, self._index_chain)[:,
self._usr_idx_lookup[item]]
else: else:
return self._usr_data[:, self._usr_idx_lookup[item]] return self._usr_data[:, self._usr_idx_lookup[item]]
...@@ -197,8 +199,8 @@ class OfflineReader: ...@@ -197,8 +199,8 @@ class OfflineReader:
def events(self): def events(self):
"""The `E` branch, containing all offline events.""" """The `E` branch, containing all offline events."""
return OfflineBranch(self._tree, return OfflineBranch(self._tree,
mapper=EVENTS_MAP, mapper=EVENTS_MAP,
subbranchmaps=SUBBRANCH_MAPS) subbranchmaps=SUBBRANCH_MAPS)
@cached_property @cached_property
def header(self): def header(self):
......
...@@ -26,9 +26,10 @@ def _unfold_indices(obj, indices): ...@@ -26,9 +26,10 @@ def _unfold_indices(obj, indices):
try: try:
obj = obj[idx] obj = obj[idx]
except IndexError: except IndexError:
print("IndexError while accessing an item from '{}' at depth {} ({}) " print(
"using the index chain {}" "IndexError while accessing an item from '{}' at depth {} ({}) "
.format(repr(original_obj), depth, idx, indices)) "using the index chain {}".format(repr(original_obj), depth,
idx, indices))
raise raise
return obj return obj
...@@ -62,7 +63,7 @@ class Branch: ...@@ -62,7 +63,7 @@ class Branch:
if subbranchmaps is not None: if subbranchmaps is not None:
for mapper in subbranchmaps: for mapper in subbranchmaps:
subbranch = self.__class__(self._tree, subbranch = self.__class__(self._tree,
mapper=mapper, mapper=mapper,
index_chain=self._index_chain) index_chain=self._index_chain)
self._subbranches.append(subbranch) self._subbranches.append(subbranch)
for subbranch in self._subbranches: for subbranch in self._subbranches:
...@@ -129,8 +130,10 @@ class Branch: ...@@ -129,8 +130,10 @@ class Branch:
elif isinstance(self._index_chain[-1], int): elif isinstance(self._index_chain[-1], int):
return 1 return 1
else: else:
return len(_unfold_indices(self._branch[self._keymap['id']].lazyarray( return len(
basketcache=BASKET_CACHE), self._index_chain)) _unfold_indices(
self._branch[self._keymap['id']].lazyarray(
basketcache=BASKET_CACHE), self._index_chain))
def __str__(self): def __str__(self):
return "Number of elements: {}".format(len(self._branch)) return "Number of elements: {}".format(len(self._branch))
...@@ -142,8 +145,6 @@ class Branch: ...@@ -142,8 +145,6 @@ class Branch:
's' if length > 1 else '') 's' if length > 1 else '')
def _to_num(value): def _to_num(value):
"""Convert a value to a numerical one if possible""" """Convert a value to a numerical one if possible"""
for converter in (int, float): for converter in (int, float):
......
...@@ -154,7 +154,8 @@ class TestOfflineEvents(unittest.TestCase): ...@@ -154,7 +154,8 @@ class TestOfflineEvents(unittest.TestCase):
def test_index_chaining(self): def test_index_chaining(self):
assert np.allclose(self.events[3:5].n_hits, self.events.n_hits[3:5]) assert np.allclose(self.events[3:5].n_hits, self.events.n_hits[3:5])
assert np.allclose(self.events[3:5][0].n_hits, self.events.n_hits[3:5][0]) assert np.allclose(self.events[3:5][0].n_hits,
self.events.n_hits[3:5][0])
def test_str(self): def test_str(self):
assert str(self.n_events) in str(self.events) assert str(self.n_events) in str(self.events)
...@@ -344,7 +345,6 @@ class TestUsr(unittest.TestCase): ...@@ -344,7 +345,6 @@ class TestUsr(unittest.TestCase):
self.f.events.usr.DeltaPosZ) self.f.events.usr.DeltaPosZ)
class TestNestedMapper(unittest.TestCase): class TestNestedMapper(unittest.TestCase):
def test_nested_mapper(self): def test_nested_mapper(self):
self.assertEqual('pos_x', _nested_mapper("trks.pos.x")) self.assertEqual('pos_x', _nested_mapper("trks.pos.x"))
...@@ -30,7 +30,8 @@ class TestUnfoldIndices(unittest.TestCase): ...@@ -30,7 +30,8 @@ class TestUnfoldIndices(unittest.TestCase):
assert data[indices[0]][indices[1]] == _unfold_indices(data, indices) assert data[indices[0]][indices[1]] == _unfold_indices(data, indices)
indices = [slice(1, 9, 2), slice(1, 4), 2] indices = [slice(1, 9, 2), slice(1, 4), 2]
assert data[indices[0]][indices[1]][indices[2]] == _unfold_indices(data, indices) assert data[indices[0]][indices[1]][indices[2]] == _unfold_indices(
data, indices)
def test_unfold_indices_raises_index_error(self): def test_unfold_indices_raises_index_error(self):
data = range(10) data = range(10)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment