Repository navigation
Shape MATLAB outputs at the transport boundary - #657
Conversation
Numeric, cell, and character results that the Python backend compares against EEGLAB now use row, column, 1-by-1, and container shapes. Co-authored-by: Suraj Ranganath <[email protected]>
There was a problem hiding this comment.
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.
|
🤖 Specification Problem: after the MATLAB input adapters, 69 Python-backend xfails still failed because results left EEGPrep as Python scalars, 1-D arrays, lists, or too few outputs. Comparisons require MATLAB rows, columns, 1-by-1 arrays, or cell and character containers. Approach: Tests: the 69 markers are removed and those cases pass with Left xfailed: dataset and location struct arrays ( |
|
Claude finished @suraj-ranganath's task in 3m 0s —— View job Code review
Blocking1.
Important2. The new Both callers iterate the second output as a list of per-epoch lists. Iterating a
Fix: in both callers, iterate 3.
4.
Nits
Test gaps
EEGLAB parity notes
I couldn't run local tests in this environment (command approval was denied), so these findings come from reading the code and its callers. CI |
| @@ -41,7 +41,6 @@ def robust_kmeans( | |||
| ) | |||
| elif method.lower() == "kmeanscluster": | |||
| active_labels, centers, _previous, _matrix = kmeanscluster(values[active], cluster_count) | |||
There was a problem hiding this comment.
Blocking: pop_clust(..., algorithm="kmeanscluster", outliers=<finite>) now crashes.
kmeanscluster returns as_column(labels + 1), which has shape (k, 1). Two lines below, labels[active] = active_labels writes it into a 1-D (n,) array, and numpy raises ValueError: could not broadcast input array from shape (k,1) into shape (k,). Even with a working broadcast, _outlier_rows runs sorted(set(labels.tolist())), which fails on nested lists with TypeError: unhashable type: 'list'.
This is the robust_kmeans path that pop_clust uses when an outlier threshold is set (pop_clust.py#L75-L85), and no test covers it.
Fix: flatten here, and add a pop_clust(study, alleeg, algorithm="kmeanscluster", clus_num=4, outliers=3) test in tests/test_study_clustering.py.
| active_labels, centers, _previous, _matrix = kmeanscluster(values[active], cluster_count) | |
| active_labels, centers, _previous, _matrix = kmeanscluster(values[active], cluster_count) | |
| active_labels = active_labels.ravel() |
There was a problem hiding this comment.
🤖 Cluster labels from kmeanscluster stay a one-dimensional 1-based vector, so robust_kmeans can assign them and _outlier_rows can read them. pop_clust(..., algorithm='kmeanscluster', clus_num=4, outliers=3) is covered in tests/test_study_clustering.py. The MATLAB column shape is applied in tests/eeglab_tests/matlab_output_transport.py when the result leaves through call_python.
| cells = np.empty((1, len(all_epoch_values)), dtype=object) | ||
| for index, item in enumerate(all_epoch_values): | ||
| array = np.asarray(item) | ||
| cells[0, index] = array.reshape(1, -1) if array.ndim < 2 else array | ||
| return output_values, cells |
There was a problem hiding this comment.
Important: the new (1, N) cell output breaks both in-package callers.
Both callers iterate the second output as a list of per-epoch lists. Iterating a (1, N) object array yields one row, not N epochs.
pop_eventstat.event_values:groupis now the whole row, so eachitemis one epoch's(1, k)array. Whenk > 1,float(np.asarray(item).squeeze())raisesTypeError, theexceptcatches it, and that epoch's values are silently dropped. Continuous data puts every event in epoch 1, sopop_eventstatgets no values as soon as more than one event matches. Epoched data with several matching events per epoch loses those epochs.pop_erpimage._sorting_variable:enumerate(all_values)yields a single item of length N. The "multiple event latencies found in epochs 1" warning then fires for any multi-trial dataset and never names the right epochs.
Fix: update both callers to iterate np.asarray(grouped, dtype=object).ravel() and to use np.ravel(item) for each epoch's values. Add a pop_eventstat test on continuous data with several matching events, asserting the value count.
There was a problem hiding this comment.
🤖 eeg_getepochevent again returns a one-dimensional latency vector, or one list of latencies per epoch, so pop_eventstat and pop_erpimage see every matching event. tests/test_phase4_timefreq_statistics.py checks a continuous recording with three matching events. The reference comparison wraps that vector as a row in the output transport.
| else: | ||
| output = new_text | ||
| return (output, command) if return_com else output | ||
| return output, command |
There was a problem hiding this comment.
Important: pop_comments now always returns a tuple, which breaks the documented Python API.
EEG = pop_comments(EEG, '', 'note') now binds EEG to (EEG, ''), as does the cancel path on L40. That contradicts the packaged help (pop_comments.md#L5-L7). It also breaks the repo-wide return_com contract in AGENTS.md: "User-facing pop_* functions should support return_com=True and return EEGLAB-style history commands." Every other pop_* returns a bare result unless return_com=True. The test edits that add [0] / , _command hide the regression instead of catching it.
If the two-output form is only for the reference-suite transport, the transport should pass return_com=True, or use the matlab_outputs attribute pattern this PR already uses for pop_chancenter. The public function should not change.
| return output, command | |
| return (output, command) if return_com else output |
(L40 needs the matching return (original, "") if return_com else original, and the test edits need reverting.)
There was a problem hiding this comment.
🤖 Both the success path and the GUI cancel path return (output, command) if return_com else output. The unit tests call pop_comments without return_com again. The MATLAB backend passes return_com=True when nargout is greater than one.
|
|
||
| def __init__(self, values: dict[str, Any], unrecognized: list[Any]): | ||
| super().__init__(values) | ||
| self.values = self |
There was a problem hiding this comment.
Important: self.values = self shadows dict.values().
_CheckedArguments subclasses dict. An instance attribute named values takes precedence over the inherited dict.values method, so g = finputcheck(...); g.values() now raises TypeError: '_CheckedArguments' object is not callable. Any caller that iterates over the validated options with .values() breaks.
Fix: the transport only needs matlab_outputs to resolve to attributes. Expose the first output under a name that is not a dict method, for example matlab_outputs = ("g", "unrecognized") with self.g = self, or have backend.py map the first output to the object itself.
There was a problem hiding this comment.
🤖 The first MATLAB output is now g, the name EEGLAB assigns, so dict.values() stays the method. nargout=2 still returns the checked dict and the unrecognized cell.
The MATLAB output name is g, so the checked-arguments dict no longer shadows the values method. Co-authored-by: Suraj Ranganath <[email protected]>
MATLAB row and column shapes are applied in the output transport used by the Python backend, and pop_comments returns a command only when asked. Co-authored-by: Suraj Ranganath <[email protected]>
Keep both sides' Python-backend xfail removals. MATLAB row and column shapes stay in the output transport, and nargout still requests the history command for pop_comments, pop_copyset, and pop_editeventfield. Co-authored-by: Suraj Ranganath <[email protected]>
Channel matches, comment cells, and present-mode flags stay Python scalars and strings. The transport adds the struct, character matrix, and 1-by-1 shapes. pcsquash follows eig and does not flip eigenvector signs. Co-authored-by: Suraj Ranganath <[email protected]>
Python vector results stay one-dimensional. MATLAB row, column, and 1-by-1 shapes are applied in the output transport used by the Python backend, and the matching xfail markers stay removed. pop_comments returns the history command only when return_com is set. Dataset struct arrays and several multi-output returns still differ and stay xfailed. MATLAB is not installed, so the reference suite was not run.
Refs #430