Skip to content

Fix 1-based index translation for pop_interp and pop_editset#251

Open
google-labs-jules[bot] wants to merge 1 commit into
developfrom
jules/fix-eeg-index-translation-js1-28c291bc-158f-413c-97f3-6fca792c277d
Open

Fix 1-based index translation for pop_interp and pop_editset#251
google-labs-jules[bot] wants to merge 1 commit into
developfrom
jules/fix-eeg-index-translation-js1-28c291bc-158f-413c-97f3-6fca792c277d

Conversation

@google-labs-jules

Copy link
Copy Markdown

This PR addresses critical off-by-one errors in the EEG interactive console when users provide MATLAB-style (1-based) indices. Previously, the system relied on fragile regex patterns to intercept commands, which frequently failed to capture complex user inputs or specific keyword arguments, leading to silent data corruption.

Rationale

To ensure data integrity, we are migrating index translation from simple string pattern matching to a robust AST (Abstract Syntax Tree) transformation layer. This allows the console to accurately identify and decrement integer literals and lists regardless of whether they are provided as positional or keyword arguments.

Key Changes

  • Migration to AST Transformation: Removed the legacy _POP_INTERP_CHANNELS_PATTERN and _pythonize_pop_interp_channels logic. These have been replaced by hooks in the _ConsoleCommandArgumentConverter pass.
  • Enhanced pop_interp Support:
    • The translation layer now correctly identifies the primary channel argument (index 1).
    • It explicitly monitors keyword arguments and MATLAB-style string pairings including channels, bad_chans, and bad_elec.
  • Enhanced pop_editset Support:
    • Added interception for the icachansind argument.
    • The system now handles both inline kwargs (e.g., icachansind=15) and positional string sequences (e.g., 'icachansind', 15), converting them to 0-based Python indices.
  • Literal Value Scope: In alignment with current constraints, this translation only applies to literal integers and literal lists. Expressions involving variables or dynamic function calls (e.g., np.arange) remain out of scope to avoid side effects.

Success Criteria

  • Commands like pop_interp(EEG, [1, 2, 3]) correctly target Python indices [0, 1, 2].
  • Keyword arguments for interpolation (e.g., bad_chans=[10]) are successfully zero-indexed.
  • The icachansind parameter in pop_editset is correctly translated.
  • Verified that these changes only affect the interactive console translation layer and do not modify the underlying core API logic.

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.

0 participants