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 bad validation check for postion in ElectrodeGroup.__init__ #1770

Merged
merged 25 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2beae7c
Fix #1768 Bad validation check for postion in ElectrodeGroup.__init__
oruebel Aug 29, 2023
e031cd9
Update CHANGELOG
oruebel Aug 29, 2023
dc8c1c4
Updated comments
oruebel Aug 29, 2023
60844f2
Fix spelling in src/pynwb/ecephys.py
oruebel Aug 29, 2023
826c1d4
Merge branch 'dev' into fix/electrodegroup_position
CodyCBakerPhD Sep 28, 2023
a214ad6
Update src/pynwb/ecephys.py
oruebel Jan 25, 2024
5272bc3
Merge branch 'dev' into fix/electrodegroup_position
oruebel Jan 25, 2024
169b53d
Merge branch 'dev' into fix/electrodegroup_position
stephprince Mar 5, 2024
f4ff605
add len check for all position elements
stephprince Mar 5, 2024
ecd7de2
update CHANGELOG.md
stephprince Mar 5, 2024
a21f672
update docstring to fix broken reference
stephprince Mar 5, 2024
067a618
Merge branch 'dev' into fix/electrodegroup_position
rly Mar 23, 2024
c7962f7
Merge branch 'dev' into fix/electrodegroup_position
oruebel May 2, 2024
6cdd381
Merge branch 'dev' into fix/electrodegroup_position
stephprince Jul 16, 2024
4ec3b93
update CHANGELOG.md
stephprince Jul 16, 2024
aecfbc6
update validation checks for scalar compound dataset
stephprince Jul 17, 2024
dd5da88
Merge branch 'dev' into fix/electrodegroup_position
stephprince Sep 4, 2024
33110b7
update position validation
stephprince Sep 4, 2024
33d34d0
update tests for electrode group validation
stephprince Sep 4, 2024
4837aba
Merge branch 'dev' into fix/electrodegroup_position
stephprince Sep 4, 2024
3b2bf9f
Merge branch 'dev' into fix/electrodegroup_position
stephprince Sep 5, 2024
5419275
Require hdmf 3.14.5
rly Oct 10, 2024
f915e62
Merge branch 'dev' into fix/electrodegroup_position
rly Oct 10, 2024
b11ff87
Try removing deprecated call to get_html_theme_path
rly Oct 10, 2024
3fe93eb
Update CHANGELOG.md
stephprince Oct 14, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# PyNWB Changelog

## PyNWB 2.5.1 (Upcoming)

### Bug fixes
- Fixed bug in how `ElectrodGroup.__init__` validates its `position` argument. @oruebel [#1770](https://github.com/NeurodataWithoutBorders/pynwb/pull/1770)


## PyNWB 2.5.0 (August 18, 2023)

### Enhancements and minor changes
Expand Down
24 changes: 20 additions & 4 deletions src/pynwb/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,29 @@
{'name': 'location', 'type': str, 'doc': 'description of location of this electrode group'},
{'name': 'device', 'type': Device, 'doc': 'the device that was used to record from this electrode group'},
{'name': 'position', 'type': 'array_data',
'doc': 'stereotaxic position of this electrode group (x, y, z)', 'default': None})
'doc': 'Compound dataset with stereotaxic position of this electrode group (x, y, z). '
'Each element of the data array must have three elements or the dtype of the '
'array must be `(float, float, float)', 'default': None})
def __init__(self, **kwargs):
args_to_set = popargs_to_dict(('description', 'location', 'device', 'position'), kwargs)
super().__init__(**kwargs)
if args_to_set['position'] and len(args_to_set['position']) != 3:
raise ValueError('ElectrodeGroup position argument must have three elements: x, y, z, but received: %s'
% str(args_to_set['position']))
# position is a compound dataset, i.e., this must be an array with a compound data type of three floats
# or each element in the list must at least have three entries
if args_to_set['position'] is not None and len(args_to_set['position']) > 0:
position_dtype_valid = True
if hasattr(args_to_set['position'], 'dtype'): # If we have a dtype, then check that it is valid
if len(args_to_set['position'].dtype) != 3:
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
print("H1", len(args_to_set['position'].dtype))
oruebel marked this conversation as resolved.
Show resolved Hide resolved
position_dtype_valid = False
if position_dtype_valid: # If we have list of element, then check that the elements are of lenght 3

Check failure on line 43 in src/pynwb/ecephys.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

lenght ==> length
oruebel marked this conversation as resolved.
Show resolved Hide resolved
try:
if len(args_to_set['position'][0]) != 3:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Checking only the first element here seems to imply that this value should only be a single tuple of length 2 or 3 and that we would not expect more than one to be passed in the list input

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could iterate through all elements. I believe I just wanted to avoid checking all elements to keep runtime short in case there are a lot of values .

Copy link
Contributor

Choose a reason for hiding this comment

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

I updated this to iterate and check the length of all the position elements

position_dtype_valid = False
except TypeError: # len not supported by first_position
position_dtype_valid = False
if not position_dtype_valid:
raise ValueError('ElectrodeGroup position dataset must have three components (x, y, z) '
'for each array element, but received: %s' % str(args_to_set['position']))
for key, val in args_to_set.items():
setattr(self, key, val)

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/hdf5/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def setUpContainer(self):
eg = ElectrodeGroup(name='elec1',
description='a test ElectrodeGroup',
location='a nonexistent place',
device=self.dev1)
device=self.dev1,
position=[(1., 2., 3.), ])
Copy link
Collaborator

Choose a reason for hiding this comment

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

One question - why is this a list at all? Is there a case where we would have multiple tuples in this list? What would that represent?

Copy link
Contributor

Choose a reason for hiding this comment

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

I also wasn't sure what the use case of the list would be - I added a test case with multiple tuples for now but not sure if that is necessary?

return eg

def addContainer(self, nwbfile):
Expand Down
37 changes: 33 additions & 4 deletions tests/unit/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,23 @@ class ElectrodeGroupConstructor(TestCase):

def test_init(self):
dev1 = Device('dev1')
group = ElectrodeGroup('elec1', 'electrode description', 'electrode location', dev1, (1, 2, 3))
group = ElectrodeGroup(name='elec1',
description='electrode description',
location='electrode location',
device=dev1,
position=[(1, 2, 3), ])
self.assertEqual(group.name, 'elec1')
self.assertEqual(group.description, 'electrode description')
self.assertEqual(group.location, 'electrode location')
self.assertEqual(group.device, dev1)
self.assertEqual(group.position, (1, 2, 3))
self.assertEqual(group.position, [(1, 2, 3), ])

def test_init_position_none(self):
dev1 = Device('dev1')
group = ElectrodeGroup('elec1', 'electrode description', 'electrode location', dev1)
group = ElectrodeGroup(name='elec1',
description='electrode description',
location='electrode location',
device=dev1)
self.assertEqual(group.name, 'elec1')
self.assertEqual(group.description, 'electrode description')
self.assertEqual(group.location, 'electrode location')
Expand All @@ -173,7 +180,29 @@ def test_init_position_none(self):
def test_init_position_bad(self):
dev1 = Device('dev1')
with self.assertRaises(ValueError):
ElectrodeGroup('elec1', 'electrode description', 'electrode location', dev1, (1, 2))
ElectrodeGroup(name='elec1',
description='electrode description',
location='electrode location',
device=dev1,
position=(1, 2))
with self.assertRaises(ValueError):
ElectrodeGroup(name='elec1',
description='electrode description',
location='electrode location',
device=dev1,
position=(1, 2, 3))
with self.assertRaises(ValueError):
ElectrodeGroup(name='elec1',
description='electrode description',
location='electrode location',
device=dev1,
position=[(1, 2), ])
with self.assertRaises(ValueError):
ElectrodeGroup(name='elec1',
description='electrode description',
location='electrode location',
device=dev1,
position=np.array([(1., 2.)], dtype=np.dtype([('x', float), ('y', float)])))
oruebel marked this conversation as resolved.
Show resolved Hide resolved


class EventDetectionConstructor(TestCase):
Expand Down