-
Notifications
You must be signed in to change notification settings - Fork 238
The misuse of smart union in pydantic #72
Copy link
Copy link
Closed
Description
The string value "1" in doc.tags will be automatically converted to bool True when using .to_pydantic_model. This would not make sense.
The reproduce script:
from docarray import Document
doc = Document(tags={'a': '1', 'b': 1, 'c': '2'})
print(f'origin:')
print(doc.tags)
pd_doc_tags = doc.to_pydantic_model().tags
print(f'pydantic: ')
print(pd_doc_tags)
proto_tags = doc.to_dict(protocol='protobuf')['tags']
print(f'protobuf: ')
print(proto_tags)
json_tags = doc.to_dict(protocol='jsonschema')['tags']
print(f'jsonschema')
print(proto_tags)yields the following output:
origin:
{'a': '1', 'b': 1, 'c': '2'}
pydantic:
{'a': True, 'b': True, 'c': 2.0}
protobuf:
{'a': '1', 'c': '2', 'b': 1.0}
jsonschema
{'a': '1', 'c': '2', 'b': 1.0}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels