Skip to content

Conversation

devparikh0506
Copy link

… ≥1.24

Note that .encode() was added because np.frombuffer requires bytes.

Reference issue (if any)

Fixes #13414.

What does this implement/fix?

  • np.fromstring in binary mode was removed in NumPy ≥1.24.
  • Replaced with np.frombuffer(etmode.encode(), dtype=UINT8) in _read_gdf_header.
  • This preserves the original behavior and restores compatibility.

How was this tested?

  • Ran pytest mne/io/edf/tests successfully (all relevant tests passed).
  • Verified on BCI Competition IV Dataset 2b .gdf files using Python 3.11.7 + NumPy 2.3.3.
  • read_raw_gdf("B0101T.gdf", preload=True) now works without errors.

Additional information

  • No API changes.
  • Minor internal fix for compatibility with modern NumPy.
… ≥1.24 Note that .encode() was added because np.frombuffer requires bytes.
Copy link

welcome bot commented Sep 11, 2025

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴

Comment on lines 1444 to 1446
etmode = fid.read(1).decode()
if etmode != "":
etmode = np.fromstring(etmode, UINT8).tolist()[0]
etmode = np.frombuffer(etmode.encode(), dtype=UINT8).tolist()[0]
Copy link
Member

@larsoner larsoner Sep 11, 2025

Choose a reason for hiding this comment

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

We decode it just to encode it? Maybe we could do instead

etmode = fid.read(1) if len(etmode): etmode = np.frombuffer(etmode, dtype=UINT8)[0] 
@larsoner
Copy link
Member

Also needs a changelog entry in doc/changes/devel/13415.bugfix.rst with :newcontrib: and a name+link in doc/changes/names.inc. Thanks for working on this @devparikh0506 !

@drammock
Copy link
Member

would be great if the test coverage gap @scott-huberty mentioned in #13414 (comment) could also be closed here. @devparikh0506 let us know if you want help with that part.

…string (NumPy ≥1.24) - Now reading a single byte directly from the file handle (fid.read(1)), and parsing it using np.frombuffer with dtype=UINT8. - Added changelog entry (doc/changes/devel/13415.bugfix.rst) and contributor link in doc/changes/names.inc.
@devparikh0506
Copy link
Author

Hi @larsoner, thanks for pointing out the improvement! I’ve updated the PR with the suggested change.

Also @drammock, I’d be happy to add test coverage for this. Could you please provide a brief outline of the steps or the best place in the test suite to add it? That would help me make sure I implement it correctly.

@scott-huberty
Copy link
Contributor

Could you please provide a brief outline of the steps or the best place in the test suite to add it?

@devparikh0506 we are trying to figure that part out. Stand by!

@scott-huberty
Copy link
Contributor

scott-huberty commented Sep 14, 2025

Needs mne-tools/mne-testing-data#124

@devparikh0506 I submitted a PR to add a test file to mne-testing-data . Once it is merged and @larsoner cuts a new release, You will need to update this PR to point to the newly released testing dataset, by following the directions here:

# To update the `testing` or `misc` datasets, push or merge commits to their
# respective repos, and make a new release of the dataset on GitHub. Then
# update the checksum in the MNE_DATASETS dict below, and change version
# here: ↓↓↓↓↓↓↓↓
RELEASES = dict(
testing="0.161",
misc="0.27",
phantom_kit="0.2",
ucl_opm_auditory="0.2",
)

# Testing and misc are at the top as they're updated most often
MNE_DATASETS["testing"] = dict(
archive_name=f"{TESTING_VERSIONED}.tar.gz",
hash="md5:a32cfb9e098dec39a5f3ed6c0833580d",
url=(
"https://codeload.github.com/mne-tools/mne-testing-data/"
f"tar.gz/{RELEASES['testing']}"
),

Once this is updated, you can run:

import mne testing_fpath = mne.datasets.testing.data_path(force_update=True) # FYI The new test file will be located at: testing_fpath / "GDF" / "test_gdf_1.99.gdf"

Which should download the updated testing dataset. At this point you can add a unit test to mne/io/edf/tests/test_gdf.py, that reads 'test_gdf_1.99.gdf' . This should confirm that your patch works and address our coverage gap!

Let us know if you have any questions along the way or need any help.

@scott-huberty
Copy link
Contributor

https://github.com/mne-tools/mne-testing-data/releases/tag/0.165

release: 0.165
md5: 5b791cb91e0f62732aa5827d9aba706d

@scott-huberty
Copy link
Contributor

Hey @devparikh0506 Let us know if you don't have time to work on this and need us to push it over the line! (i.e. close this PR and open a superceding PR that builds off the work done here).

@devparikh0506
Copy link
Author

devparikh0506 commented Sep 29, 2025

Hey @devparikh0506 Let us know if you don't have time to work on this and need us to push it over the line! (i.e. close this PR and open a superceding PR that builds off the work done here).

Hi @scott-huberty, Thank you for checking in. I am currently traveling and will not be able to write the tests or complete this work. I apologize for the delay, and I would appreciate it if you could take it forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants