Skip to content

ENH: Support io.BytesIO in BaseRaw.save and mne.io.read_raw #14514

Open

Description

@bruAristimunha

While integrating MNE with Hugging Face datasets (Biosignal feature storing Arrow/Parquet bytes), we noticed that mne.io.read_raw_fif and mne._fiff.write.start_file already accept io.BytesIO, but BaseRaw.save and mne.io.read_raw reject file-like objects:

  1. raw.save(io.BytesIO()) fails in _check_fname (TypeError: fname must be an instance of path-like, got <class '_io.BytesIO'> instead), _write_raw accesses fpath.parent, and end_file calls fid.close() (which frees the BytesIO buffer).
  2. mne.io.read_raw(io.BytesIO(data)) fails in split_name_ext (Path(fname).suffixes) instead of dispatching when _file_like(fname) is True (e.g. via getattr(fname, "name", None) or magic bytes).

Supporting io.BytesIO in raw.save and mne.io.read_raw would avoid temporary .fif files on disk when serializing/deserializing BaseRaw objects in memory.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions