Skip to content

Commit

Permalink
Merge pull request #4912 from PrimozGodec/fix-timevarmetacharsh
Browse files Browse the repository at this point in the history
[FIX] Select Rows: fix fail when time variable in metas
  • Loading branch information
ajdapretnar authored Jul 24, 2020
2 parents 56cc38c + af6bdc1 commit 945e235
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
7 changes: 3 additions & 4 deletions Orange/widgets/data/owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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


Expand Down
58 changes: 57 additions & 1 deletion Orange/widgets/data/tests/test_owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 945e235

Please sign in to comment.