mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-09-26 08:33:51 +00:00
refactor: Remove id_hash_keys
parameter in from_dict
method (#4207)
* Remove id_hash_keys parameter in from_dict method * Remove unused import * Adapt `from_dict` of `SpeechDocument` * Revert "Adapt `from_dict` of `SpeechDocument`" This reverts commit 309cbeb7fbb3094c43be76d9e431db9391913144. * Adapt `from_dict` of `SpeechDocument`
This commit is contained in:
parent
30cdb81f19
commit
18e7b8399b
@ -1,6 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import csv
|
import csv
|
||||||
import warnings
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
@ -178,9 +177,7 @@ class Document:
|
|||||||
return _doc
|
return _doc
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(
|
def from_dict(cls, dict: Dict[str, Any], field_map: Optional[Dict[str, Any]] = None) -> Document:
|
||||||
cls, dict: Dict[str, Any], field_map: Optional[Dict[str, Any]] = None, id_hash_keys: Optional[List[str]] = None
|
|
||||||
) -> Document:
|
|
||||||
"""
|
"""
|
||||||
Create Document from dict. An optional `field_map` parameter can be supplied to adjust for custom names of the keys in the
|
Create Document from dict. An optional `field_map` parameter can be supplied to adjust for custom names of the keys in the
|
||||||
input dict. This way you can work with standardized Document objects in Haystack, but adjust the format that
|
input dict. This way you can work with standardized Document objects in Haystack, but adjust the format that
|
||||||
@ -198,15 +195,6 @@ class Document:
|
|||||||
"""
|
"""
|
||||||
if not field_map:
|
if not field_map:
|
||||||
field_map = {}
|
field_map = {}
|
||||||
if id_hash_keys:
|
|
||||||
warnings.warn(
|
|
||||||
message="Passing id_hash_keys directly is deprecated: Document objects now store such information internally.\n"
|
|
||||||
"Old API: Document.from_dict({'content': 'test', 'meta': {'some': 'value'}}, id_hash_keys=['meta'])\n"
|
|
||||||
"New API: Document.from_dict({'content': 'test', 'meta': {'some': 'value'}, 'id_hash_keys': ['meta']})\n",
|
|
||||||
category=DeprecationWarning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
dict["id_hash_keys"] = id_hash_keys
|
|
||||||
|
|
||||||
_doc = dict.copy()
|
_doc = dict.copy()
|
||||||
init_args = ["content", "content_type", "id", "score", "id_hash_keys", "question", "meta", "embedding"]
|
init_args = ["content", "content_type", "id", "score", "id_hash_keys", "question", "meta", "embedding"]
|
||||||
@ -310,10 +298,10 @@ class SpeechDocument(Document):
|
|||||||
return dictionary
|
return dictionary
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, dict, field_map=None, id_hash_keys=None):
|
def from_dict(cls, dict, field_map=None):
|
||||||
if field_map is None:
|
if field_map is None:
|
||||||
field_map = {}
|
field_map = {}
|
||||||
doc = super().from_dict(dict=dict, field_map=field_map, id_hash_keys=id_hash_keys)
|
doc = super().from_dict(dict=dict, field_map=field_map)
|
||||||
doc.content_audio = Path(dict["content_audio"])
|
doc.content_audio = Path(dict["content_audio"])
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
@ -52,19 +52,6 @@ def test_document_from_dict():
|
|||||||
assert doc == Document.from_dict(doc.to_dict())
|
assert doc == Document.from_dict(doc.to_dict())
|
||||||
|
|
||||||
|
|
||||||
@fail_at_version(1, 15)
|
|
||||||
def test_deprecated_id_hash_keys_in_document_from_dict():
|
|
||||||
doc = Document(
|
|
||||||
content="this is the content of the document", meta={"some": "meta"}, id_hash_keys=["content", "meta"]
|
|
||||||
)
|
|
||||||
# id_hash_keys in Document.from_dict() is deprecated and should be removed.
|
|
||||||
with pytest.warns(DeprecationWarning):
|
|
||||||
assert doc == Document.from_dict(
|
|
||||||
{"content": "this is the content of the document", "meta": {"some": "meta"}},
|
|
||||||
id_hash_keys=["content", "meta"],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_no_answer_label():
|
def test_no_answer_label():
|
||||||
labels = [
|
labels = [
|
||||||
Label(
|
Label(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user