@@ -589,6 +589,23 @@ def append(self, row):
589589 }
590590 )
591591
592+ def replace_with (self , other ):
593+ # Overwrite the contents of this table with a copy of the other table
594+ params = {}
595+ for column in self .column_names :
596+ try :
597+ params [column ] = getattr (other , column )
598+ except AttributeError :
599+ raise TypeError (
600+ "Replacement table has wrong type: it lacks a {column} column"
601+ )
602+ try :
603+ # Not all tables have a metadata_schema: if they do, encode it with repr
604+ params ["metadata_schema" ] = repr (other .metadata_schema )
605+ except AttributeError :
606+ pass
607+ self .set_columns (** params )
608+
592609 def clear (self ):
593610 """
594611 Deletes all rows in this table.
@@ -2869,6 +2886,10 @@ class TableCollection(metadata.MetadataProvider):
28692886 method.
28702887 """
28712888
2889+ set_err_text = (
2890+ "Cannot set tables in a table collection: use table.replace_with() instead."
2891+ )
2892+
28722893 def __init__ (self , sequence_length = 0 ):
28732894 self ._ll_tables = _tskit .TableCollection (sequence_length )
28742895 super ().__init__ (self ._ll_tables )
@@ -2880,55 +2901,87 @@ def individuals(self) -> IndividualTable:
28802901 """
28812902 return IndividualTable (ll_table = self ._ll_tables .individuals )
28822903
2904+ @individuals .setter
2905+ def individuals (self , value ):
2906+ raise AttributeError (self .set_err_text )
2907+
28832908 @property
28842909 def nodes (self ) -> NodeTable :
28852910 """
28862911 The :ref:`sec_node_table_definition` in this collection.
28872912 """
28882913 return NodeTable (ll_table = self ._ll_tables .nodes )
28892914
2915+ @nodes .setter
2916+ def nodes (self , value ):
2917+ raise AttributeError (self .set_err_text )
2918+
28902919 @property
28912920 def edges (self ) -> EdgeTable :
28922921 """
28932922 The :ref:`sec_edge_table_definition` in this collection.
28942923 """
28952924 return EdgeTable (ll_table = self ._ll_tables .edges )
28962925
2926+ @edges .setter
2927+ def edges (self , value ):
2928+ raise AttributeError (self .set_err_text )
2929+
28972930 @property
28982931 def migrations (self ) -> MigrationTable :
28992932 """
29002933 The :ref:`sec_migration_table_definition` in this collection
29012934 """
29022935 return MigrationTable (ll_table = self ._ll_tables .migrations )
29032936
2937+ @migrations .setter
2938+ def migrations (self , value ):
2939+ raise AttributeError (self .set_err_text )
2940+
29042941 @property
29052942 def sites (self ) -> SiteTable :
29062943 """
29072944 The :ref:`sec_site_table_definition` in this collection.
29082945 """
29092946 return SiteTable (ll_table = self ._ll_tables .sites )
29102947
2948+ @sites .setter
2949+ def sites (self , value ):
2950+ raise AttributeError (self .set_err_text )
2951+
29112952 @property
29122953 def mutations (self ) -> MutationTable :
29132954 """
29142955 The :ref:`sec_mutation_table_definition` in this collection.
29152956 """
29162957 return MutationTable (ll_table = self ._ll_tables .mutations )
29172958
2959+ @mutations .setter
2960+ def mutations (self , value ):
2961+ raise AttributeError (self .set_err_text )
2962+
29182963 @property
29192964 def populations (self ) -> PopulationTable :
29202965 """
29212966 The :ref:`sec_population_table_definition` in this collection.
29222967 """
29232968 return PopulationTable (ll_table = self ._ll_tables .populations )
29242969
2970+ @populations .setter
2971+ def populations (self , value ):
2972+ raise AttributeError (self .set_err_text )
2973+
29252974 @property
29262975 def provenances (self ) -> ProvenanceTable :
29272976 """
29282977 The :ref:`sec_provenance_table_definition` in this collection.
29292978 """
29302979 return ProvenanceTable (ll_table = self ._ll_tables .provenances )
29312980
2981+ @provenances .setter
2982+ def provenances (self , value ):
2983+ raise AttributeError (self .set_err_text )
2984+
29322985 @property
29332986 def indexes (self ) -> TableCollectionIndexes :
29342987 """
0 commit comments