Skip to content

fix: raise ValueError for non-1D data array in Channel.__init__#288

Merged
sorlob merged 3 commits into
mainfrom
fix/287-2d-data-length-check
May 7, 2026
Merged

fix: raise ValueError for non-1D data array in Channel.__init__#288
sorlob merged 3 commits into
mainfrom
fix/287-2d-data-length-check

Conversation

@sorlob
Copy link
Copy Markdown
Collaborator

@sorlob sorlob commented May 7, 2026

Closes #287.

Adds ndim != 1 guards to prevent 2D+ arrays from silently passing len()-based length checks:

  • Channel.__init__data (extended with test for 2D time_index)
  • TimeSeriesBase.__init__time_index (new)
  • Label.__init__data and text_data (new)

IntervalLabel is unaffected: it reshapes an (m, 2) time_index to 1D before the parent __init__ is called, so the new guard never trips for valid interval input.

Test plan

  • test_channel_creation_2d_data_raises — 2D data and 2D time_index on Channel raise ValueError
  • test_label_creation_2d_raises — 2D data, text_data, and time_index on Label raise ValueError
  • Full test suite (71 tests) — no regressions

@sorlob sorlob requested a review from behackl May 7, 2026 16:07
@sorlob sorlob added bug Something isn't working c:data structure Anything concerning our internal data structures labels May 7, 2026
sorlob and others added 3 commits May 7, 2026 18:11
Before this fix, passing a 2D array as data (e.g. shape (n, n)) would
silently pass the len() length check when the first dimension matched
len(time_index).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…#287

Extends the ndim guard to TimeSeriesBase.__init__ (time_index) and
Label.__init__ (data, text_data), so that any 2D+ array raises a clear
ValueError instead of silently corrupting the stored index or data.
IntervalLabel is unaffected — it reshapes (m, 2) time_index to 1D
before reaching the parent __init__.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sorlob sorlob force-pushed the fix/287-2d-data-length-check branch from 83e36b0 to cd5ef5e Compare May 7, 2026 16:11
@sorlob sorlob merged commit 2d45df5 into main May 7, 2026
9 of 10 checks passed
@sorlob sorlob deleted the fix/287-2d-data-length-check branch May 7, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working c:data structure Anything concerning our internal data structures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2D data array silently passes length check in Channel.__init__

2 participants