Skip to content

Commit

Permalink
str(null_schema) returns "Null_schema" not None
Browse files Browse the repository at this point in the history
  • Loading branch information
hyanwong committed Mar 2, 2023
1 parent 42e1cbb commit ac33a3f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions python/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
- 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**

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


--------------------
[0.5.4] - 2023-01-13
--------------------
Expand Down
11 changes: 5 additions & 6 deletions python/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,8 @@ 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: self=None "
f"other=OrderedDict([('codec', "
"'json')])",
match=f"{type(table_5row).__name__} metadata schemas differ: "
"self=Null_schema other=OrderedDict([('codec', 'json')])",
):
table_5row.assert_equals(table2)
table_5row.assert_equals(table2, ignore_metadata=True)
Expand Down Expand Up @@ -4032,7 +4031,7 @@ def test_metadata_schema(self, t1, t2):
AssertionError,
match=re.escape(
"Metadata schemas differ: self=OrderedDict([('codec', 'json')]) "
"other=None"
"other=Null_schema"
),
):
t1.assert_equals(t2)
Expand Down Expand Up @@ -4081,7 +4080,7 @@ def test_ignore_metadata(self, t1, t2, table_name):
AssertionError,
match=re.escape(
f"{type(table).__name__} metadata schemas differ: "
f"self=OrderedDict([('codec', 'json')]) other=None"
f"self=OrderedDict([('codec', 'json')]) other=Null_schema"
),
):
t1.assert_equals(t2)
Expand Down Expand Up @@ -4142,7 +4141,7 @@ def test_ignore_reference_sequence(self, t1, t2):
AssertionError,
match=re.escape(
"Metadata schemas differ: "
"self=OrderedDict([('codec', 'json')]) other=None"
"self=OrderedDict([('codec', 'json')]) other=Null_schema"
),
):
t1.assert_equals(t2)
Expand Down
7 changes: 5 additions & 2 deletions python/tskit/metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2020-2022 Tskit Developers
# Copyright (c) 2020-2023 Tskit Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -654,7 +654,10 @@ def __repr__(self) -> str:
return self._string

def __str__(self) -> str:
return pprint.pformat(self._schema)
if self._schema is None:
return "Null_schema"
else:
return pprint.pformat(self._schema)

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

0 comments on commit ac33a3f

Please sign in to comment.