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

make yapf

parent 96d49876
No related branches found
No related tags found
1 merge request!27Refactor offline I/O
......@@ -151,7 +151,9 @@ class Usr:
def __getitem_flat__(self, item):
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:
return self._usr_data[:, self._usr_idx_lookup[item]]
......@@ -197,8 +199,8 @@ class OfflineReader:
def events(self):
"""The `E` branch, containing all offline events."""
return OfflineBranch(self._tree,
mapper=EVENTS_MAP,
subbranchmaps=SUBBRANCH_MAPS)
mapper=EVENTS_MAP,
subbranchmaps=SUBBRANCH_MAPS)
@cached_property
def header(self):
......
......@@ -26,9 +26,10 @@ def _unfold_indices(obj, indices):
try:
obj = obj[idx]
except IndexError:
print("IndexError while accessing an item from '{}' at depth {} ({}) "
"using the index chain {}"
.format(repr(original_obj), depth, idx, indices))
print(
"IndexError while accessing an item from '{}' at depth {} ({}) "
"using the index chain {}".format(repr(original_obj), depth,
idx, indices))
raise
return obj
......@@ -62,7 +63,7 @@ class Branch:
if subbranchmaps is not None:
for mapper in subbranchmaps:
subbranch = self.__class__(self._tree,
mapper=mapper,
mapper=mapper,
index_chain=self._index_chain)
self._subbranches.append(subbranch)
for subbranch in self._subbranches:
......@@ -129,8 +130,10 @@ class Branch:
elif isinstance(self._index_chain[-1], int):
return 1
else:
return len(_unfold_indices(self._branch[self._keymap['id']].lazyarray(
basketcache=BASKET_CACHE), self._index_chain))
return len(
_unfold_indices(
self._branch[self._keymap['id']].lazyarray(
basketcache=BASKET_CACHE), self._index_chain))
def __str__(self):
return "Number of elements: {}".format(len(self._branch))
......
......@@ -154,7 +154,8 @@ class TestOfflineEvents(unittest.TestCase):
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][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):
assert str(self.n_events) in str(self.events)
......@@ -344,7 +345,6 @@ class TestUsr(unittest.TestCase):
self.f.events.usr.DeltaPosZ)
class TestNestedMapper(unittest.TestCase):
def test_nested_mapper(self):
self.assertEqual('pos_x', _nested_mapper("trks.pos.x"))
......@@ -30,7 +30,8 @@ class TestUnfoldIndices(unittest.TestCase):
assert data[indices[0]][indices[1]] == _unfold_indices(data, indices)
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):
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