Skip to content

Commit 6c742f7

Browse files
authored
Merge pull request #6862 from VesnaT/fix_header_flags
CSVReader, ExcelReader: Consider attribute type in header flags
2 parents b981d76 + 1d5c288 commit 6c742f7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Orange/data/io_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ def _header1(cls, headers: List[List[str]]) -> Tuple[List, List, List]:
170170
"""
171171

172172
def is_flag(x):
173-
return bool(Flags.RE_ALL.match(cls._type_from_flag([x])[0]) or
173+
return bool(cls._type_from_flag([x])[0] and
174+
_RE_TYPES.match(cls._type_from_flag([x])[0]) or
174175
Flags.RE_ALL.match(cls._flag_from_flag([x])[0]))
175176

176177
flags, names = zip(*[i.split(cls.HEADER1_FLAG_SEP, 1)

Orange/data/tests/test_io_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def setUpClass(cls):
2323
["red", "0.5", "0.0", "0.0", "aa", "a"],
2424
["red", "0.1", "1.0", "1.0", "b", "b"],
2525
["green", "0.0", "2.0", "2.0", "c", "c"]]
26+
cls.header1_flags2 = [["D#a1", "D#a2", "cD#a3", "C#a4", "S#a5",
27+
"mS#a6", "T#a7", "mT#a8", "T#a9"],
28+
["", "0", "", "0", "a", "a",
29+
"2024-01-01", "2024-01-01", ""],
30+
["", "1", "", "1", "b", "b",
31+
"2024-01-01", "2024-01-01", ""],
32+
["green", "0.0", "2.0", "2.0", "c", "c"]]
2633
cls.header3 = [["a", "b", "c", "d", "w", "e", "f", "g"],
2734
["d", "c", "c", "c", "c", "d", "s", "yes no"],
2835
["meta", "class", "meta", "", "weight", "i", "", ""],
@@ -53,6 +60,16 @@ def test_get_header_data_1_flags(self):
5360
self.assertListEqual(types, ["", "c", "", "", "", ""])
5461
self.assertListEqual(flags, ["m", "c", "m", "", "i", ""])
5562

63+
def test_get_header_data_1_flags2(self):
64+
names, types, flags = _TableHeader.create_header_data(
65+
self.header1_flags2[:1])
66+
names_ = ["a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"]
67+
types_ = ["d", "d", "d", "c", "s", "s", "t", "t", "t"]
68+
flags_ = ["", "", "c", "", "", "m", "", "m", ""]
69+
self.assertListEqual(names, names_)
70+
self.assertListEqual(types, types_)
71+
self.assertListEqual(flags, flags_)
72+
5673
def test_get_header_data_3(self):
5774
names, types, flags = _TableHeader.create_header_data(self.header3[:3])
5875
self.assertListEqual(names, ["a", "b", "c", "d", "w", "e", "f", "g"])

0 commit comments

Comments
 (0)