Skip to content

Commit 09b7dc3

Browse files
committed
zach review
1 parent 3e661eb commit 09b7dc3

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

neo/io/neuralynxio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(
7575
detailed gap report. If a float value is provided, gaps smaller than this
7676
threshold (in milliseconds) are ignored, and gaps larger create new segments.
7777
strict_gap_mode : bool | None, default: None
78-
Deprecated. Use gap_tolerance_ms instead.
78+
Deprecated and will be removed in version 0.16.0. Use gap_tolerance_ms instead.
7979
"""
8080

8181
if filename is not None:

neo/rawio/neuralynxrawio/ncssections.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def build_for_ncs_file(ncsMemMap, nlxHdr, gap_tolerance_us=None, **kwargs):
285285

286286
if gapTolerance is not None:
287287
warnings.warn(
288-
"The `gapTolerance` parameter is deprecated and will be removed in version 0.16. "
288+
"The `gapTolerance` parameter is deprecated and will be removed in version 0.16.0. "
289289
"Use `gap_tolerance_us` instead.",
290290
DeprecationWarning,
291291
stacklevel=2,
@@ -295,20 +295,23 @@ def build_for_ncs_file(ncsMemMap, nlxHdr, gap_tolerance_us=None, **kwargs):
295295

296296
if strict_gap_mode is not None:
297297
warnings.warn(
298-
"The `strict_gap_mode` parameter is deprecated and will be removed in version 0.16. "
298+
"The `strict_gap_mode` parameter is deprecated and will be removed in version 0.16.0. "
299299
"Use `gap_tolerance_us` instead.",
300300
DeprecationWarning,
301301
stacklevel=2,
302302
)
303303

304+
if gap_tolerance_us is not None and gap_tolerance_us < 0:
305+
raise ValueError(f"`gap_tolerance_us` must be non-negative, got {gap_tolerance_us}")
306+
304307
acqType = nlxHdr.type_of_recording()
305308
freq = nlxHdr["sampling_rate"]
306309

307310
# Deprecation shim for strict_gap_mode (the boolean predecessor of gap_tolerance_us).
308311
# strict_gap_mode True/None already match the modern per-type defaults below; only
309312
# strict_gap_mode=False differed, tolerating a quarter-packet gap (PRE4 was 0 either way).
310313
# Translating that single case here keeps the per-type branches on gap_tolerance_us only.
311-
# Remove this block when strict_gap_mode is dropped in v0.16.
314+
# Remove this block when strict_gap_mode is dropped in v0.16.0.
312315
if gap_tolerance_us is None and strict_gap_mode is not None and not strict_gap_mode and acqType != AcqType.PRE4:
313316
gap_tolerance_us = round(0.25 * NcsSection._RECORD_SIZE * 1e6 / freq)
314317

neo/rawio/neuralynxrawio/neuralynxrawio.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class NeuralynxRawIO(BaseRawIO):
100100
Use gap_tolerance_ms=0.0 to segment on all detected gaps.
101101
strict_gap_mode : bool | None, default: None
102102
.. deprecated::
103-
Use ``gap_tolerance_ms`` instead. Will be removed in version 0.16.
103+
Use ``gap_tolerance_ms`` instead. Will be removed in version 0.16.0.
104104
If explicitly set, uses legacy gap detection behavior:
105105
strict_gap_mode=True uses tight tolerance (0.2 sample intervals),
106106
strict_gap_mode=False uses loose tolerance (quarter of 512-sample packet).
@@ -204,13 +204,18 @@ def __init__(
204204
else:
205205
self.rawmode = "one-dir"
206206

207+
if gap_tolerance_ms is not None and gap_tolerance_ms < 0:
208+
raise ValueError(f"`gap_tolerance_ms` must be non-negative, got {gap_tolerance_ms}")
209+
207210
# Handle gap_tolerance_ms and deprecated strict_gap_mode
208211
if strict_gap_mode is not None:
209212
warnings.warn(
210-
"`strict_gap_mode` is deprecated and will be removed in version 0.16. "
211-
"Use `gap_tolerance_ms` instead to control gap handling. "
213+
"`strict_gap_mode` is deprecated and will be removed in version 0.16.0. "
214+
"Use `gap_tolerance_ms` instead to control gap handling. The equivalent value "
215+
"depends on the sampling rate: 0.2 / rate * 1000 ms reproduces strict_gap_mode=True "
216+
"and 128 / rate * 1000 ms reproduces strict_gap_mode=False (at 32 kHz, 0.00625 and 4.0). "
212217
"See issue #1773 for details.",
213-
DeprecationWarning,
218+
FutureWarning,
214219
stacklevel=2,
215220
)
216221
if gap_tolerance_ms is not None:

neo/test/rawiotest/test_neuralynxrawio.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,29 @@ def test_gap_tolerance_ms_large_tolerance(self):
287287
rawio.parse_header()
288288
self.assertEqual(rawio._nb_segment, 1)
289289

290+
def test_negative_gap_tolerance_ms_raises(self):
291+
"""A negative tolerance would treat every record as a gap, so it is rejected up front."""
292+
with self.assertRaises(ValueError):
293+
NeuralynxRawIO(
294+
self.get_local_path("neuralynx/Cheetah_v5.5.1/original_data"),
295+
gap_tolerance_ms=-10.0,
296+
)
297+
290298
def test_no_gaps_no_error(self):
291299
"""Test that datasets without gaps load fine without gap_tolerance_ms."""
292300
rawio = NeuralynxRawIO(self.get_local_path("neuralynx/Cheetah_v4.0.2/original_data"))
293301
rawio.parse_header()
294302
self.assertEqual(rawio._nb_segment, 1)
295303

296304
def test_strict_gap_mode_deprecation(self):
297-
"""Test that strict_gap_mode emits DeprecationWarning."""
298-
with self.assertWarns(DeprecationWarning):
305+
"""Test that strict_gap_mode emits FutureWarning."""
306+
with self.assertWarns(FutureWarning):
299307
rawio = NeuralynxRawIO(
300308
self.get_local_path("neuralynx/BML/original_data"),
301309
strict_gap_mode=True,
302310
)
303311

304-
with self.assertWarns(DeprecationWarning):
312+
with self.assertWarns(FutureWarning):
305313
rawio = NeuralynxRawIO(
306314
self.get_local_path("neuralynx/BML/original_data"),
307315
strict_gap_mode=False,
@@ -310,7 +318,7 @@ def test_strict_gap_mode_deprecation(self):
310318
def test_strict_gap_mode_legacy_behavior(self):
311319
"""Test that strict_gap_mode still works for backward compatibility."""
312320
# strict_gap_mode=True should segment like gap_tolerance_ms=0.0
313-
with self.assertWarns(DeprecationWarning):
321+
with self.assertWarns(FutureWarning):
314322
rawio = NeuralynxRawIO(
315323
self.get_local_path("neuralynx/Cheetah_v5.5.1/original_data"),
316324
strict_gap_mode=True,
@@ -320,7 +328,7 @@ def test_strict_gap_mode_legacy_behavior(self):
320328

321329
def test_strict_gap_mode_false_legacy_behavior(self):
322330
"""The deprecated strict_gap_mode=False (lenient) path still loads, warns, and segments."""
323-
with self.assertWarns(DeprecationWarning):
331+
with self.assertWarns(FutureWarning):
324332
rawio = NeuralynxRawIO(
325333
self.get_local_path("neuralynx/Cheetah_v5.5.1/original_data"),
326334
strict_gap_mode=False,

0 commit comments

Comments
 (0)