From cd38b82755fb4a2c95b7449ef7e272d8d4a9095b Mon Sep 17 00:00:00 2001 From: nikicc Date: Tue, 13 Jun 2017 09:39:59 +0200 Subject: [PATCH 1/2] Table.from_table: Use given domain instance when domains match This ensures that after one calls data.transform(domain) the domain of the resulting data is set to the instance that was passed to transform. --- Orange/data/table.py | 5 ++++- Orange/tests/test_table.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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..c1237ae65e2 100644 --- a/Orange/tests/test_table.py +++ b/Orange/tests/test_table.py @@ -1,6 +1,7 @@ # Test methods with long descriptive names can omit docstrings # pylint: disable=missing-docstring +import copy import os import unittest from itertools import chain @@ -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) From d3adc47e0b0370dcfa9539c4e6ba16c3adf0829e Mon Sep 17 00:00:00 2001 From: nikicc Date: Fri, 7 Jul 2017 14:18:12 +0200 Subject: [PATCH 2/2] test_table: Optimize imports --- Orange/tests/test_table.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Orange/tests/test_table.py b/Orange/tests/test_table.py index c1237ae65e2..82398326f74 100644 --- a/Orange/tests/test_table.py +++ b/Orange/tests/test_table.py @@ -3,14 +3,14 @@ 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,