Repository: deepset-ai/haystack

Issue:
DocumentCleaner does not pass along dataframe
**Describe the bug**
DocumentCleaner does not pass along dataframe

https://github.com/deepset-ai/haystack/blob/main/haystack/components/preprocessors/document_cleaner.py
```
      cleaned_docs.append(Document(content=text, meta=deepcopy(doc.meta), id=doc.id if self.keep_id else ""))
```



Discussion:
coveralls: ## Pull Request Test Coverage Report for [Build 12008535867](https://coveralls.io/builds/71034953)


### Details

* **0** of **0**   changed or added relevant lines in **0** files are covered.
* **1** unchanged line in **1** file lost coverage.
* Overall coverage increased (+**0.001%**) to **90.29%**

---


|  Files with Coverage Reduction | New Missed Lines | % |
| :-----|--------------|--: |
| [components/preprocessors/document_cleaner.py](https://coveralls.io/builds/71034953/source?filename=components%2Fpreprocessors%2Fdocument_cleaner.py#L321) | 1 | 98.1% |
<!-- | **Total:** | **1** |  | -->

|  Totals | [![Coverage Status](https://coveralls.io/builds/71034953/badge)](https://coveralls.io/builds/71034953) |
| :-- | --: |
| Change from base [Build 12007957555](https://coveralls.io/builds/71034354): |  0.001% |
| Covered Lines: | 7978 |
| Relevant Lines: | 8836 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/haystack/components/preprocessors/document_cleaner.py b/haystack/components/preprocessors/document_cleaner.py
index d5600613..29e0757c 100644
--- a/haystack/components/preprocessors/document_cleaner.py
+++ b/haystack/components/preprocessors/document_cleaner.py
@@ -38,7 +38,7 @@ class DocumentCleaner:
     ```
     """
 
-    def __init__(
+    def __init__(  # pylint: disable=too-many-positional-arguments
         self,
         remove_empty_lines: bool = True,
         remove_extra_whitespaces: bool = True,
@@ -131,7 +131,17 @@ class DocumentCleaner:
             if self.remove_repeated_substrings:
                 text = self._remove_repeated_substrings(text)
 
-            cleaned_docs.append(Document(content=text, meta=deepcopy(doc.meta), id=doc.id if self.keep_id else ""))
+            clean_doc = Document(
+                id=doc.id if self.keep_id else "",
+                content=text,
+                dataframe=doc.dataframe,
+                blob=doc.blob,
+                meta=deepcopy(doc.meta),
+                score=doc.score,
+                embedding=doc.embedding,
+                sparse_embedding=doc.sparse_embedding,
+            )
+            cleaned_docs.append(clean_doc)
 
         return {"documents": cleaned_docs}
 
diff --git a/releasenotes/notes/fix-document-cleaner-4e18a63fd7dc2bd9.yaml b/releasenotes/notes/fix-document-cleaner-4e18a63fd7dc2bd9.yaml
new file mode 100644
index 00000000..144db126
--- /dev/null
+++ b/releasenotes/notes/fix-document-cleaner-4e18a63fd7dc2bd9.yaml
@@ -0,0 +1,4 @@
+---
+fixes:
+  - |
+    Fix `DocumentCleaner` not preserving all `Document` fields when run


Test patch:
diff --git a/test/components/preprocessors/test_document_cleaner.py b/test/components/preprocessors/test_document_cleaner.py
index 2c84d5b1..5f5633a2 100644
--- a/test/components/preprocessors/test_document_cleaner.py
+++ b/test/components/preprocessors/test_document_cleaner.py
@@ -5,7 +5,9 @@ import logging
 
 import pytest
 
+from pandas import DataFrame
 from haystack import Document
+from haystack.dataclasses import ByteStream, SparseEmbedding
 from haystack.components.preprocessors import DocumentCleaner
 
 
@@ -204,3 +206,33 @@ class TestDocumentCleaner:
         cleaner = DocumentCleaner(ascii_only=True, remove_extra_whitespaces=False, remove_empty_lines=False)
         result = cleaner.run(documents=[Document(content=text)])
         assert result["documents"][0].content == expected_text
+
+    def test_other_document_fields_are_not_lost(self):
+        cleaner = DocumentCleaner(keep_id=True)
+        document = Document(
+            content="This is a text with some words. \n"
+            ""
+            "There is a second sentence. \n"
+            ""
+            "And there is a third sentence.\n",
+            dataframe=DataFrame({"col1": [1], "col2": [2]}),
+            blob=ByteStream.from_string("some_data"),
+            meta={"data": 1},
+            score=0.1,
+            embedding=[0.1, 0.2, 0.3],
+            sparse_embedding=SparseEmbedding([0, 2], [0.1, 0.3]),
+        )
+        res = cleaner.run(documents=[document])
+
+        assert len(res) == 1
+        assert len(res["documents"])
+        assert res["documents"][0].id == document.id
+        assert res["documents"][0].content == (
+            "This is a text with some words. There is a second sentence. And there is a third sentence."
+        )
+        assert res["documents"][0].dataframe.equals(document.dataframe)
+        assert res["documents"][0].blob == document.blob
+        assert res["documents"][0].meta == document.meta
+        assert res["documents"][0].score == document.score
+        assert res["documents"][0].embedding == document.embedding
+        assert res["documents"][0].sparse_embedding == document.sparse_embedding