Skip to content
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

Md null schema #2720

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions python/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
in the presence of non-ancestral material (very rare).
(:user:`petrelharp`, :issue:`2983`, :pr:`1623`)

- Printing ``tskit.MetadataSchema(schema=None)`` now shows ``"Null_schema"`` rather
than ``None``, to avoid confusion (:user:`hyanwong`, :pr:`2720`)

**Features**

- Add ``TreeSequence.extend_haplotypes`` method that extends ancestral haplotypes
Expand Down Expand Up @@ -110,8 +113,7 @@
- Add ``__repr__`` for variants to return a string representation of the raw data
without spewing megabytes of text (:user:`chriscrsmith`, :pr:`2695`, :issue:`2694`)

- Add ``keep_rows`` method to table classes to support efficient in-place
table subsetting (:user:`jeromekelleher`, :pr:`2700`)
**Breaking Changes**

**Bugfixes**

Expand Down
5 changes: 4 additions & 1 deletion python/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ def test_schema_str(self):
"required": ["one", "two"],
"additionalProperties": False,
}
assert str(metadata.MetadataSchema(schema)) == pprint.pformat(schema)
assert (
str(metadata.MetadataSchema(schema))
== f"tskit.MetadataSchema(\n{pprint.pformat(schema)}\n)"
)

def test_register_codec(self):
class TestCodec(metadata.AbstractMetadataCodec):
Expand Down
6 changes: 3 additions & 3 deletions python/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ def test_metadata_schema(self, table_5row):
table2.metadata_schema = tskit.MetadataSchema({"codec": "json"})
with pytest.raises(
AssertionError,
match=f"{type(table_5row).__name__} metadata schemas differ:",
match=f"{type(table_5row).__name__} metadata schemas differ: ",
):
table_5row.assert_equals(table2)
table_5row.assert_equals(table2, ignore_metadata=True)
Expand Down Expand Up @@ -4089,7 +4089,7 @@ def test_metadata_schema(self, t1, t2):
t2.metadata_schema = tskit.MetadataSchema(None)
with pytest.raises(
AssertionError,
match=re.escape("Metadata schemas differ"),
match=re.escape("Metadata schemas differ:"),
):
t1.assert_equals(t2)
t1.assert_equals(t2, ignore_metadata=True)
Expand Down Expand Up @@ -4193,7 +4193,7 @@ def test_ignore_reference_sequence(self, t1, t2):
t2.reference_sequence.clear()
with pytest.raises(
AssertionError,
match=re.escape("Metadata schemas differ"),
match=re.escape("Metadata schemas differ: "),
):
t1.assert_equals(t2)
t1.assert_equals(t2, ignore_reference_sequence=True)
Expand Down
9 changes: 8 additions & 1 deletion python/tskit/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,14 @@ def __repr__(self) -> str:
return self._string

def __str__(self) -> str:
return pprint.pformat(self._schema)
if isinstance(self._schema, collections.OrderedDict):
s = pprint.pformat(dict(self._schema))
else:
s = pprint.pformat(self._schema)
if "\n" in s:
return f"tskit.MetadataSchema(\n{s}\n)"
else:
return f"tskit.MetadataSchema({s})"

def __eq__(self, other) -> bool:
return self._string == other._string
Expand Down
Loading