Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty list in reports #51

Merged
merged 2 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could define

def empty_list():
    '''Only solution to return an empty list from self._frame_population.get
       see: https://github.com/BlueBrain/libsonata/issues/84
    '''
   return np.array([-2])

And use it everywhere, so that you won't have to look for np.array([-2]) the day you need to fix it, and you don't need to rewrite the comment everytime you need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes why not.

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