Skip to content

Commit f7fd48c

Browse files
authored
Merge pull request #5152 from ales-erjavec/fixes/feature-statistics-time-format
[FIX] Feature Statistics: Error in time variable display
2 parents e5d5fa0 + 7b0b946 commit f7fd48c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Orange/widgets/data/owfeaturestatistics.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ def __init__(self, data=None, parent=None):
149149
self.n_attributes = self.n_instances = 0
150150

151151
self.__attributes = self.__class_vars = self.__metas = None
152+
# sets of variables for fast membership tests
153+
self.__attributes_set = set()
154+
self.__class_vars_set = set()
155+
self.__metas_set = set()
152156
self.__distributions_cache = {}
153157

154158
no_data = np.array([])
@@ -176,7 +180,9 @@ def set_data(self, data):
176180
# while we need a 2d array, which `_Y` provides
177181
self.__class_vars = self.__filter_attributes(domain.class_vars, self.table._Y) # pylint: disable=protected-access
178182
self.__metas = self.__filter_attributes(domain.metas, self.table.metas)
179-
183+
self.__attributes_set = set(self.__metas[0])
184+
self.__class_vars_set = set(self.__class_vars[0])
185+
self.__metas_set = set(self.__metas[0])
180186
self.n_attributes = len(self.variables)
181187
self.n_instances = len(data)
182188

@@ -191,6 +197,9 @@ def clear(self):
191197
self.__attributes = (np.array([]), np.array([]))
192198
self.__class_vars = (np.array([]), np.array([]))
193199
self.__metas = (np.array([]), np.array([]))
200+
self.__attributes_set = set()
201+
self.__class_vars_set = set()
202+
self.__metas_set = set()
194203
self.__distributions_cache.clear()
195204
self.endResetModel()
196205

@@ -471,11 +480,11 @@ def headerData(self, section, orientation, role):
471480
def data(self, index, role):
472481
# type: (QModelIndex, Qt.ItemDataRole) -> Any
473482
def background():
474-
if attribute in self.domain.attributes:
483+
if attribute in self.__attributes_set:
475484
return self.COLOR_FOR_ROLE[self.ATTRIBUTE]
476-
if attribute in self.domain.metas:
485+
if attribute in self.__metas_set:
477486
return self.COLOR_FOR_ROLE[self.META]
478-
if attribute in self.domain.class_vars:
487+
if attribute in self.__class_vars_set:
479488
return self.COLOR_FOR_ROLE[self.CLASS_VAR]
480489
return None
481490

@@ -505,7 +514,7 @@ def render_value(value):
505514
return "∞"
506515

507516
str_val = attribute.str_val(value)
508-
if attribute.is_continuous:
517+
if attribute.is_continuous and not attribute.is_time:
509518
str_val = format_zeros(str_val)
510519

511520
return str_val

Orange/widgets/data/tests/test_owfeaturestatistics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _to_timestamps(years):
105105
# Time variable variations, windows timestamps need to be valid timestamps so
106106
# we'll just fill it in with arbitrary years
107107
time_full = VarDataPair(
108-
TimeVariable('time_full'),
108+
TimeVariable('time_full', have_date=True, have_time=True),
109109
np.array(_to_timestamps([2000, 2001, 2002, 2003, 2004]), dtype=float),
110110
)
111111
time_missing = VarDataPair(
@@ -117,7 +117,7 @@ def _to_timestamps(years):
117117
np.array(_to_timestamps([np.nan] * 5), dtype=float),
118118
)
119119
time_same = VarDataPair(
120-
TimeVariable('time_same'),
120+
TimeVariable('time_same', have_date=True, have_time=True),
121121
np.array(_to_timestamps([2004] * 5), dtype=float),
122122
)
123123
time = [

0 commit comments

Comments
 (0)