tskit
tskit copied to clipboard
Accessing metadata schema values not obvious
>>> print(ts.tables.nodes.metadata_schema)
OrderedDict([('codec', 'json')])
>>> ts.tables.nodes.metadata_schema["codec"]
TypeError: 'MetadataSchema' object is not subscriptable
>>> ts.tables.nodes.metadata_schema.asdict()["codec"]
'json'
Having to use .asdict() to get the schema values, when the printed version says it's an OrderedDict is pretty unintuitive, I would say.
In general we need higher level APIs for accessing and modifying metadata schemas - do we have some issues open to track this @benjeffery?
At the moment you have to work directly with the schema attribute on the MetadataSchema, which you treat as a plain dictionary and is interpreted directly as JSON schema.
At the moment you have to work directly with the schema attribute on the MetadataSchema, which you treat as a plain dictionary and is interpreted directly as JSON schema.
So I think it's just a bit confusing that print(ts.tables.nodes.metadata_schema) and print(ts.tables.nodes.metadata_schema.schema) give the same thing. Perhaps the string version of metadata_schema should imply that you need to use .schema to get at the good stuff.
Thanks for spotting this @hyanwong - I've added this to the metadata project. We'll soon take all the metadata issues and plan out a coherent high-level API for the schemas.