Skip to content

Commit

Permalink
Fix empty list in reports
Browse files Browse the repository at this point in the history
* this is a temporary solution until
  BlueBrain/libsonata#84 is done
  • Loading branch information
tomdele committed Apr 8, 2020
1 parent 5147443 commit f920953
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bluepysnap/frame_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from cached_property import cached_property
from pathlib2 import Path
import numpy as np
import pandas as pd
from libsonata import ElementReportReader

Expand Down Expand Up @@ -211,6 +212,10 @@ def nodes(self):

def _resolve(self, group):
"""Transform a group into a node_id array."""
if group == []:
# Only solution to return an empty list from self._frame_population.get
# see: https://github.com/BlueBrain/libsonata/issues/84
return np.array([-2])
return self.nodes.ids(group=group)


Expand Down
4 changes: 4 additions & 0 deletions bluepysnap/spike_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def nodes(self):

def _resolve_nodes(self, group):
"""Transform a node group into a node_id array."""
if group == []:
# Only solution to return an empty list from self._spike_population.get
# see: https://github.com/BlueBrain/libsonata/issues/84
return np.array([-2])
return self.nodes.ids(group=group)

def get(self, group=None, t_start=None, t_stop=None):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_frame_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def test_nodes_invalid_population(self):
def test_get(self):
pdt.assert_frame_equal(self.test_obj.get(), self.df)

pdt.assert_frame_equal(self.test_obj.get([]), pd.DataFrame())

pdt.assert_frame_equal(self.test_obj.get(2), self.df.loc[:, [2]])

pdt.assert_frame_equal(self.test_obj.get([2, 0]), self.df.loc[:, [0, 2]])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_spike_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test__resolve_nodes(self):
def test_get(self):
pdt.assert_series_equal(self.test_obj.get(),
_create_series([2, 0, 1, 2, 0], [0.1, 0.2, 0.3, 0.7, 1.3]))

pdt.assert_series_equal(self.test_obj.get([]), _create_series([], []))
npt.assert_allclose(self.test_obj.get(2), np.array([0.1, 0.7]))
npt.assert_allclose(self.test_obj.get(0, t_start=1.), [1.3])
npt.assert_allclose(self.test_obj.get(0, t_stop=1.), [0.2])
Expand Down

0 comments on commit f920953

Please sign in to comment.