From f4ff6059c0fcb3e14fb8c32b13154d62f830a3d4 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Tue, 5 Mar 2024 11:22:46 -0800 Subject: [PATCH] add len check for all position elements --- src/pynwb/ecephys.py | 3 +-- tests/unit/test_ecephys.py | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pynwb/ecephys.py b/src/pynwb/ecephys.py index cd268aaa5..759661435 100644 --- a/src/pynwb/ecephys.py +++ b/src/pynwb/ecephys.py @@ -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: diff --git a/tests/unit/test_ecephys.py b/tests/unit/test_ecephys.py index cf967230e..4c6fd5c4c 100644 --- a/tests/unit/test_ecephys.py +++ b/tests/unit/test_ecephys.py @@ -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):