Skip to content

Commit 154168f

Browse files
committed
Fix metadata schemas on assert_equals
1 parent ce09b35 commit 154168f

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

python/CHANGELOG.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
- Add ``TreeSequence.mutations_edge`` which returns the edge ID for each mutation's
2020
edge. (:user:`benjeffery`, :pr:`3226`, :issue:`3189`)
2121

22-
2322
**Bugfixes**
2423

2524
- Fix bug in ``TreeSequence.pair_coalescence_counts`` when ``span_normalise=True``
2625
and a window breakpoint falls within an internal missing interval.
2726
(:user:`nspope`, :pr:`3176`, :issue:`3175`)
2827

28+
- Fix metadata schemas that are equal but have different byte representations not being equal
29+
when using ``TableCollection.assert_equals`` and ``Table.assert_equals``.
30+
(:user:`benjeffery`, :pr:`3246`, :issue:`3244`)
31+
2932
**Breaking changes**
3033

3134
- ``ltrim``, ``rtrim``, ``trim`` and ``shift`` raise an error if used on a tree sequence

python/tests/test_tables.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,21 @@ def test_metadata_schema(self, table_5row):
14011401
table_5row.assert_equals(table2)
14021402
table_5row.assert_equals(table2, ignore_metadata=True)
14031403

1404+
def test_degenerate_metadata_schema(self, table_5row):
1405+
if hasattr(table_5row, "metadata_schema"):
1406+
table_5row.clear()
1407+
table1 = table_5row.copy()
1408+
table2 = table_5row.copy()
1409+
table1.ll_table.metadata_schema = (
1410+
'{"codec": "json", "properties": '
1411+
'{"A": {"type": "integer"}, "B": {"type": "number"}}}'
1412+
)
1413+
table2.ll_table.metadata_schema = (
1414+
'{"codec": "json", "properties": '
1415+
'{"B": {"type": "number"}, "A": {"type": "integer"}}}'
1416+
)
1417+
table1.assert_equals(table2)
1418+
14041419
def test_row_changes(self, table_5row, test_rows):
14051420
for column_name in test_rows[0].keys():
14061421
table2 = self.table_class()
@@ -4217,6 +4232,17 @@ def test_ignore_reference_sequence(self, t1, t2):
42174232
t1.assert_equals(t2)
42184233
t1.assert_equals(t2, ignore_reference_sequence=True)
42194234

4235+
def test_degenerate_metadata_schema(self, t1, t2):
4236+
t1._ll_object.metadata_schema = (
4237+
'{"codec": "json", "properties": '
4238+
'{"A": {"type": "integer"}, "B": {"type": "number"}}}'
4239+
)
4240+
t2._ll_object.metadata_schema = (
4241+
'{"codec": "json", "properties": '
4242+
'{"B": {"type": "number"}, "A": {"type": "integer"}}}'
4243+
)
4244+
t1.assert_equals(t2)
4245+
42204246

42214247
class TestTableCollectionMethodSignatures:
42224248
tc = msprime.simulate(10, random_seed=1234).dump_tables()

python/tskit/tables.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,18 @@ def assert_equals(self, other, *, ignore_metadata=False):
462462
f"other={other.num_rows}"
463463
)
464464

465+
# We can reach this point if the metadata schemas byte representations
466+
# differ when the decoded schema is the same
467+
if (
468+
not ignore_metadata
469+
and self.ll_table.metadata_schema != other.ll_table.metadata_schema
470+
and self.metadata_schema == other.metadata_schema
471+
):
472+
return
473+
465474
raise AssertionError(
466475
"Tables differ in an undetected way - "
467-
"this is a bug, please report an issue on gitub"
476+
"this is a bug, please report an issue on github"
468477
) # pragma: no cover
469478

470479
def __eq__(self, other):
@@ -2411,7 +2420,7 @@ def assert_equals(self, other, *, ignore_timestamps=False):
24112420

24122421
raise AssertionError(
24132422
"Tables differ in an undetected way - "
2414-
"this is a bug, please report an issue on gitub"
2423+
"this is a bug, please report an issue on github"
24152424
) # pragma: no cover
24162425

24172426
def add_row(self, record, timestamp=None):
@@ -3277,9 +3286,18 @@ def assert_equals(
32773286
other.provenances, ignore_timestamps=ignore_timestamps
32783287
)
32793288

3289+
# We can reach this point if the metadata schemas byte representations
3290+
# differ when the decoded schema is the same
3291+
if (
3292+
not ignore_metadata
3293+
and self._ll_object.metadata_schema != other._ll_object.metadata_schema
3294+
and self.metadata_schema == other.metadata_schema
3295+
):
3296+
return
3297+
32803298
raise AssertionError(
32813299
"TableCollections differ in an undetected way - "
3282-
"this is a bug, please report an issue on gitub"
3300+
"this is a bug, please report an issue on github"
32833301
) # pragma: no cover
32843302

32853303
def __eq__(self, other):

0 commit comments

Comments
 (0)