From ada371e98d470de7699e480659d1382bc71ca4d2 Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Mon, 8 Jul 2024 10:50:49 +0200 Subject: [PATCH] Table.from_table: refactor: separate cache-independent part --- Orange/data/table.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Orange/data/table.py b/Orange/data/table.py index f8454010db0..076c84cd035 100644 --- a/Orange/data/table.py +++ b/Orange/data/table.py @@ -792,6 +792,16 @@ def from_table(cls, domain, source, row_indices=...): :return: a new table :rtype: Orange.data.Table """ + if domain is source.domain: + table = cls.from_table_rows(source, row_indices) + # assure resulting domain is the instance passed on input + table.domain = domain + # since sparse flags are not considered when checking for + # domain equality, fix manually. + with table.unlocked_reference(): + table = assure_domain_conversion_sparsity(table, source) + return table + new_cache = _thread_local.conversion_cache is None try: if new_cache: @@ -801,17 +811,6 @@ def from_table(cls, domain, source, row_indices=...): cached = _idcache_restore(_thread_local.conversion_cache, (domain, source)) if cached is not None: return cached - if domain is source.domain: - table = cls.from_table_rows(source, row_indices) - # assure resulting domain is the instance passed on input - table.domain = domain - # since sparse flags are not considered when checking for - # domain equality, fix manually. - with table.unlocked_reference(): - table = assure_domain_conversion_sparsity(table, source) - if new_cache: # from_table_rows is not outermost: explicitly deepcopy attributes - table.attributes = deepcopy(getattr(source, 'attributes', {})) - return table # avoid boolean indices; also convert to slices if possible row_indices = _optimize_indices(row_indices, len(source))