From 784907cc0e7e03725689978166079ef344417975 Mon Sep 17 00:00:00 2001 From: ptlnextdoor <67443596+ptlnextdoor@users.noreply.github.com> Date: Tue, 17 Nov 2026 04:54:12 +0000 Subject: [PATCH 1/2] Fix TdtIO IndexError when given a single block directory A directory that holds the files of one TDT block (Tbk, Tdx, tev, tsq) was read as a tank of blocks. No sub-block folders were found, so no segment was created and _parse_header raised IndexError. Treat such a directory as a single block. --- neo/rawio/tdtrawio.py | 7 ++++++- neo/test/rawiotest/test_tdtrawio.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/neo/rawio/tdtrawio.py b/neo/rawio/tdtrawio.py index 280b95106..c7cb0c8e1 100644 --- a/neo/rawio/tdtrawio.py +++ b/neo/rawio/tdtrawio.py @@ -75,7 +75,12 @@ def __init__(self, dirname="", sortname=""): """ BaseRawIO.__init__(self) dirname = Path(dirname) - if dirname.is_dir(): + tsq_files = [f for f in dirname.iterdir() if f.suffix.lower() == ".tsq"] if dirname.is_dir() else [] + if dirname.is_dir() and is_tdtblock(dirname) and len(tsq_files) == 1: + # the directory is itself a single block, not a tank of blocks + self.dirname = tsq_files[0].with_suffix("") + self.tdt_block_mode = "single" + elif dirname.is_dir(): self.dirname = Path(dirname) self.tdt_block_mode = "multi" elif dirname.is_file(): diff --git a/neo/test/rawiotest/test_tdtrawio.py b/neo/test/rawiotest/test_tdtrawio.py index 1c3afe3c6..56db73dc9 100644 --- a/neo/test/rawiotest/test_tdtrawio.py +++ b/neo/test/rawiotest/test_tdtrawio.py @@ -1,3 +1,4 @@ +import tempfile import unittest from pathlib import Path from numpy.testing import assert_array_equal, assert_ @@ -64,3 +65,18 @@ def test_compare_load_multi_single_block(self): if __name__ == "__main__": unittest.main() + + +class TestTdtRawIOBlockDirectory(unittest.TestCase): + def test_block_directory_is_single_block(self): + # a directory holding the files of one block (no sub-block folders), see issue 1970 + with tempfile.TemporaryDirectory() as tmp: + block = Path(tmp) / "recording_name" + block.mkdir() + for ext in ("Tbk", "Tdx", "tev", "tsq"): + (block / f"recording_name.{ext}").touch() + + rawio = TdtRawIO(block) + + self.assertEqual(rawio.tdt_block_mode, "single") + self.assertEqual(rawio.dirname, block / "recording_name") From c7c9f16d9795488d78ea858a5a0ed449344ce4bf Mon Sep 17 00:00:00 2001 From: ptlnextdoor <67443596+ptlnextdoor@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:36:08 +0000 Subject: [PATCH 2/2] Move TdtRawIO block directory test above the main guard --- neo/test/rawiotest/test_tdtrawio.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neo/test/rawiotest/test_tdtrawio.py b/neo/test/rawiotest/test_tdtrawio.py index 56db73dc9..4c8f92508 100644 --- a/neo/test/rawiotest/test_tdtrawio.py +++ b/neo/test/rawiotest/test_tdtrawio.py @@ -63,10 +63,6 @@ def test_compare_load_multi_single_block(self): ) -if __name__ == "__main__": - unittest.main() - - class TestTdtRawIOBlockDirectory(unittest.TestCase): def test_block_directory_is_single_block(self): # a directory holding the files of one block (no sub-block folders), see issue 1970 @@ -80,3 +76,7 @@ def test_block_directory_is_single_block(self): self.assertEqual(rawio.tdt_block_mode, "single") self.assertEqual(rawio.dirname, block / "recording_name") + + +if __name__ == "__main__": + unittest.main()