Skip to content

Commit

Permalink
Merge pull request #1589 from ales-erjavec/variable-copy
Browse files Browse the repository at this point in the history
[FIX] Variable: Fix Variable.copy for StringVariable and TimeVariable
  • Loading branch information
lanzagar committed Sep 23, 2016
2 parents ca2149f + a5c2d26 commit d84aadf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Orange/data/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def __reduce__(self):
return make_variable, (self.__class__, self._compute_value, self.name), self.__dict__

def copy(self, compute_value):
var = Variable(self.name, compute_value)
var = type(self)(self.name, compute_value=compute_value)
var.attributes = dict(self.attributes)
return var

Expand Down Expand Up @@ -524,7 +524,7 @@ def repr_val(self, val):
str_val = repr_val

def copy(self, compute_value=None):
var = ContinuousVariable(self.name, self.number_of_decimals, compute_value)
var = type(self)(self.name, self.number_of_decimals, compute_value)
var.attributes = dict(self.attributes)
return var

Expand Down Expand Up @@ -905,6 +905,12 @@ def __init__(self, *args, **kwargs):
self.have_date = 0
self.have_time = 0

def copy(self, compute_value=None):
copy = super().copy(compute_value=compute_value)
copy.have_date = self.have_date
copy.have_time = self.have_time
return copy

@staticmethod
def _tzre_sub(s, _subtz=re.compile(r'([+-])(\d\d):(\d\d)$').sub):
# Replace +ZZ:ZZ with ISO-compatible +ZZZZ, or strip +0000
Expand Down
1 change: 1 addition & 0 deletions Orange/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_copy_copies_attributes(self):
var.attributes["a"] = "b"
var2 = var.copy(compute_value=None)
self.assertIn("a", var2.attributes)
self.assertIsInstance(var2, type(var))

var2.attributes["a"] = "c"
# Attributes of original value should not change
Expand Down

0 comments on commit d84aadf

Please sign in to comment.