Skip to content

Commit 634e3e3

Browse files
committed
Fix: Avoid iteration errors caused by None when reading Nihon Kohden .LOG files
This is a follow-up to #13251. In #13251, some additional checks were added to `_read_event_log_block` (including a version check), which could cause `_read_event_log_block` to return `None`, leading to iteration errors. This change avoids that issue by returning an empty array instead of `None` when reading fails. In addition, when the version does not match, a warning is now issued instead of returning `None`.
1 parent db75c70 commit 634e3e3

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

doc/changes/dev/13915.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix iteration errors caused by `_read_event_log_block` returning `None` when reading Nihon Kohden log files, by `Tom Ma`_.

mne/io/nihon/nihon.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,23 @@ def _read_nihon_header(fname):
289289

290290

291291
def _read_event_log_block(fid, t_block, version):
292+
empty_logs = np.empty(0, dtype="|S45")
293+
292294
fid.seek(0x92 + t_block * 20)
293295
data = np.fromfile(fid, np.uint32, 1)
294296
if data.size == 0 or data[0] == 0:
295-
return
297+
return empty_logs
296298
t_blk_address = data[0]
297299

298300
fid.seek(t_blk_address + 0x1)
299301
data = np.fromfile(fid, "|S16", 1).astype("U16")
300302
if data.size == 0 or data[0] != version:
301-
return
303+
warn(f"Event log version mismatch: expected '{version}', got '{data}'")
302304

303305
fid.seek(t_blk_address + 0x12)
304306
data = np.fromfile(fid, np.uint8, 1)
305307
if data.size == 0:
306-
return
308+
return empty_logs
307309
n_logs = data[0]
308310

309311
fid.seek(t_blk_address + 0x14)

0 commit comments

Comments
 (0)