Skip to content

Commit

Permalink
Added kwarg: 'raise_missing_property' to 'NodePopulation.get' (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: Gianluca Ficarelli <26835404+GianlucaFicarelli@users.noreply.github.com>
  • Loading branch information
joni-herttuainen and GianlucaFicarelli committed Jul 11, 2023
1 parent b3a2c7a commit 28a8860
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ New Features
Improvements
~~~~~~~~~~~~
- Node set resolution is done by libsonata
- Added kwarg: `raise_missing_property` to `NodePopulation.get`

Breaking Changes
~~~~~~~~~~~~~~~~
Expand Down
8 changes: 5 additions & 3 deletions bluepysnap/nodes/node_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,16 @@ def ids(self, group=None, limit=None, sample=None, raise_missing_property=True):
else:
return np.unique(result)

def get(self, group=None, properties=None):
def get(self, group=None, properties=None, raise_missing_property=True):
"""Node properties as a pandas Series or DataFrame.
Args:
group (int/CircuitNodeId/CircuitNodeIds/sequence/str/mapping/None):
see :ref:`Group Concept`
properties (list|str|None): If specified, return only the properties in the list.
Otherwise, return all the properties.
raise_missing_property (bool): when a property used for filtering ids is not present in
the population, raise an error if True, or return empty Series/DataFrame if False.
Returns:
value/pandas.Series/pandas.DataFrame:
Expand Down Expand Up @@ -525,9 +527,9 @@ def get(self, group=None, properties=None):
if isinstance(group, (int, np.integer)):
self._check_id(group)
elif isinstance(group, CircuitNodeId):
group = self.ids(group)[0]
group = self.ids(group, raise_missing_property=raise_missing_property)[0]
else:
group = self.ids(group)
group = self.ids(group, raise_missing_property=raise_missing_property)

result = self._get_data(properties=properties)
result = result.loc[group] if group is not None else result
Expand Down
7 changes: 7 additions & 0 deletions tests/test_node_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ def test_get(self):
assert _call().shape == (3, 12)
assert _call(0, Cell.MTYPE) == "L2_X"
assert _call(CircuitNodeId("default", 0), Cell.MTYPE) == "L2_X"

# Unknown property filters
assert _call({"no-such-property": "no-value"}, raise_missing_property=False).empty
with pytest.raises(BluepySnapError) as e:
_call({"no-such-property": "no-value"})
assert "Unknown node properties" in e.value.args[0]

assert _call(np.int32(0), Cell.MTYPE) == "L2_X"
pdt.assert_frame_equal(
_call([1, 2], properties=[Cell.X, Cell.MTYPE, Cell.HOLDING_CURRENT]),
Expand Down

0 comments on commit 28a8860

Please sign in to comment.