From 1d5c28890a282f962a1ba22b7ff2450d2388b7a6 Mon Sep 17 00:00:00 2001 From: Vesna Tanko Date: Mon, 29 Jul 2024 11:57:39 +0200 Subject: [PATCH] CSVReader, ExcelReader: Consider attribute type in header flags --- Orange/data/io_base.py | 3 ++- Orange/data/tests/test_io_base.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Orange/data/io_base.py b/Orange/data/io_base.py index 914d1d3377b..6b74e72a953 100644 --- a/Orange/data/io_base.py +++ b/Orange/data/io_base.py @@ -170,7 +170,8 @@ def _header1(cls, headers: List[List[str]]) -> Tuple[List, List, List]: """ def is_flag(x): - return bool(Flags.RE_ALL.match(cls._type_from_flag([x])[0]) or + return bool(cls._type_from_flag([x])[0] and + _RE_TYPES.match(cls._type_from_flag([x])[0]) or Flags.RE_ALL.match(cls._flag_from_flag([x])[0])) flags, names = zip(*[i.split(cls.HEADER1_FLAG_SEP, 1) diff --git a/Orange/data/tests/test_io_base.py b/Orange/data/tests/test_io_base.py index 737e353deab..ba272c4d6a0 100644 --- a/Orange/data/tests/test_io_base.py +++ b/Orange/data/tests/test_io_base.py @@ -23,6 +23,13 @@ def setUpClass(cls): ["red", "0.5", "0.0", "0.0", "aa", "a"], ["red", "0.1", "1.0", "1.0", "b", "b"], ["green", "0.0", "2.0", "2.0", "c", "c"]] + cls.header1_flags2 = [["D#a1", "D#a2", "cD#a3", "C#a4", "S#a5", + "mS#a6", "T#a7", "mT#a8", "T#a9"], + ["", "0", "", "0", "a", "a", + "2024-01-01", "2024-01-01", ""], + ["", "1", "", "1", "b", "b", + "2024-01-01", "2024-01-01", ""], + ["green", "0.0", "2.0", "2.0", "c", "c"]] cls.header3 = [["a", "b", "c", "d", "w", "e", "f", "g"], ["d", "c", "c", "c", "c", "d", "s", "yes no"], ["meta", "class", "meta", "", "weight", "i", "", ""], @@ -53,6 +60,16 @@ def test_get_header_data_1_flags(self): self.assertListEqual(types, ["", "c", "", "", "", ""]) self.assertListEqual(flags, ["m", "c", "m", "", "i", ""]) + def test_get_header_data_1_flags2(self): + names, types, flags = _TableHeader.create_header_data( + self.header1_flags2[:1]) + names_ = ["a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"] + types_ = ["d", "d", "d", "c", "s", "s", "t", "t", "t"] + flags_ = ["", "", "c", "", "", "m", "", "m", ""] + self.assertListEqual(names, names_) + self.assertListEqual(types, types_) + self.assertListEqual(flags, flags_) + def test_get_header_data_3(self): names, types, flags = _TableHeader.create_header_data(self.header3[:3]) self.assertListEqual(names, ["a", "b", "c", "d", "w", "e", "f", "g"])