diff --git a/Orange/widgets/data/owselectrows.py b/Orange/widgets/data/owselectrows.py index 124b55ce62a..8abb49f475c 100644 --- a/Orange/widgets/data/owselectrows.py +++ b/Orange/widgets/data/owselectrows.py @@ -554,7 +554,7 @@ def datetime_changed(): invalidate_datetime() datetime_format = (var.have_date, var.have_time) - column = self.data[:, var_idx] + column = self.data.get_column_view(var_idx)[0] w = DateTimeWidget(self, column, datetime_format) w.set_datetime(lc[0]) box.controls = [w] @@ -951,11 +951,10 @@ def convert_timestamp(timestamp): return datetime(1970, 1, 1, tzinfo=timezone.utc) + \ timedelta(seconds=int(timestamp)) - item_list = [item for items in list(column) for item in items] min_datetime = convert_timestamp( - np.nanmin(item_list)).strftime(convert_format) + np.nanmin(column)).strftime(convert_format) max_datetime = convert_timestamp( - np.nanmax(item_list)).strftime(convert_format) + np.nanmax(column)).strftime(convert_format) return min_datetime, max_datetime diff --git a/Orange/widgets/data/tests/test_owselectrows.py b/Orange/widgets/data/tests/test_owselectrows.py index adf1187abf8..17f3cc6eca9 100644 --- a/Orange/widgets/data/tests/test_owselectrows.py +++ b/Orange/widgets/data/tests/test_owselectrows.py @@ -10,7 +10,7 @@ from Orange.data import ( Table, Variable, ContinuousVariable, StringVariable, DiscreteVariable, - Domain) + Domain, TimeVariable) from Orange.preprocess import discretize from Orange.widgets.data import owselectrows from Orange.widgets.data.owselectrows import ( @@ -59,6 +59,18 @@ FilterDiscreteType.IsDefined: [], } +TFValues = { + FilterContinuous.Equal: [QDate(2013, 5, 5)], + FilterContinuous.NotEqual: [QDate(2013, 5, 5)], + FilterContinuous.Less: [QDate(2013, 5, 5)], + FilterContinuous.LessEqual: [QDate(2013, 5, 5)], + FilterContinuous.Greater: [QDate(2013, 5, 5)], + FilterContinuous.GreaterEqual: [QDate(2013, 5, 5)], + FilterContinuous.Between: [QDate(2013, 5, 5), QDate(2015, 5, 5)], + FilterContinuous.Outside: [QDate(2013, 5, 5), QDate(2015, 5, 5)], + FilterContinuous.IsDefined: [], +} + class TestOWSelectRows(WidgetTest): def setUp(self): @@ -75,6 +87,17 @@ def test_filter_cont(self): self.widget.conditions_changed() self.widget.unconditional_commit() + # continuous var in metas + iris = Table.from_table( + Domain([], metas=[iris.domain.attributes[0]]), iris + ) + self.widget.set_data(iris) + for i, (op, _) in enumerate(OWSelectRows.Operators[ContinuousVariable]): + self.widget.remove_all() + self.widget.add_row(iris.domain.metas[0], i, CFValues[op]) + self.widget.conditions_changed() + self.widget.unconditional_commit() + def test_filter_str(self): zoo = Table("zoo")[::5] self.widget.auto_commit = False @@ -96,6 +119,39 @@ def test_filter_disc(self): self.widget.conditions_changed() self.widget.unconditional_commit() + # discrete var in metas + lenses = Table.from_table( + Domain([], metas=[lenses.domain.attributes[0]]), lenses + ) + self.widget.set_data(lenses) + for i, (op, _) in enumerate(OWSelectRows.Operators[DiscreteVariable]): + self.widget.remove_all() + self.widget.add_row(lenses.domain.metas[0], i, DFValues[op]) + self.widget.conditions_changed() + self.widget.unconditional_commit() + + def test_filter_time(self): + data = Table(test_filename("datasets/cyber-security-breaches.tab")) + self.widget.auto_commit = False + self.widget.set_data(data) + + for i, (op, _) in enumerate(OWSelectRows.Operators[TimeVariable]): + self.widget.remove_all() + self.widget.add_row(data.domain["breach_start"], i, TFValues[op]) + self.widget.conditions_changed() + self.widget.unconditional_commit() + + # time var in metas + data = Table.from_table( + Domain([], metas=[data.domain["breach_start"]]), data + ) + self.widget.set_data(data) + for i, (op, _) in enumerate(OWSelectRows.Operators[TimeVariable]): + self.widget.remove_all() + self.widget.add_row(data.domain.metas[0], i, TFValues[op]) + self.widget.conditions_changed() + self.widget.unconditional_commit() + @override_locale(QLocale.C) # Locale with decimal point def test_continuous_filter_with_c_locale(self): iris = Table("iris")[:5]