Skip to content

Commit

Permalink
Domain: Add copy method
Browse files Browse the repository at this point in the history
  • Loading branch information
nikicc committed Nov 3, 2017
1 parent 9225e8d commit fa91921
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Orange/data/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ def _compute_col_indices(self, col_idx):
def checksum(self):
return hash(self)

def copy(self):
return Domain(
attributes=[a.make_proxy() for a in self.attributes],
class_vars=[a.make_proxy() for a in self.class_vars],
metas=[a.make_proxy() for a in self.metas],
source=self,
)

def __eq__(self, other):
if not isinstance(other, Domain):
return False
Expand Down
11 changes: 11 additions & 0 deletions Orange/tests/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,17 @@ def test_domain_conversion_is_fast_enough(self):

self.assertLessEqual(time() - start, 1)

def test_copy(self):
attributes = (age, gender, income)
new_attributes = (age, )

domain = Domain(attributes, [race], [ssn])

new_domain = domain.copy()
new_domain.attributes = new_attributes

self.assertEqual(domain.attributes, attributes)


class TestDomainFilter(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit fa91921

Please sign in to comment.