Skip to content

Commit

Permalink
add len check for all position elements
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Mar 5, 2024
1 parent 169b53d commit f4ff605
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/pynwb/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def __init__(self, **kwargs):
position_dtype_valid = False
if position_dtype_valid: # If we have list of element, then check that the elements are of length 3
try:
if len(args_to_set['position'][0]) != 3:
position_dtype_valid = False
position_dtype_valid = all([len(pos) == 3 for pos in args_to_set['position']])
except TypeError: # len not supported by first_position
position_dtype_valid = False
if not position_dtype_valid:
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ def test_init_position_bad(self):
location='electrode location',
device=dev1,
position=np.array([(1., 2.)], dtype=np.dtype([('x', float), ('y', float)])))
with self.assertRaises(ValueError):
ElectrodeGroup(name='elec1',
description='electrode description',
location='electrode location',
device=dev1,
position=[(1, 2, 3), (4, 5)])


class EventDetectionConstructor(TestCase):
Expand Down

0 comments on commit f4ff605

Please sign in to comment.