Skip to content

Commit

Permalink
owfeatureconstructor: Always use Values for TimeVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed May 18, 2022
1 parent fc4807c commit d133f43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Orange/widgets/data/owfeatureconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,8 @@ def extract_column(self, table: Table, var: Variable):
idx = data.astype(int)
idx[~np.isfinite(data)] = len(values) - 1
return values[idx].tolist()
elif var.is_time: # time always needs Values due to str(val) formatting
return Value._as_values(var, data.tolist()) # pylint: disable=protected-access
elif not self.use_values:
return data.tolist()
else:
Expand Down
6 changes: 6 additions & 0 deletions Orange/widgets/data/tests/test_owfeatureconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ def test_missing_variable(self):
self.assertTrue(np.all(np.isnan(r)))
self.assertTrue(np.isnan(f(data2[0])))

def test_time_str(self):
data = Table.from_numpy(Domain([TimeVariable("T", have_date=True)]), [[0], [0]])
f = FeatureFunc("str(T)", [("T", data.domain[0])])
c = f(data)
self.assertEqual(c, ["1970-01-01", "1970-01-01"])

def test_invalid_expression_variable(self):
iris = Table("iris")
f = FeatureFunc("1 / petal_length",
Expand Down

0 comments on commit d133f43

Please sign in to comment.