Skip to content

Clear Python-backend xfails at the root and the MATLAB transport - #658

Merged
suraj-ranganath merged 4 commits into
developfrom
cursor/xfail-430-root-fixes-3f99
Nov 19, 2026
Merged

suraj-ranganath merged 4 commits into
developfrom
cursor/xfail-430-root-fixes-3f99

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Keep MATLAB shaping on compared outputs so datasets, BDF headers, and location lists stay Python objects for the next call. pop_rmbase history, reref refloc records, rejtrend window length, finputcheck character cells, and structured pop_saveset fields now follow the EEGLAB functions. Six Python-backend xfails remain.

Part of #430

Open in Web Open in Cursor 

Read struct and cell inputs in the dataset, event, channel, and STUDY helpers, and present MATLAB shapes only when the EEGLAB test harness compares outputs. Document the matchchans, hungarian, and rmart differences and drop the xfails those fixes cover.

Co-authored-by: Suraj Ranganath <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 2m 18s —— View job


Code review

  • Overall assessment: Needs changes. One input-shape bug in the STUDY parent-cluster path. MATLAB reference evidence is also missing for the core-function changes.
  • Checked and look correct: the struct-array and cell handling. The new runica activation output, which reorders rows by windex and flips signs with posact the same way as winv. The hungarian tie-handling tests, whose tied and non-tied cases use the same column-to-row convention.
  • Highest-risk area: ensure_parent_cluster in studyfunc/_cluster_utils.py. Core numerics also changed in reref, runica and eeg_checkset.
  • Merge recommendation: Needs changes.

Blocking

None.

Important

  • ensure_parent_cluster crashes on component lists stored as a MATLAB row (src/eegprep/functions/studyfunc/_cluster_utils.py:50).
    • selected = list(recorded) on a (1, N) array gives a single element: the whole row. int(comp) on line 59 then raises TypeError when N > 1. A 0-d array raises TypeError already at list().
    • sync_datasetinfo keeps comps exactly as supplied (_study_utils.py:163-165), so arrays in this shape do reach this code.
    • This may also explain the remaining test_reference_pop_clust xfail.
    • Fix:
      selected = [] if is_matlab_empty(recorded) else np.asarray(recorded, dtype=float).reshape(-1).astype(int).tolist()
      This also replaces the hand-written three-way empty check. Fix this →
  • No MATLAB reference run for the core-function changes.
    • The PR changes EEGLAB-ported processing code: sigprocfunc/reref.py, sigprocfunc/runica.py, adminfunc/eeg_checkset.py, pop_select and pop_reref.
    • AGENTS.md §Testing requires one run of the eeglab-reference.yml workflow, or one local --eeglab-backend=matlab run, on the final branch before a human approves.
    • The PR description must report:
      • the command or workflow run
      • the EEGLAB and eeglab_tests commits
      • pass/fail/skip counts
      • runtime

Nits

  • reref._present duplicates an existing helper (src/eegprep/functions/sigprocfunc/reref.py:107). It is the same as not is_matlab_empty(...) from miscfunc/matlab_inputs.py. AGENTS.md lists "parallel implementations of existing helpers" as a failure pattern. pop_chancenter already uses is_matlab_empty in this PR.
  • tests/eeglab_tests/backend.py:147 runs pop_rejchan twice. The first call gets the outputs; the second, with return_com=True, only gets the history command. That doubles the rejection cost on every call that asks for four or more outputs.
    • If return_com=True can also return indices and measure, call pop_rejchan once.
    • Otherwise, note the gap on the pop_rejchan xfail row.

Test gaps

  • Missing test for the cluster fix. Pass STUDY.datasetinfo(i).comps as a (1, N) float array through pop_clust / ensure_parent_cluster. This is the shape the MATLAB transport delivers. Assert that cluster[0]["comps"] has sum(N_i) entries.

EEGLAB parity notes

  • Documented deviations meet the standard. The eeg_matchchans, hungarian, rmart and empty-struct near deviations are documented in changelog.rst. Backend-conditional tests lock each one. The PR changes only the test expectations for these functions, not their source.
  • eegh change not checked against eegh.m. The vendored EEGLAB tree (src/eegprep/eeglab/) is not in this CI checkout. A dataset list with one entry no longer gets the % multiple datasets command: prefix. The MATLAB reference run would cover this.

Notes on this run

  • I posted inline comments on _cluster_utils.py:42-50 and reref.py:107-114.
  • The committable suggestion on _cluster_utils.py also needs is_matlab_empty added to the imports from matlab_inputs. The inline comment says so.
  • I could not run any tests or gh pr comment: those commands need approval this workflow does not grant. This review is based on reading the code only.

Comment on lines +42 to +50
recorded = info.get("comps")
if (
recorded is None
or (isinstance(recorded, np.ndarray) and recorded.size == 0)
or (isinstance(recorded, (list, tuple)) and not recorded)
):
selected = []
else:
selected = list(recorded)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important — a MATLAB-shaped comps row is not flattened. list(recorded) on a (1, N) array returns one element: the whole row. int(comp) on line 59 then raises TypeError for N > 1. A 0-d array fails earlier, at list(). sync_datasetinfo keeps user or loaded comps unchanged (

info = dataset_info_from_eeg(index, eeg)
for field in ("subject", "condition", "group", "session", "run", "comps", "trialinfo"):
if not _empty_value(previous.get(field)):
info[field] = previous[field]
for key, value in previous.items():
), so comps can arrive in this shape. This may also explain the remaining test_reference_pop_clust xfail. is_matlab_empty already covers all three empty cases checked here.

After applying the suggestion, also add is_matlab_empty to the imports from eegprep.functions.miscfunc.matlab_inputs:

Suggested change
recorded = info.get("comps")
if (
recorded is None
or (isinstance(recorded, np.ndarray) and recorded.size == 0)
or (isinstance(recorded, (list, tuple)) and not recorded)
):
selected = []
else:
selected = list(recorded)
recorded = info.get("comps")
selected = [] if is_matlab_empty(recorded) else np.asarray(recorded, dtype=float).reshape(-1).astype(int).tolist()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Flattened a (1, N) comps row with is_matlab_empty and reshape(-1), and added test_ensure_parent_cluster_flattens_a_matlab_component_row. test_reference_pop_clust now passes.

Comment on lines +107 to +114
def _present(value: Any) -> bool:
if value is None:
return False
if isinstance(value, np.ndarray):
return value.size > 0
if isinstance(value, (list, tuple, str)):
return len(value) > 0
return True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit — this duplicates an existing helper. _present(x) is not is_matlab_empty(x) from miscfunc/matlab_inputs.py. That module is already imported here, and pop_chancenter uses it in this same PR. AGENTS.md lists "Parallel implementations of existing helpers" as a failure pattern. Delete _present, import is_matlab_empty, and use if not is_matlab_empty(refloc): at line 67.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Removed _present. reref uses is_matlab_empty, and a structured refloc is appended as location records. The result stays the flattened channels-by-frames matrix, matching reref.m. test_reference_reref now passes.

cursoragent and others added 3 commits November 19, 2026 05:02
A (1, N) comps row is one component list, and an empty refloc uses the shared MATLAB empty check.

Co-authored-by: Suraj Ranganath <[email protected]>
Datasets, BDF headers, and location lists stay Python objects inside
call_python. Compared outputs are shaped only at the assertion.
pop_rmbase history, reref refloc, rejtrend windows, finputcheck cells,
and structured pop_saveset fields follow the EEGLAB functions.

Co-authored-by: Suraj Ranganath <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants