-
Notifications
You must be signed in to change notification settings - Fork 78
Add table.replace_with #2389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add table.replace_with #2389
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -589,6 +589,23 @@ def append(self, row): | |
| } | ||
| ) | ||
|
|
||
| def replace_with(self, other): | ||
| # Overwrite the contents of this table with a copy of the other table | ||
| params = {} | ||
| for column in self.column_names: | ||
| try: | ||
| params[column] = getattr(other, column) | ||
| except AttributeError: | ||
| raise TypeError( | ||
| "Replacement table has wrong type: it lacks a {column} column" | ||
| ) | ||
| try: | ||
| # Not all tables have a metadata_schema: if they do, encode it with repr | ||
| params["metadata_schema"] = repr(other.metadata_schema) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine internally maybe, but it's not a great convention. A well named method would be much clearer to the reader |
||
| except AttributeError: | ||
| pass | ||
| self.set_columns(**params) | ||
|
|
||
| def clear(self): | ||
| """ | ||
| Deletes all rows in this table. | ||
|
|
@@ -2869,6 +2886,10 @@ class TableCollection(metadata.MetadataProvider): | |
| method. | ||
| """ | ||
|
|
||
| set_err_text = ( | ||
| "Cannot set tables in a table collection: use table.replace_with() instead." | ||
| ) | ||
|
|
||
| def __init__(self, sequence_length=0): | ||
| self._ll_tables = _tskit.TableCollection(sequence_length) | ||
| super().__init__(self._ll_tables) | ||
|
|
@@ -2880,55 +2901,87 @@ def individuals(self) -> IndividualTable: | |
| """ | ||
| return IndividualTable(ll_table=self._ll_tables.individuals) | ||
|
|
||
| @individuals.setter | ||
| def individuals(self, value): | ||
| raise AttributeError(self.set_err_text) | ||
|
|
||
| @property | ||
| def nodes(self) -> NodeTable: | ||
| """ | ||
| The :ref:`sec_node_table_definition` in this collection. | ||
| """ | ||
| return NodeTable(ll_table=self._ll_tables.nodes) | ||
|
|
||
| @nodes.setter | ||
| def nodes(self, value): | ||
| raise AttributeError(self.set_err_text) | ||
|
|
||
| @property | ||
| def edges(self) -> EdgeTable: | ||
| """ | ||
| The :ref:`sec_edge_table_definition` in this collection. | ||
| """ | ||
| return EdgeTable(ll_table=self._ll_tables.edges) | ||
|
|
||
| @edges.setter | ||
| def edges(self, value): | ||
| raise AttributeError(self.set_err_text) | ||
|
|
||
| @property | ||
| def migrations(self) -> MigrationTable: | ||
| """ | ||
| The :ref:`sec_migration_table_definition` in this collection | ||
| """ | ||
| return MigrationTable(ll_table=self._ll_tables.migrations) | ||
|
|
||
| @migrations.setter | ||
| def migrations(self, value): | ||
| raise AttributeError(self.set_err_text) | ||
|
|
||
| @property | ||
| def sites(self) -> SiteTable: | ||
| """ | ||
| The :ref:`sec_site_table_definition` in this collection. | ||
| """ | ||
| return SiteTable(ll_table=self._ll_tables.sites) | ||
|
|
||
| @sites.setter | ||
| def sites(self, value): | ||
| raise AttributeError(self.set_err_text) | ||
|
|
||
| @property | ||
| def mutations(self) -> MutationTable: | ||
| """ | ||
| The :ref:`sec_mutation_table_definition` in this collection. | ||
| """ | ||
| return MutationTable(ll_table=self._ll_tables.mutations) | ||
|
|
||
| @mutations.setter | ||
| def mutations(self, value): | ||
| raise AttributeError(self.set_err_text) | ||
|
|
||
| @property | ||
| def populations(self) -> PopulationTable: | ||
| """ | ||
| The :ref:`sec_population_table_definition` in this collection. | ||
| """ | ||
| return PopulationTable(ll_table=self._ll_tables.populations) | ||
|
|
||
| @populations.setter | ||
| def populations(self, value): | ||
| raise AttributeError(self.set_err_text) | ||
|
|
||
| @property | ||
| def provenances(self) -> ProvenanceTable: | ||
| """ | ||
| The :ref:`sec_provenance_table_definition` in this collection. | ||
| """ | ||
| return ProvenanceTable(ll_table=self._ll_tables.provenances) | ||
|
|
||
| @provenances.setter | ||
| def provenances(self, value): | ||
| raise AttributeError(self.set_err_text) | ||
|
|
||
| @property | ||
| def indexes(self) -> TableCollectionIndexes: | ||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.