From ab866f27f89dcf10d6454594fb868a189062d13d Mon Sep 17 00:00:00 2001 From: Dev Parikh Date: Wed, 10 Sep 2025 23:15:40 -0400 Subject: [PATCH 1/3] =?UTF-8?q?FIX:=20Replace=20np.fromstring=20with=20np.?= =?UTF-8?q?frombuffer=20in=20GDF=20reader=20for=20NumPy=20=E2=89=A51.24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that .encode() was added because np.frombuffer requires bytes. --- mne/io/edf/edf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/io/edf/edf.py b/mne/io/edf/edf.py index 763ef4f91eb..4508d48bd7e 100644 --- a/mne/io/edf/edf.py +++ b/mne/io/edf/edf.py @@ -1443,7 +1443,7 @@ def _read_gdf_header(fname, exclude, include=None): fid.seek(etp) # skip data to go to event table etmode = fid.read(1).decode() if etmode != "": - etmode = np.fromstring(etmode, UINT8).tolist()[0] + etmode = np.frombuffer(etmode.encode(), dtype=UINT8).tolist()[0] if edf_info["number"] < 1.94: sr = np.fromfile(fid, UINT8, 3) From 9e9e281a523bf67bfb7ed822f4a57f96df6fc66c Mon Sep 17 00:00:00 2001 From: Dev Parikh Date: Thu, 11 Sep 2025 11:08:37 -0400 Subject: [PATCH 2/3] =?UTF-8?q?FIX:=20Use=20fid.read(1)=20+=20np.frombuffe?= =?UTF-8?q?r=20in=20GDF=20reader=20to=20replace=20np.fromstring=20(NumPy?= =?UTF-8?q?=20=E2=89=A51.24)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- doc/changes/dev/13415.bugfix.rst | 1 + doc/changes/names.inc | 1 + mne/io/edf/edf.py | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 doc/changes/dev/13415.bugfix.rst diff --git a/doc/changes/dev/13415.bugfix.rst b/doc/changes/dev/13415.bugfix.rst new file mode 100644 index 00000000000..371e426a3ed --- /dev/null +++ b/doc/changes/dev/13415.bugfix.rst @@ -0,0 +1 @@ +Fixed a bug where ``mne.io.read_raw_gdf`` failed with NumPy ≥1.24 due to the removal of ``np.fromstring`` binary mode. Replaced with ``np.frombuffer`` for compatibility. (:newcontrib:`devparikh0506`) \ No newline at end of file diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 38c240d69d7..5da6a3f77cb 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -339,3 +339,4 @@ .. _Zhi Zhang: https://github.com/tczhangzhi/ .. _Ziyi ZENG: https://github.com/ZiyiTsang .. _Zvi Baratz: https://github.com/ZviBaratz +.. _Dev Parikh: https://github.com/devparikh0506 diff --git a/mne/io/edf/edf.py b/mne/io/edf/edf.py index 4508d48bd7e..83e66b9f9c6 100644 --- a/mne/io/edf/edf.py +++ b/mne/io/edf/edf.py @@ -1441,9 +1441,9 @@ def _read_gdf_header(fname, exclude, include=None): edf_info["data_offset"] + edf_info["n_records"] * edf_info["bytes_tot"] ) fid.seek(etp) # skip data to go to event table - etmode = fid.read(1).decode() + etmode = fid.read(1) if etmode != "": - etmode = np.frombuffer(etmode.encode(), dtype=UINT8).tolist()[0] + etmode = np.frombuffer(etmode, dtype=UINT8).tolist()[0] if edf_info["number"] < 1.94: sr = np.fromfile(fid, UINT8, 3) From fc98279b3b3ee9c76b3820d40e16d4c1b9dba570 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Sep 2025 15:11:00 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/changes/names.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 5da6a3f77cb..fbbe285720b 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -65,6 +65,7 @@ .. _David Sabbagh: https://github.com/DavidSabbagh .. _Demetres Kostas: https://github.com/kostasde .. _Denis Engemann: https://denis-engemann.de +.. _Dev Parikh: https://github.com/devparikh0506 .. _Dinara Issagaliyeva: https://github.com/dissagaliyeva .. _Diptyajit Das: https://github.com/dasdiptyajit .. _Dirk Gütlin: https://github.com/DiGyt @@ -339,4 +340,3 @@ .. _Zhi Zhang: https://github.com/tczhangzhi/ .. _Ziyi ZENG: https://github.com/ZiyiTsang .. _Zvi Baratz: https://github.com/ZviBaratz -.. _Dev Parikh: https://github.com/devparikh0506