diff --git a/Orange/data/variable.py b/Orange/data/variable.py index 89924cfe82b..c87b0c759b4 100644 --- a/Orange/data/variable.py +++ b/Orange/data/variable.py @@ -3,7 +3,6 @@ from math import isnan, floor, sqrt import numpy as np from pickle import PickleError -import copy import collections from datetime import datetime, timedelta, timezone @@ -421,7 +420,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 @@ -518,7 +517,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 @@ -899,6 +898,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_data = 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 diff --git a/Orange/tests/test_variable.py b/Orange/tests/test_variable.py index 7a824aa33dc..099984b857b 100644 --- a/Orange/tests/test_variable.py +++ b/Orange/tests/test_variable.py @@ -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