Skip to content

Commit bef62df

Browse files
committed
Modification of the string construction
1 parent 980210d commit bef62df

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

Orange/widgets/utils/state_summary.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ def format_variables_string(variables):
1010
:param variables: Features, targets or metas of the input dataset
1111
:return: A formatted string
1212
"""
13+
if not variables:
14+
return '—'
15+
1316
agg = []
1417
for var_type_name, var_type in [('categorical', DiscreteVariable),
1518
('numeric', ContinuousVariable),
@@ -21,28 +24,19 @@ def format_variables_string(variables):
2124
# `isinstance`, which would fail in the above case
2225
var_type_list = [v for v in variables if type(v) is var_type] # pylint: disable=unidiomatic-typecheck
2326
if var_type_list:
24-
shown = var_type in (StringVariable,)
25-
agg.append(
26-
(f'{len(var_type_list)} ' + var_type_name +
27-
f"{['', ' (not shown)'][shown]}",
28-
len(var_type_list)))
29-
30-
if not agg:
31-
return '—'
27+
not_shown = ' (not shown)' if issubclass(var_type, StringVariable)\
28+
else ''
29+
agg.append((f'{var_type_name}{not_shown}', len(var_type_list)))
3230

3331
attrs, counts = list(zip(*agg))
3432
if len(attrs) > 1:
35-
var_string = ', '.join(attrs[:-1]) + ', ' + attrs[-1]
36-
return f'{sum(counts)} (' + var_string + ')'
37-
elif sum(counts) == 1:
38-
var_string = attrs[0][2:]
39-
return var_string
33+
var_string = [f'{i} {j}' for i, j in zip(counts, attrs)]
34+
var_string = f'{sum(counts)} ({", ".join(var_string)})'
35+
elif counts[0] == 1:
36+
var_string = attrs[0]
4037
else:
41-
types = [s for s in ['categorical', 'numeric', 'time', 'string'] if
42-
s in attrs[0]]
43-
ind = attrs[0].find(types[0])
44-
var_string = attrs[0][ind:]
45-
return f'{sum(counts)} ' + var_string
38+
var_string = f'{counts[0]} {attrs[0]}'
39+
return var_string
4640

4741

4842
def format_summary_details(data):
@@ -55,7 +49,7 @@ def format_summary_details(data):
5549
:return: A formatted string
5650
"""
5751
def _plural(number):
58-
return number, 's' * (number != 1)
52+
return 's' * (number != 1)
5953

6054
details = ''
6155
if data:
@@ -65,10 +59,8 @@ def _plural(number):
6559

6660
n_features = len(data.domain.variables) + len(data.domain.metas)
6761
details = \
68-
f'{_plural(len(data))[0]} instance{_plural(len(data))[1]}, ' \
69-
f'{_plural(n_features)[0]} feature{_plural(n_features)[1]}\n' \
70-
f'Features: ' + features + '\n' + \
71-
f'Target: ' + targets + '\n' + \
72-
f'Metas: ' + metas
62+
f'{len(data)} instance{_plural(len(data))}, ' \
63+
f'{n_features} feature{_plural(n_features)}\n' \
64+
f'Features: {features}\nTarget: {targets}\nMetas: {metas}'
7365

7466
return details

0 commit comments

Comments
 (0)