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:
bogdankostic 2023-02-20 17:37:35 +01:00 committed by GitHub
parent 30cdb81f19
commit 18e7b8399b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 28 deletions

View File

@ -1,6 +1,5 @@
from __future__ import annotations
import csv
import warnings
import hashlib
import inspect
@ -178,9 +177,7 @@ class Document:
return _doc
@classmethod
def from_dict(
cls, dict: Dict[str, Any], field_map: Optional[Dict[str, Any]] = None, id_hash_keys: Optional[List[str]] = None
) -> Document:
def from_dict(cls, dict: Dict[str, Any], field_map: Optional[Dict[str, Any]] = None) -> Document:
"""
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
@ -198,15 +195,6 @@ class Document:
"""
if not 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()
init_args = ["content", "content_type", "id", "score", "id_hash_keys", "question", "meta", "embedding"]
@ -310,10 +298,10 @@ class SpeechDocument(Document):
return dictionary
@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:
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"])
return doc

View File

@ -52,19 +52,6 @@ def test_document_from_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():
labels = [
Label(