Skip to content

[tests] Strengthen weak eeg2mne epoched and py2mat type-consistency tests #434

Closed

Description

@suraj-ranganath

🤖 Strengthen two weak tests that #429 kept.

#429's auditors kept these two because they cover behavior nothing else tests, but their assertions can't fail in the cases that matter:

  1. tests/test_eeg_eeg2mne.py::test_eeg_eeg2mne_epoched_data wraps the conversion in except Exception as e: self.skipTest(f"eeg_eeg2mne epoched conversion not available: {e}"). Any regression in epoched EEG-to-MNE conversion shows up as a skip, not a failure. Fix: drop the blanket except, and skip only on a specific missing optional dependency, if that is the intent.
  2. tests/test_pymat.py::test_py2mat_type_consistency asserts str(result[0]['mixed_field']) == '42' or result[0]['mixed_field'] == 42. It passes even if py2mat silently turns the number 42 into the string '42', which is exactly the type-corruption bug the test is named for. Fix: assert the exact expected MATLAB-side type and value for a mixed numeric/string field across records, matching what EEGLAB writes. The CNT [7, 'boundary', 8] event-type case is a real-data example.

Before relying on the strengthened assertions, confirm they fail against a deliberately broken implementation.

Activity

  1. added
    enhancement
    on Oct 7, 2026
  2. suraj-ranganath commented on Oct 7, 2026

    @suraj-ranganath
    MemberAuthor

    🤖

    Research

    Both weak assertions are confirmed: epoched conversion currently passes, but its blanket exception handler hides conversion and assertion failures; py2mat currently converts numeric 42 into text when a later record contains a string. The string branch overwrites an already inferred numeric/object dtype, making conversion depend on record order. MATLAB struct fields preserve per-record types; EEGLAB's eeg_checkset separately normalizes mixed event types to strings, so transport preservation must not be confused with event normalization.

    Relevant code

    Proposed Fix

    eeglabcompat → py2mat → MAT-file must preserve numeric and character fields independently of record order: retain object dtype once a string mixes with another type. Strengthen the existing tests first with strict MAT-file type/value checks and uncaught epoched conversion assertions, then verify deliberately broken conversion implementations cause failures; compare the resulting structs with MATLAB and document transport semantics. No overlapping implementation PR was found; the broader MNE import/export issue #23 is outside this focused regression repair.

  3. suraj-ranganath commented on Oct 7, 2026

    @suraj-ranganath
    MemberAuthor

    🤖 Fixed in draft PR #437 at 8f239b3. The strengthened tests catch deliberate faults, and the exposed py2mat numeric-to-text corruption is fixed; MATLAB struct checks and the full epoched EEGLAB/MNE comparison passed (evidence).

    All four platform test jobs, pre-commit, Ruff/ty, and documentation CI passed. The automated Claude review failed immediately after initialization with is_error:true and zero model usage, producing no code findings; this infrastructure limitation is tracked separately in eegprep-aug. The PR remains a draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions