Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Variable: Fix Variable.copy for StringVariable and TimeVariable #1589

Merged
merged 1 commit into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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