Skip to content

Commit

Permalink
Merge pull request #4419 from VesnaT/state_summary
Browse files Browse the repository at this point in the history
[FIX] format_summary_details: Replace 'features' with 'variables'
  • Loading branch information
janezd authored Feb 14, 2020
2 parents 5c36a87 + b484745 commit f6fa3e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Orange/widgets/utils/state_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _plural(number):
n_features = len(data.domain.variables) + len(data.domain.metas)
details = \
f'{len(data)} instance{_plural(len(data))}, ' \
f'{n_features} feature{_plural(n_features)}\n' \
f'{n_features} variable{_plural(n_features)}\n' \
f'Features: {features}\nTarget: {targets}\nMetas: {metas}'

return details
26 changes: 16 additions & 10 deletions Orange/widgets/utils/tests/test_state_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import numpy as np

from Orange.widgets.utils.state_summary import format_summary_details
from Orange.data import Table, Domain, StringVariable, ContinuousVariable, \
DiscreteVariable, TimeVariable
from Orange.widgets.utils.state_summary import format_summary_details

VarDataPair = namedtuple('VarDataPair', ['variable', 'data'])

Expand Down Expand Up @@ -40,10 +40,12 @@
np.array([0, 1, 1, np.nan, 2], dtype=float),
)


def _to_timestamps(years):
return [datetime.datetime(year, 1, 1).timestamp() if not np.isnan(year)
else np.nan for year in years]


time_full = VarDataPair(
TimeVariable('time_full'),
np.array(_to_timestamps([2000, 2001, 2002, 2003, 2004]), dtype=float),
Expand Down Expand Up @@ -103,7 +105,7 @@ def test_details(self):
data = Table('zoo')
n_features = len(data.domain.variables) + len(data.domain.metas)
details = f'{len(data)} instances, ' \
f'{n_features} features\n' \
f'{n_features} variables\n' \
f'Features: {len(data.domain.attributes)} categorical\n' \
f'Target: categorical\n' \
f'Metas: string (not shown)'
Expand All @@ -112,7 +114,7 @@ def test_details(self):
data = Table('housing')
n_features = len(data.domain.variables) + len(data.domain.metas)
details = f'{len(data)} instances, ' \
f'{n_features} features\n' \
f'{n_features} variables\n' \
f'Features: {len(data.domain.attributes)} numeric\n' \
f'Target: numeric\n' \
f'Metas: —'
Expand All @@ -121,7 +123,7 @@ def test_details(self):
data = Table('heart_disease')
n_features = len(data.domain.variables) + len(data.domain.metas)
details = f'{len(data)} instances, ' \
f'{n_features} features\n' \
f'{n_features} variables\n' \
f'Features: {len(data.domain.attributes)} ' \
f'(7 categorical, 6 numeric)\n' \
f'Target: categorical\n' \
Expand All @@ -134,7 +136,7 @@ def test_details(self):
)
n_features = len(data.domain.variables) + len(data.domain.metas)
details = f'{len(data)} instances, ' \
f'{n_features} features\n' \
f'{n_features} variables\n' \
f'Features: {len(data.domain.attributes)} numeric\n' \
f'Target: {len(data.domain.class_vars)} categorical\n' \
f'Metas: {len(data.domain.metas)} categorical'
Expand All @@ -147,7 +149,7 @@ def test_details(self):
)
n_features = len(data.domain.variables) + len(data.domain.metas)
details = f'{len(data)} instances, ' \
f'{n_features} features\n' \
f'{n_features} variables\n' \
f'Features: {len(data.domain.attributes)} ' \
f'(2 categorical, 1 numeric, 1 time)\n' \
f'Target: {len(data.domain.class_vars)} ' \
Expand All @@ -158,27 +160,31 @@ def test_details(self):
data = make_table([time_full, time_missing], target=[ints_missing],
metas=None)
details = f'{len(data)} instances, ' \
f'{len(data.domain.variables)} features\n' \
f'Features: {len(data.domain.attributes)} time\n'\
f'{len(data.domain.variables)} variables\n' \
f'Features: {len(data.domain.attributes)} time\n' \
f'Target: categorical\n' \
f'Metas: —'
self.assertEqual(details, format_summary_details(data))

data = make_table([rgb_full, ints_full], target=None, metas=None)
details = f'{len(data)} instances, ' \
f'{len(data.domain.variables)} features\n' \
f'{len(data.domain.variables)} variables\n' \
f'Features: {len(data.domain.variables)} categorical\n' \
f'Target: —\n' \
f'Metas: —'
self.assertEqual(details, format_summary_details(data))

data = make_table([rgb_full], target=None, metas=None)
details = f'{len(data)} instances, ' \
f'{len(data.domain.variables)} feature\n' \
f'{len(data.domain.variables)} variable\n' \
f'Features: categorical\n' \
f'Target: —\n' \
f'Metas: —'
self.assertEqual(details, format_summary_details(data))

data = None
self.assertEqual('', format_summary_details(data))


if __name__ == "__main__":
unittest.main()

0 comments on commit f6fa3e3

Please sign in to comment.