mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-11-18 02:53:42 +00:00
fix: Fix TextDocumentSplitter failing if run with empty list (#6081)
* Fix TextDocumentSplitter failing if run with empty list * Release notes * Simplify check * Enhance test
This commit is contained in:
parent
90ddeba579
commit
ec9f898cd6
@ -44,8 +44,9 @@ class TextDocumentSplitter:
|
|||||||
:return: A list of documents with the split texts.
|
:return: A list of documents with the split texts.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not documents or not isinstance(documents, list) or not isinstance(documents[0], Document):
|
if not isinstance(documents, list) or (documents and not isinstance(documents[0], Document)):
|
||||||
raise TypeError("TextDocumentSplitter expects a List of Documents as input.")
|
raise TypeError("TextDocumentSplitter expects a List of Documents as input.")
|
||||||
|
|
||||||
split_docs = []
|
split_docs = []
|
||||||
for doc in documents:
|
for doc in documents:
|
||||||
if doc.text is None:
|
if doc.text is None:
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
preview:
|
||||||
|
- Fix TextDocumentSplitter failing when run with an empty list
|
||||||
@ -21,9 +21,9 @@ class TestTextDocumentSplitter:
|
|||||||
|
|
||||||
@pytest.mark.unit
|
@pytest.mark.unit
|
||||||
def test_empty_list(self):
|
def test_empty_list(self):
|
||||||
with pytest.raises(TypeError, match="TextDocumentSplitter expects a List of Documents as input."):
|
splitter = TextDocumentSplitter()
|
||||||
splitter = TextDocumentSplitter()
|
res = splitter.run(documents=[])
|
||||||
splitter.run(documents=[])
|
assert res == {"documents": []}
|
||||||
|
|
||||||
@pytest.mark.unit
|
@pytest.mark.unit
|
||||||
def test_unsupported_split_by(self):
|
def test_unsupported_split_by(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user