diff --git a/Orange/data/table.py b/Orange/data/table.py index 0a44568f8bf..2cb106c8f3e 100644 --- a/Orange/data/table.py +++ b/Orange/data/table.py @@ -349,7 +349,10 @@ def match_type(x): if cached: return cached if domain == source.domain: - return cls.from_table_rows(source, row_indices) + table = cls.from_table_rows(source, row_indices) + # assure resulting domain is the instance passed on input + table.domain = domain + return table if isinstance(row_indices, slice): start, stop, stride = row_indices.indices(source.X.shape[0]) diff --git a/Orange/tests/test_table.py b/Orange/tests/test_table.py index 05eb843f2a4..82398326f74 100644 --- a/Orange/tests/test_table.py +++ b/Orange/tests/test_table.py @@ -1,15 +1,16 @@ # Test methods with long descriptive names can omit docstrings # pylint: disable=missing-docstring +import copy import os +import random import unittest from itertools import chain from math import isnan -import random - from unittest.mock import Mock, MagicMock, patch -import scipy.sparse as sp + import numpy as np +import scipy.sparse as sp from Orange import data from Orange.data import (filter, Unknown, Variable, Table, DiscreteVariable, @@ -1735,6 +1736,12 @@ class MyTableClass(data.Table): self.assertIsNot(table, new_table) self.assertIs(new_table.domain, new_domain) + def test_transform_same_domain(self): + iris = data.Table("iris") + new_domain = copy.copy(iris.domain) + new_data = iris.transform(new_domain) + self.assertIs(new_data.domain, new_domain) + def test_can_copy_table(self): new_table = data.Table.from_table(self.domain, self.table) self.assert_table_with_filter_matches(new_table, self.table)