Skip to content

Commit

Permalink
Merge pull request #6352 from noahnovsak/str-value
Browse files Browse the repository at this point in the history
FIX: create Values from strings
  • Loading branch information
markotoplak authored Feb 27, 2023
2 parents 43d70af + 728e12b commit 8b8b358
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Orange/data/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def __new__(cls, variable, value=Unknown):
:param value: value
"""
if variable.is_primitive():
if isinstance(variable, DiscreteVariable) and isinstance(value, str):
value = variable.to_val(value)
self = super().__new__(cls, value)
self.variable = variable
self._value = None
Expand Down
3 changes: 3 additions & 0 deletions Orange/tests/sql/test_sql_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def test_query_subset_of_rows(self):
def test_getitem_single_value(self):
table = SqlTable(self.conn, self.iris, inspect_values=True)
self.assertAlmostEqual(table[0, 0], 5.1)
self.assertAlmostEqual(table[0, table.domain[0]], 5.1)
self.assertEqual(table[0, 4], "Iris-setosa")
self.assertEqual(table[0, table.domain[4]], "Iris-setosa")

@dbt.run_on(["postgres", "mssql"])
def test_type_hints(self):
Expand Down

0 comments on commit 8b8b358

Please sign in to comment.