From 4e0ff4eddd2fd6a30e92c207bd25f6e51e9b73c6 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Fri, 24 Mar 2023 11:03:50 +0100 Subject: [PATCH] replace semicolon and commas with spaces in csv; closes #23 --- src/nmreval/io/asciireader.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/nmreval/io/asciireader.py b/src/nmreval/io/asciireader.py index 979c560..c10c158 100644 --- a/src/nmreval/io/asciireader.py +++ b/src/nmreval/io/asciireader.py @@ -1,5 +1,6 @@ import pathlib import re +from io import BytesIO from itertools import islice import numpy as np @@ -99,7 +100,10 @@ class AsciiReader: y = list(range(1, max(self.width))) cols = x + y + yerr - raw_data = np.genfromtxt(self.fname, usecols=cols, missing_values='--') + with self.fname.open('rb') as fh: + tmp_ = re.sub(b'[;,]', b' ', fh.read()) + raw_data = np.genfromtxt(BytesIO(tmp_), usecols=cols, missing_values='--') + del tmp_ if raw_data.ndim == 1: # only one row or column if len(self.data) == 1: