Fix deprecation warning when calling Document.from_dict() (#6267)

This commit is contained in:
Silvano Cerza 2023-11-09 16:50:06 +01:00 committed by GitHub
parent f95937b0ce
commit 73e2843cf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
import io
import hashlib import hashlib
import logging import logging
from dataclasses import asdict, dataclass, field, fields from dataclasses import asdict, dataclass, field, fields
@ -145,7 +146,7 @@ class Document(metaclass=_BackwardCompatible):
`dataframe` and `blob` fields are converted to their original types. `dataframe` and `blob` fields are converted to their original types.
""" """
if (dataframe := data.get("dataframe")) is not None: if (dataframe := data.get("dataframe")) is not None:
data["dataframe"] = pandas.read_json(dataframe) data["dataframe"] = pandas.read_json(io.StringIO(dataframe))
if blob := data.get("blob"): if blob := data.get("blob"):
data["blob"] = ByteStream(data=bytes(blob["data"]), mime_type=blob["mime_type"]) data["blob"] = ByteStream(data=bytes(blob["data"]), mime_type=blob["mime_type"])
return cls(**data) return cls(**data)