@@ -792,6 +792,16 @@ def from_table(cls, domain, source, row_indices=...):
792792 :return: a new table
793793 :rtype: Orange.data.Table
794794 """
795+ if domain is source .domain :
796+ table = cls .from_table_rows (source , row_indices )
797+ # assure resulting domain is the instance passed on input
798+ table .domain = domain
799+ # since sparse flags are not considered when checking for
800+ # domain equality, fix manually.
801+ with table .unlocked_reference ():
802+ table = assure_domain_conversion_sparsity (table , source )
803+ return table
804+
795805 new_cache = _thread_local .conversion_cache is None
796806 try :
797807 if new_cache :
@@ -801,15 +811,6 @@ def from_table(cls, domain, source, row_indices=...):
801811 cached = _idcache_restore (_thread_local .conversion_cache , (domain , source ))
802812 if cached is not None :
803813 return cached
804- if domain is source .domain :
805- table = cls .from_table_rows (source , row_indices )
806- # assure resulting domain is the instance passed on input
807- table .domain = domain
808- # since sparse flags are not considered when checking for
809- # domain equality, fix manually.
810- with table .unlocked_reference ():
811- table = assure_domain_conversion_sparsity (table , source )
812- return table
813814
814815 # avoid boolean indices; also convert to slices if possible
815816 row_indices = _optimize_indices (row_indices , len (source ))
@@ -834,7 +835,9 @@ def from_table(cls, domain, source, row_indices=...):
834835 self .W = source .W [row_indices ]
835836 self .name = getattr (source , 'name' , '' )
836837 self .ids = source .ids [row_indices ]
837- self .attributes = deepcopy (getattr (source , 'attributes' , {}))
838+ self .attributes = getattr (source , 'attributes' , {})
839+ if new_cache : # only deepcopy attributes for the outermost transformation
840+ self .attributes = deepcopy (self .attributes )
838841 _idcache_save (_thread_local .conversion_cache , (domain , source ), self )
839842 return self
840843 finally :
@@ -879,6 +882,7 @@ def from_table_rows(cls, source, row_indices):
879882 :return: a new table
880883 :rtype: Orange.data.Table
881884 """
885+ is_outermost_transformation = _thread_local .conversion_cache is None
882886 self = cls ()
883887 self .domain = source .domain
884888 with self .unlocked_reference ():
@@ -892,7 +896,9 @@ def from_table_rows(cls, source, row_indices):
892896 self .W = source .W [row_indices ]
893897 self .name = getattr (source , 'name' , '' )
894898 self .ids = source .ids [row_indices ]
895- self .attributes = deepcopy (getattr (source , 'attributes' , {}))
899+ self .attributes = getattr (source , 'attributes' , {})
900+ if is_outermost_transformation :
901+ self .attributes = deepcopy (self .attributes )
896902 return self
897903
898904 @classmethod
0 commit comments