From c8b801a7b16bc7a608096cc9d1746fe44d8bb28d Mon Sep 17 00:00:00 2001 From: Sjoerd Stendahl Date: Sun, 31 Dec 2023 08:59:35 +0100 Subject: [PATCH] adjust header detection --- src/parse_file.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/parse_file.py b/src/parse_file.py index 624f63f75..6b59ae966 100644 --- a/src/parse_file.py +++ b/src/parse_file.py @@ -135,30 +135,16 @@ def import_from_columns(self, file): # If not all values in the line are floats, start looking for # headers instead except ValueError: - # By default it will check for headers using at least - # two whitespaces as delimiter (often tabs), but if - # that doesn"t work it will try the same delimiter as - # used for the data import itself The reasoning is that - # some people use tabs for the headers, but e.g. commas - # for the data try: - headers = re.split("\\s{2,}", line) + headers = re.split(delimiter, line) if len(values) == 1: - item_.ylabel = headers[column_x] + item_.set_ylabel(headers[column_x]) else: - item_.xlabel = headers[column_x] - item_.ylabel = headers[column_y] + item_.set_xlabel(headers[column_x]) + item_.set_ylabel(headers[column_y]) + # If no label could be found at the index, skip. except IndexError: - try: - headers = re.split(delimiter, line) - if len(values) == 1: - item_.ylabel = headers[column_x] - else: - item_.xlabel = headers[column_x] - item_.ylabel = headers[column_y] - # If neither heuristic works, we just skip headers - except IndexError: - pass + pass if not item_.xdata: raise ParseError(_("Unable to import from file")) return [item_]