tskit icon indicating copy to clipboard operation
tskit copied to clipboard

Accessing metadata schema values not obvious

Open hyanwong opened this issue 3 years ago • 3 comments
trafficstars

>>> 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.

hyanwong avatar Feb 08 '22 15:02 hyanwong

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.

jeromekelleher avatar Feb 08 '22 15:02 jeromekelleher

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.

hyanwong avatar Feb 08 '22 15:02 hyanwong

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.

benjeffery avatar Feb 09 '22 16:02 benjeffery