diff --git a/bluepysnap/frame_report.py b/bluepysnap/frame_report.py index ea6c9ade..631e0d83 100644 --- a/bluepysnap/frame_report.py +++ b/bluepysnap/frame_report.py @@ -21,7 +21,7 @@ from pathlib2 import Path import numpy as np import pandas as pd -from libsonata import ElementReportReader +from libsonata import ElementReportReader, SonataError import bluepysnap._plotting from bluepysnap.exceptions import BluepySnapError @@ -98,11 +98,13 @@ def get(self, group=None, t_start=None, t_stop=None): Returns: pandas.DataFrame: frame as columns indexed by timestamps. """ - ids = [] if group is None else self._resolve(group).tolist() - t_start = -1 if t_start is None else t_start - t_stop = -1 if t_stop is None else t_stop + ids = self._resolve(group).tolist() + + try: + view = self._frame_population.get(node_ids=ids, tstart=t_start, tstop=t_stop) + except SonataError as e: + raise BluepySnapError(e) - view = self._frame_population.get(node_ids=ids, tstart=t_start, tstop=t_stop) if len(view.ids) == 0: return pd.DataFrame() res = pd.DataFrame(data=view.data, diff --git a/bluepysnap/spike_report.py b/bluepysnap/spike_report.py index 71a35871..b2444d58 100644 --- a/bluepysnap/spike_report.py +++ b/bluepysnap/spike_report.py @@ -22,6 +22,7 @@ from cached_property import cached_property import pandas as pd import numpy as np +from libsonata import SpikeReader, SonataError from bluepysnap.exceptions import BluepySnapError from bluepysnap.utils import fix_libsonata_empty_list @@ -29,7 +30,6 @@ def _get_reader(spike_report): - from libsonata import SpikeReader path = str(Path(spike_report.config["output_dir"]) / spike_report.config["spikes_file"]) return SpikeReader(path) @@ -101,12 +101,14 @@ def get(self, group=None, t_start=None, t_stop=None): Returns: pandas.Series: return spiking node_ids indexed by sorted spike time. """ - node_ids = [] if group is None else self._resolve_nodes(group).tolist() + node_ids = self._resolve_nodes(group).tolist() - t_start = -1 if t_start is None else t_start - t_stop = -1 if t_stop is None else t_stop series_name = "ids" - res = self._spike_population.get(node_ids=node_ids, tstart=t_start, tstop=t_stop) + try: + res = self._spike_population.get(node_ids=node_ids, tstart=t_start, tstop=t_stop) + except SonataError as e: + raise BluepySnapError(e) + if not res: return pd.Series(data=[], index=pd.Index([], name="times"), name=series_name) diff --git a/tests/test_frame_report.py b/tests/test_frame_report.py index 679ceaa5..265287e3 100644 --- a/tests/test_frame_report.py +++ b/tests/test_frame_report.py @@ -214,8 +214,6 @@ def test_get(self): pdt.assert_frame_equal( self.test_obj.get([2, 1], t_start=0.2, t_stop=0.8), self.df.iloc[2:9].loc[:, [1, 2]]) - pdt.assert_frame_equal(self.test_obj.get([0, 2], t_start=15), pd.DataFrame()) - pdt.assert_frame_equal( self.test_obj.get(group={Cell.MTYPE: "L6_Y"}, t_start=0.2, t_stop=0.8), self.df.iloc[2:9].loc[:, [1, 2]]) @@ -226,6 +224,15 @@ def test_get(self): pdt.assert_frame_equal( self.test_obj.get(group="Layer23"), self.df.loc[:, [0]]) + with pytest.raises(BluepySnapError): + self.test_obj.get(-1, t_start=0.2) + + with pytest.raises(BluepySnapError): + self.test_obj.get(0, t_start=-1) + + with pytest.raises(BluepySnapError): + self.test_obj.get([0, 2], t_start=15) + with pytest.raises(BluepySnapError): self.test_obj.get(4) diff --git a/tests/test_spike_report.py b/tests/test_spike_report.py index b4985241..e9100ed2 100644 --- a/tests/test_spike_report.py +++ b/tests/test_spike_report.py @@ -157,8 +157,6 @@ def test_get(self): pdt.assert_series_equal(self.test_obj.get([2, 1], t_start=0.2, t_stop=0.8), _create_series([1, 2], [0.3, 0.7])) - pdt.assert_series_equal(self.test_obj.get([0, 2], t_start=12), _create_series([], [])) - pdt.assert_series_equal( self.test_obj.get(group={Cell.MTYPE: "L6_Y"}, t_start=0.2, t_stop=0.8), _create_series([1, 2], [0.3, 0.7])) @@ -169,6 +167,15 @@ def test_get(self): pdt.assert_series_equal( self.test_obj.get(group="Layer23"), _create_series([0, 0], [0.2, 1.3])) + with pytest.raises(BluepySnapError): + self.test_obj.get([-1], t_start=0.2) + + with pytest.raises(BluepySnapError): + self.test_obj.get([0, 2], t_start=-1) + + with pytest.raises(BluepySnapError): + self.test_obj.get([0, 2], t_start=12) + with pytest.raises(BluepySnapError): self.test_obj.get(4)