Skip to content

to_dict() -> to_json() for metadata classes #2916

Open
@d-v-b

Description

@d-v-b

Our Metadata ABC defines to_dict and from_dict, and we use these methods to recursively read and write nested metadata documents to and from JSON. This would be fine if every implementation of Metadata serialized to a JSON object, but dtypes are a case where we have a rich in-memory representation that serializes to a simple string. data_type.to_dict() -> str is pretty confusing in this case, since one would expect to_dict to return a dict.

Since Metadata is a dataclass, someone who wants to recursively turn one into a dict can already use dataclasses.asdict. So maybe we should remove from_dict and to_dict, and instead define from_json and to_json, methods that turn a metadata model into a JSON-serializable form. This would make the job of these methods more obvious I think, and remove the confusing situation where to_dict doesn't produce a dict.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions