Skip to content

Commit 4187575

Browse files
benjefferyjeromekelleher
authored andcommitted
Correct assert_equals message when tables differ by content and metadata
1 parent c914b8b commit 4187575

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

python/CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
associated with each individual as a numpy array.
1313
(:user:`benjeffery`, :pr:`3153`)
1414

15+
16+
**Fixes**
17+
18+
- Correct assertion message when tables are compared with metadata ignored.
19+
(:user:`benjeffery`, :pr:`3162`, :issue:`3161`)
20+
1521
--------------------
1622
[0.6.3] - 2025-04-28
1723
--------------------

python/tests/test_tables.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,6 +3758,25 @@ def test_equals_options(self, ts_fixture):
37583758
with pytest.raises(TypeError):
37593759
t1.equals(t2, True)
37603760

3761+
# When two tables differ, check that the right reason is given
3762+
t1 = tskit.TableCollection(sequence_length=1.0)
3763+
t2 = tskit.TableCollection(sequence_length=1.0)
3764+
t1.assert_equals(t2)
3765+
t1.metadata = b""
3766+
t2.metadata = b"abc"
3767+
t1.assert_equals(t2, ignore_ts_metadata=True)
3768+
t1.edges.add_row(0, 1, 0, 1)
3769+
with pytest.raises(AssertionError, match="EdgeTable number of rows"):
3770+
t1.assert_equals(t2, ignore_ts_metadata=True)
3771+
t2.metadata = b""
3772+
t2.edges.add_row(0, 1, 0, 1, metadata=b"abc")
3773+
t1.assert_equals(t2, ignore_metadata=True)
3774+
t1.edges.add_row(0, 1, 0, 1)
3775+
with pytest.raises(AssertionError, match="EdgeTable number of rows"):
3776+
t1.assert_equals(t2, ignore_metadata=True)
3777+
with pytest.raises(AssertionError, match="EdgeTable row 0 differs"):
3778+
t1.assert_equals(t2)
3779+
37613780
def test_sequence_length(self):
37623781
for sequence_length in [0, 1, 100.1234]:
37633782
tables = tskit.TableCollection(sequence_length=sequence_length)

python/tskit/tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3246,7 +3246,7 @@ def assert_equals(
32463246
):
32473247
return
32483248

3249-
if not ignore_metadata or ignore_ts_metadata:
3249+
if not (ignore_metadata or ignore_ts_metadata):
32503250
super().assert_equals(other)
32513251

32523252
if not ignore_reference_sequence:

0 commit comments

Comments
 (0)