Skip to content

Commit

Permalink
CSVReader, ExcelReader: Consider attribute type in header flags
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Jul 29, 2024
1 parent 09df730 commit 1d5c288
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Orange/data/io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions Orange/data/tests/test_io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "", ""],
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit 1d5c288

Please sign in to comment.