Skip to content
Merged
1 change: 1 addition & 0 deletions doc/changes/dev/13497.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions doc/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mne/io/edf/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions mne/io/edf/tests/test_gdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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