Skip to content

Commit 823463e

Browse files
scott-hubertydevparikh0506pre-commit-ci[bot]larsoner
authored
FIX: Replace use of deprecated Numpy func in GDF reader (Supersedes #13415) (#13497)
Co-authored-by: Dev Parikh <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Larson <[email protected]>
1 parent dc61256 commit 823463e

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

doc/changes/dev/13497.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`.

doc/changes/names.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
.. _David Sabbagh: https://github.com/DavidSabbagh
6868
.. _Demetres Kostas: https://github.com/kostasde
6969
.. _Denis Engemann: https://denis-engemann.de
70+
.. _Dev Parikh: https://github.com/devparikh0506
7071
.. _Dinara Issagaliyeva: https://github.com/dissagaliyeva
7172
.. _Diptyajit Das: https://github.com/dasdiptyajit
7273
.. _Dirk Gütlin: https://github.com/DiGyt

mne/io/edf/edf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,9 +1734,9 @@ def _read_gdf_header(fname, exclude, include=None):
17341734
edf_info["data_offset"] + edf_info["n_records"] * edf_info["bytes_tot"]
17351735
)
17361736
fid.seek(etp) # skip data to go to event table
1737-
etmode = fid.read(1).decode()
1738-
if etmode != "":
1739-
etmode = np.fromstring(etmode, UINT8).tolist()[0]
1737+
etmode = fid.read(1)
1738+
if isinstance(etmode, (bytes, bytearray)) and len(etmode) == 1:
1739+
etmode = np.frombuffer(etmode, dtype=UINT8).tolist()[0]
17401740

17411741
if edf_info["number"] < 1.94:
17421742
sr = read_from_file_or_buffer(fid, UINT8, 3)

mne/io/edf/tests/test_gdf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,13 @@ def test_gdf_read_from_file_like():
199199

200200
with pytest.raises(Exception, match="Bad GDF file provided."):
201201
read_raw_gdf(BytesIO(), preload=True)
202+
203+
204+
@testing.requires_testing_data
205+
@pytest.mark.filterwarnings("ignore:Highpass cutoff frequency")
206+
def test_gh_13414():
207+
"""Test handling bytes objects when reading GDF events."""
208+
fpath = data_path / "GDF" / "test_gdf_1.99.gdf"
209+
raw = read_raw_gdf(fpath)
210+
# Should be 1 event in this GDF file.
211+
assert len(raw.annotations) == 1

0 commit comments

Comments
 (0)