Conversation
Codecov Report
@@ Coverage Diff @@
## main #205 +/- ##
==========================================
+ Coverage 80.71% 84.59% +3.87%
==========================================
Files 119 119
Lines 5295 5302 +7
==========================================
+ Hits 4274 4485 +211
+ Misses 1021 817 -204
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| return cls.load_json(file, protocol=protocol, encoding=encoding, **kwargs) | ||
| from .... import Document | ||
|
|
||
| json_docs = json.loads(file) |
There was a problem hiding this comment.
are your sure this maps to the type hint?
file: Union[str, bytes, bytearray, TextIO],
either this line or type hint, one of them is wrong
There was a problem hiding this comment.
fixed. Only str, bytes and bytearray are kept while TextIO and str are supported for load_json
docarray/document/mixins/porting.py
Outdated
|
|
||
| return MessageToJson(self.to_protobuf(), **kwargs) | ||
| elif protocol == 'dynamic': | ||
| return json.dumps(self.to_dict(protocol=protocol)) |
There was a problem hiding this comment.
pass the kwargs for json.dumps(.., **kwargs)
There was a problem hiding this comment.
dumping is not supported anymore
docarray/document/mixins/porting.py
Outdated
| elif protocol == 'dynamic': | ||
| warnings.warn( | ||
| f'protocol=`{protocol}` is not supported, ' | ||
| f'the result dict is a Python dynamic typing dict without any promise on the schema.' | ||
| 'The result dict is a Python dynamic typing dict without any promise on the schema.' | ||
| ) | ||
| return dataclasses.asdict(self._data) | ||
| res = dataclasses.asdict(self._data) | ||
| del res['_reference_doc'] | ||
| return res |
There was a problem hiding this comment.
no need, you only need it in load/from
we do not support arbitrary/unschema-ed json dumping
docarray/array/mixins/io/json.py
Outdated
| :param protocol: `jsonschema` or `protobuf` | ||
| :param protocol: `jsonschema`, `protobuf` or `dynamic` |
docarray/document/mixins/porting.py
Outdated
| pb_msg = DocumentProto() | ||
| json_format.ParseDict(obj, pb_msg, **kwargs) | ||
| return cls.from_protobuf(pb_msg) | ||
| elif protocol == 'dynamic': |
There was a problem hiding this comment.
| elif protocol == 'dynamic': | |
| else: |
docarray/document/mixins/porting.py
Outdated
| elif protocol == 'dynamic': | ||
| return cls.from_dict(json.loads(obj), protocol=protocol) | ||
| else: | ||
| raise ValueError(f'protocol=`{protocol}` is not supported') |
There was a problem hiding this comment.
| elif protocol == 'dynamic': | |
| return cls.from_dict(json.loads(obj), protocol=protocol) | |
| else: | |
| raise ValueError(f'protocol=`{protocol}` is not supported') | |
| else: | |
| return cls(json.loads(obj)) |
There was a problem hiding this comment.
done but using return cls.from_dict(json.loads(obj), protocol=protocol)
| ``` | ||
|
|
||
| By default, it uses {ref}`JSON Schema and pydantic model<schema-gen>` for serialization, i.e. `protocol='jsonschema'`. You can switch the method to `protocol='protobuf'`, which leverages Protobuf as the JSON serialization backend. | ||
| By default, it uses {ref}`JSON Schema and pydantic model<schema-gen>` for serialization, i.e. `protocol='jsonschema'`. You can switch the method to `protocol='protobuf'`, which leverages Protobuf as the JSON serialization backend or `protocol='dynamic'` which accepts schemaless Documents. |
There was a problem hiding this comment.
| By default, it uses {ref}`JSON Schema and pydantic model<schema-gen>` for serialization, i.e. `protocol='jsonschema'`. You can switch the method to `protocol='protobuf'`, which leverages Protobuf as the JSON serialization backend or `protocol='dynamic'` which accepts schemaless Documents. | |
| By default, it uses {ref}`JSON Schema and pydantic model<schema-gen>` for serialization, i.e. `protocol='jsonschema'`. You can switch the method to `protocol='protobuf'`, which leverages Protobuf as the JSON serialization backend. | |
| To load an arbitrary JSON file, please set `protocol=None`. But as it is "arbitrary", you should not expect it can be succesfully loaded. DocArray tries its best reasonable effort by first load this JSON into `dict` and then load it via `Document(dict)`. |
|
📝 Docs are deployed on https://ft-fix-json-save-load--jina-docs.netlify.app 🎉 |
No description provided.