Skip to content

Commit e3127b2

Browse files
h-mayorquinrly
andauthored
Fix mock_electrodes ignoring n_electrodes when sizing the electrodes table (#2214)
Co-authored-by: Ryan Ly <310197+rly@users.noreply.github.com>
1 parent 497132b commit e3127b2

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# PyNWB Changelog
22

3+
## PyNWB 4.0.1 (Unreleased)
4+
5+
### Fixed
6+
- Fixed `mock_electrodes` (and `mock_ElectricalSeries`) sizing the auto-created `ElectrodesTable` to a fixed 5 rows while the `DynamicTableRegion` followed `n_electrodes`, which raised an `IndexError` under HDMF 4.x+ for any data with more than 5 channels. The table is now sized to `n_electrodes`. @h-mayorquin [#2214](https://github.com/NeurodataWithoutBorders/pynwb/pull/2214)
7+
8+
39
## PyNWB 4.0.0 (June 29, 2026)
410

511
### Removed

src/pynwb/testing/mock/ecephys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def mock_electrodes(
6565
n_electrodes: int = 5, table: Optional[DynamicTable] = None, nwbfile: Optional[NWBFile] = None
6666
) -> DynamicTableRegion:
6767

68-
table = table or mock_ElectrodesTable(n_rows=5, nwbfile=nwbfile)
68+
table = table or mock_ElectrodesTable(n_rows=n_electrodes, nwbfile=nwbfile)
6969
return DynamicTableRegion(
7070
name="electrodes",
7171
data=list(range(n_electrodes)),

tests/unit/test_mock.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import numpy as np
2+
13
from pynwb import NWBHDF5IO
24

35
from pynwb.testing.mock.file import mock_Subject, mock_NWBFile
@@ -33,6 +35,7 @@
3335
from pynwb.testing.mock.ecephys import (
3436
mock_ElectrodeGroup,
3537
mock_ElectrodesTable,
38+
mock_electrodes,
3639
mock_ElectricalSeries,
3740
mock_SpikeEventSeries,
3841
mock_Units,
@@ -103,6 +106,20 @@ def test_mock_TimeSeries_w_no_time():
103106
assert ts.rate == 10.0
104107

105108

109+
def test_mock_electrodes_sizes_table_to_n_electrodes():
110+
"""The auto-created table must have exactly n_electrodes rows so the region of n_electrodes is in range."""
111+
region = mock_electrodes(n_electrodes=128)
112+
assert len(region.data) == 128
113+
assert len(region.table) == 128
114+
115+
116+
def test_mock_ElectricalSeries_more_than_five_channels():
117+
"""mock_ElectricalSeries must support data with more than the default 5 channels."""
118+
electrical_series = mock_ElectricalSeries(data=np.ones((10, 128)))
119+
assert electrical_series.data.shape[1] == 128
120+
assert len(electrical_series.electrodes.table) == 128
121+
122+
106123
@pytest.mark.parametrize("mock_function", mock_functions)
107124
def test_mock_write(mock_function, tmp_path):
108125
if mock_function is mock_NWBFile:

0 commit comments

Comments
 (0)