Skip to content

Commit 5eaab68

Browse files
committed
add union tests with empty tables
1 parent ae420ac commit 5eaab68

1 file changed

Lines changed: 40 additions & 10 deletions

File tree

python/tests/test_tables.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,7 +5190,36 @@ def test_split_and_rejoin(self):
51905190
tables1.sort()
51915191
tables1.assert_equals(ts.tables, ignore_provenance=True)
51925192

5193-
def test_add_from_empty(self):
5193+
def test_both_empty(self):
5194+
tables = tskit.TableCollection(sequence_length=1)
5195+
t1 = tables.copy()
5196+
t2 = tables.copy()
5197+
t1.union(t2, node_mapping=np.arange(0), all_edges=True, all_mutations=True)
5198+
t1.assert_equals(tables, ignore_provenance=True)
5199+
5200+
def test_one_empty(self):
5201+
ts = self.get_msprime_example(5, T=2, seed=928)
5202+
tables = ts.dump_tables()
5203+
empty = tskit.TableCollection(sequence_length=tables.sequence_length)
5204+
empty.time_units = tables.time_units
5205+
5206+
# union with empty should be no-op
5207+
tables.union(
5208+
empty, node_mapping=np.arange(0), all_edges=True, all_mutations=True
5209+
)
5210+
tables.assert_equals(ts.dump_tables(), ignore_provenance=True)
5211+
5212+
# empty union with tables should be tables
5213+
empty.union(
5214+
tables,
5215+
node_mapping=np.full(tables.nodes.num_rows, tskit.NULL),
5216+
all_edges=True,
5217+
all_mutations=True,
5218+
check_shared_equality=False,
5219+
)
5220+
empty.assert_equals(tables, ignore_provenance=True)
5221+
5222+
def test_reciprocal_empty(self):
51945223
# reciprocally add mutations from one table and edges from the other
51955224
edges_table = tskit.Tree.generate_comb(6, span=6).tree_sequence.dump_tables()
51965225
muts_table = tskit.TableCollection(sequence_length=6)
@@ -5203,19 +5232,20 @@ def test_add_from_empty(self):
52035232
identity_map = np.arange(len(muts_table.nodes), dtype="int32")
52045233
params = {"node_mapping": identity_map, "check_shared_equality": False}
52055234

5206-
edges_table.union(muts_table, **params, all_edges=True) # null op
5207-
assert len(edges_table.sites) == 0
5208-
assert len(edges_table.mutations) == 0
5209-
edges_table.union(muts_table, **params, all_mutations=True)
5210-
assert len(edges_table.sites) == 6
5211-
assert len(edges_table.mutations) == 3
5235+
test_table = edges_table.copy()
5236+
test_table.union(muts_table, **params, all_edges=True) # null op
5237+
assert len(test_table.sites) == 0
5238+
assert len(test_table.mutations) == 0
5239+
test_table.union(muts_table, **params, all_mutations=True)
5240+
assert test_table.sites == muts_table.sites
5241+
assert test_table.mutations == muts_table.mutations
52125242

52135243
muts_table.union(edges_table, **params, all_mutations=True) # null op
52145244
assert len(muts_table.edges) == 0
5215-
muts_table.union(edges_table, **params, all_edges=True) # null op
5216-
assert len(muts_table.edges) != 0
5245+
muts_table.union(edges_table, **params, all_edges=True)
5246+
assert muts_table.edges == edges_table.edges
52175247

5218-
edges_table.assert_equals(muts_table, ignore_provenance=True)
5248+
muts_table.assert_equals(test_table, ignore_provenance=True)
52195249

52205250

52215251
class TestTableSetitemMetadata:

0 commit comments

Comments
 (0)