From 675cfa7d7577432134f02018bd7b35c195665733 Mon Sep 17 00:00:00 2001 From: Marin Manuel Date: Mon, 23 Mar 2026 21:57:48 +0000 Subject: [PATCH 1/2] added utf8 decoding for strings if first attemp fails --- neo/rawio/openephysbinaryrawio.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/neo/rawio/openephysbinaryrawio.py b/neo/rawio/openephysbinaryrawio.py index bd767f1e0..b79b584ca 100644 --- a/neo/rawio/openephysbinaryrawio.py +++ b/neo/rawio/openephysbinaryrawio.py @@ -405,16 +405,31 @@ def _parse_header(self): # all theses data are put in event array annotations if "text" in info: # text case - info["labels"] = info["text"].astype("U") + try: + info["labels"] = info["text"].astype("U") + except UnicodeDecodeError: + info["labels"] = np.array([e.decode('utf-8') for e in info['text']], dtype='U') elif "metadata" in info: # binary case - info["labels"] = info["channels"].astype("U") + try: + info["labels"] = info["channels"].astype("U") + except UnicodeDecodeError: + # non-ascii character, fallback on UTF-8 decoding byte by byte + info["labels"] = np.array([e.decode('utf-8') for e in info['channels']], dtype='U') elif "channels" in info: # ttl case use channels - info["labels"] = info["channels"].astype("U") + try: + info["labels"] = info["channels"].astype("U") + except UnicodeDecodeError: + # non-ascii character, fallback on UTF-8 decoding byte by byte + info["labels"] = np.array([e.decode('utf-8') for e in info['channels']], dtype='U') elif "states" in info: # ttl case use states - info["labels"] = info["states"].astype("U") + try: + info["labels"] = info["states"].astype("U") + except UnicodeDecodeError: + # non-ascii character, fallback on UTF-8 decoding byte by byte + info["labels"] = np.array([e.decode('utf-8') for e in info['states']], dtype='U') else: raise ValueError(f"There is no possible labels for this event!") From cb1db663c7558bf502668228751c78f1b7857eae Mon Sep 17 00:00:00 2001 From: Marin Manuel Date: Mon, 23 Mar 2026 21:57:48 +0000 Subject: [PATCH 2/2] added utf8 decoding for strings if first attemp fails --- neo/rawio/openephysbinaryrawio.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/neo/rawio/openephysbinaryrawio.py b/neo/rawio/openephysbinaryrawio.py index bd767f1e0..b79b584ca 100644 --- a/neo/rawio/openephysbinaryrawio.py +++ b/neo/rawio/openephysbinaryrawio.py @@ -405,16 +405,31 @@ def _parse_header(self): # all theses data are put in event array annotations if "text" in info: # text case - info["labels"] = info["text"].astype("U") + try: + info["labels"] = info["text"].astype("U") + except UnicodeDecodeError: + info["labels"] = np.array([e.decode('utf-8') for e in info['text']], dtype='U') elif "metadata" in info: # binary case - info["labels"] = info["channels"].astype("U") + try: + info["labels"] = info["channels"].astype("U") + except UnicodeDecodeError: + # non-ascii character, fallback on UTF-8 decoding byte by byte + info["labels"] = np.array([e.decode('utf-8') for e in info['channels']], dtype='U') elif "channels" in info: # ttl case use channels - info["labels"] = info["channels"].astype("U") + try: + info["labels"] = info["channels"].astype("U") + except UnicodeDecodeError: + # non-ascii character, fallback on UTF-8 decoding byte by byte + info["labels"] = np.array([e.decode('utf-8') for e in info['channels']], dtype='U') elif "states" in info: # ttl case use states - info["labels"] = info["states"].astype("U") + try: + info["labels"] = info["states"].astype("U") + except UnicodeDecodeError: + # non-ascii character, fallback on UTF-8 decoding byte by byte + info["labels"] = np.array([e.decode('utf-8') for e in info['states']], dtype='U') else: raise ValueError(f"There is no possible labels for this event!")