tskit icon indicating copy to clipboard operation
tskit copied to clipboard

Md null schema

Open hyanwong opened this issue 2 years ago • 3 comments

While thinking with metadata for the tskit poster, I remembered this on the queue. As discussed with @benjeffery - this is mostly a documentation PR, but it also changes behaviour so that str(tskit.MetadataSchema(schema=None)) returns "Null_schema" rather than None, which was pretty confusing, because tskit.MetadataSchema(schema=None) is None always returns False.

hyanwong avatar Mar 02 '23 15:03 hyanwong

Codecov Report

Merging #2720 (c3af8b0) into main (c12f384) will decrease coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2720      +/-   ##
==========================================
- Coverage   94.08%   94.07%   -0.01%     
==========================================
  Files          29       29              
  Lines       28516    28518       +2     
  Branches     1609     1610       +1     
==========================================
+ Hits        26828    26829       +1     
  Misses       1653     1653              
- Partials       35       36       +1     
Flag Coverage Δ
c-tests 92.36% <ø> (ø)
lwt-tests 89.05% <ø> (ø)
python-c-tests 70.89% <100.00%> (+<0.01%) :arrow_up:
python-tests 99.05% <100.00%> (+<0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
python/tskit/metadata.py 99.03% <100.00%> (+<0.01%) :arrow_up:
python/tskit/cli.py 96.18% <0.00%> (-0.77%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c12f384...c3af8b0. Read the comment docs.

codecov[bot] avatar Mar 02 '23 15:03 codecov[bot]

Having looked at https://github.com/tskit-dev/tskit/issues/2126, I wonder if, instead, we should report the str() as MetadataSchema(None), and indeed report all schemas like that? This would fully address #2126

hyanwong avatar Jul 22 '23 11:07 hyanwong

I now think we should use this for the str representation of a schema:

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

What do you think, @benjeffery ? Will this break anything?

hyanwong avatar Jul 22 '23 12:07 hyanwong