Skip to content

Commit

Permalink
Table.from_table: refactor: separate cache-independent part
Browse files Browse the repository at this point in the history
  • Loading branch information
markotoplak committed Jul 8, 2024
1 parent c69082b commit ada371e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand Down

0 comments on commit ada371e

Please sign in to comment.