diff --git a/doc/changes/dev/13497.bugfix.rst b/doc/changes/dev/13497.bugfix.rst new file mode 100644 index 00000000000..d86ec7b7835 --- /dev/null +++ b/doc/changes/dev/13497.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, by :newcontrib:`Dev Parikh`. diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 709a7ebd623..27d5398c9f7 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -67,6 +67,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 diff --git a/mne/io/edf/edf.py b/mne/io/edf/edf.py index 7d73c287d39..b03a80d5763 100644 --- a/mne/io/edf/edf.py +++ b/mne/io/edf/edf.py @@ -1734,9 +1734,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() - if etmode != "": - etmode = np.fromstring(etmode, UINT8).tolist()[0] + etmode = fid.read(1) + if isinstance(etmode, (bytes, bytearray)) and len(etmode) == 1: + etmode = np.frombuffer(etmode, dtype=UINT8).tolist()[0] if edf_info["number"] < 1.94: sr = read_from_file_or_buffer(fid, UINT8, 3) diff --git a/mne/io/edf/tests/test_gdf.py b/mne/io/edf/tests/test_gdf.py index 7b1d03f1960..4a62163b89d 100644 --- a/mne/io/edf/tests/test_gdf.py +++ b/mne/io/edf/tests/test_gdf.py @@ -199,3 +199,13 @@ def test_gdf_read_from_file_like(): with pytest.raises(Exception, match="Bad GDF file provided."): read_raw_gdf(BytesIO(), preload=True) + + +@testing.requires_testing_data +@pytest.mark.filterwarnings("ignore:Highpass cutoff frequency") +def test_gh_13414(): + """Test handling bytes objects when reading GDF events.""" + fpath = data_path / "GDF" / "test_gdf_1.99.gdf" + raw = read_raw_gdf(fpath) + # Should be 1 event in this GDF file. + assert len(raw.annotations) == 1