diff --git a/haystack/preview/dataclasses/document.py b/haystack/preview/dataclasses/document.py index 3ee8150d5f..3894116bf1 100644 --- a/haystack/preview/dataclasses/document.py +++ b/haystack/preview/dataclasses/document.py @@ -70,17 +70,6 @@ class Document: score: Optional[float] = field(default=None) embedding: Optional[List[float]] = field(default=None, repr=False) - def __str__(self): - fields = [f"mimetype: '{self.mime_type}'"] - if self.text is not None: - fields.append(f"text: '{self.text}'" if len(self.text) < 100 else f"text: '{self.text[:100]}...'") - if self.dataframe is not None: - fields.append(f"dataframe: {self.dataframe.shape}") - if self.blob is not None: - fields.append(f"blob: {len(self.blob)} bytes") - fields_str = ", ".join(fields) - return f"{self.__class__.__name__}(id={self.id}, {fields_str})" - def __eq__(self, other): """ Compares documents for equality. Uses the id to check whether the documents are supposed to be the same. diff --git a/releasenotes/notes/document-str-remove-e8dbfbc2fa709ade.yaml b/releasenotes/notes/document-str-remove-e8dbfbc2fa709ade.yaml new file mode 100644 index 0000000000..64c0318095 --- /dev/null +++ b/releasenotes/notes/document-str-remove-e8dbfbc2fa709ade.yaml @@ -0,0 +1,4 @@ +--- +preview: + - | + Remove `Document.__str__()` diff --git a/test/preview/dataclasses/test_document.py b/test/preview/dataclasses/test_document.py index e43b77fbc8..e3edc324c3 100644 --- a/test/preview/dataclasses/test_document.py +++ b/test/preview/dataclasses/test_document.py @@ -1,7 +1,6 @@ import json from pathlib import Path -import numpy as np import pandas as pd import pytest @@ -9,30 +8,6 @@ from haystack.preview.dataclasses.document import DocumentDecoder, DocumentEncoder -@pytest.mark.unit -@pytest.mark.parametrize( - "doc,doc_str", - [ - (Document(text="test text"), "text: 'test text'"), - ( - Document(dataframe=pd.DataFrame([["John", 25], ["Martha", 34]], columns=["name", "age"])), - "dataframe: (2, 2)", - ), - (Document(blob=bytes("hello, test string".encode("utf-8"))), "blob: 18 bytes"), - ( - Document( - text="test text", - dataframe=pd.DataFrame([["John", 25], ["Martha", 34]], columns=["name", "age"]), - blob=bytes("hello, test string".encode("utf-8")), - ), - "text: 'test text', dataframe: (2, 2), blob: 18 bytes", - ), - ], -) -def test_document_str(doc, doc_str): - assert f"Document(id={doc.id}, mimetype: 'text/plain', {doc_str})" == str(doc) - - @pytest.mark.unit def test_init_document_same_meta_as_main_fields(): """