Skip to content

Commit

Permalink
1 line tab-header: use named re's
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Dec 20, 2024
1 parent a32263a commit f75a884
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Orange/data/io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,19 @@ def _header1(cls, headers: List[List[str]]) -> Tuple[List, List, List]:
for vartype in Variable.registry.values())
if len(t) == 1]).upper() # CNDST

res = ('^(?:('
res = ('^((?P<flags>'
f'[{roles}{types}]|'
f'(?:[{roles}][{types}])|'
f'(?:[{types}][{roles}])'
')#)?(.*)')
f'([{roles}][{types}])|'
f'([{types}][{roles}])'
')#)?(?P<name>.*)')

header1_re = re.compile(res)

flags = []
names = []
for i in headers[0]:
m = header1_re.match(i)
f, n = m.group(1), m.group(2)
f, n = m.group("flags", "name")
flags.append('' if f is None else f)
names.append(n)

Expand Down
10 changes: 6 additions & 4 deletions Orange/data/tests/test_io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ def test_get_header_data_1_flags2(self):

def test_get_header_data_1_hashes(self):
names, types, flags = _TableHeader.create_header_data(
[["Some long text#and here", "vd#Invalid spec", "C#Valid spec"]])
names_ = ["Some long text#and here", "vd#Invalid spec", "Valid spec"]
types_ = ["", "", "c"]
flags_ = ["", "", ""]
[["Some long text#and here", "vd#Invalid spec", "C#Valid spec",
"m#Meta", "cD#Discrete class", "Si#Ignored string"]])
names_ = ["Some long text#and here", "vd#Invalid spec", "Valid spec",
"Meta", "Discrete class", "Ignored string"]
types_ = ["", "", "c", "", "d", "s"]
flags_ = ["", "", "", "m", "c", "i"]
self.assertListEqual(names, names_)
self.assertListEqual(types, types_)
self.assertListEqual(flags, flags_)
Expand Down
9 changes: 9 additions & 0 deletions i18n/si/msgs.jaml
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,15 @@ data/io_base.py:
^\s*( |{}|)*\s*$: false
class `_TableHeader`:
'#': false
def `_header1`:
TYPE_HEADERS: false
^((?P<flags>: false
[{roles}{types}]|: false
([{roles}][{types}])|: false
([{types}][{roles}]): false
)#)?(?P<name>.*): false
flags: false
name: false
class `_TableBuilder`:
def `__init__`:
'Feature ': false
Expand Down

0 comments on commit f75a884

Please sign in to comment.