Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
d-v-b opened this issue Mar 18, 2025 · 0 comments
Open

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

d-v-b opened this issue Mar 18, 2025 · 0 comments

Comments

@d-v-b
Copy link
Contributor

d-v-b commented Mar 18, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant