From 282419d82ba0d20fa19c46a697cfba81dad33f5f Mon Sep 17 00:00:00 2001 From: Vladimir Blagojevic Date: Thu, 5 Oct 2023 17:55:07 +0200 Subject: [PATCH] feat: Unfreeze Document in Haystack 2.0 (#5974) * Unfreeze document * Remove immutability test --- haystack/preview/dataclasses/document.py | 10 ++++------ test/preview/dataclasses/test_document.py | 17 +++++------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/haystack/preview/dataclasses/document.py b/haystack/preview/dataclasses/document.py index eb0704b867..76c3b78421 100644 --- a/haystack/preview/dataclasses/document.py +++ b/haystack/preview/dataclasses/document.py @@ -1,15 +1,13 @@ -from typing import List, Any, Dict, Optional, Type - -import json import hashlib +import json import logging +from dataclasses import asdict, dataclass, field, fields from pathlib import Path -from dataclasses import dataclass, field, fields, asdict +from typing import Any, Dict, List, Optional, Type import numpy import pandas - logger = logging.getLogger(__name__) @@ -50,7 +48,7 @@ def document_decoder(self, dictionary): return dictionary -@dataclass(frozen=True) +@dataclass class Document: """ Base data class containing some data to be queried. diff --git a/test/preview/dataclasses/test_document.py b/test/preview/dataclasses/test_document.py index f53b146fea..1f2610c849 100644 --- a/test/preview/dataclasses/test_document.py +++ b/test/preview/dataclasses/test_document.py @@ -1,21 +1,14 @@ -from pathlib import Path import dataclasses -import textwrap import json +import textwrap +from pathlib import Path -import pytest -import pandas as pd import numpy as np +import pandas as pd +import pytest from haystack.preview import Document -from haystack.preview.dataclasses.document import DocumentEncoder, DocumentDecoder - - -@pytest.mark.unit -def test_document_is_immutable(): - doc = Document(text="test text") - with pytest.raises(dataclasses.FrozenInstanceError): - doc.text = "won't work" +from haystack.preview.dataclasses.document import DocumentDecoder, DocumentEncoder @pytest.mark.unit