-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
FIX: Replace np.fromstring with np.frombuffer in GDF reader for NumPy… #13415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… ≥1.24 Note that .encode() was added because np.frombuffer requires bytes.
Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴 |
mne/io/edf/edf.py
Outdated
etmode = fid.read(1).decode() | ||
if etmode != "": | ||
etmode = np.fromstring(etmode, UINT8).tolist()[0] | ||
etmode = np.frombuffer(etmode.encode(), dtype=UINT8).tolist()[0] |
There was a problem hiding this comment.
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]
Also needs a changelog entry in |
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.
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. |
@devparikh0506 we are trying to figure that part out. Stand by! |
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: mne-python/mne/datasets/config.py Lines 85 to 94 in a8e2fe8
mne-python/mne/datasets/config.py Lines 115 to 122 in a8e2fe8
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 Let us know if you have any questions along the way or need any help. |
https://github.com/mne-tools/mne-testing-data/releases/tag/0.165 release: |
… ≥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.np.frombuffer(etmode.encode(), dtype=UINT8)
in_read_gdf_header
.How was this tested?
pytest mne/io/edf/tests
successfully (all relevant tests passed)..gdf
files using Python 3.11.7 + NumPy 2.3.3.read_raw_gdf("B0101T.gdf", preload=True)
now works without errors.Additional information