mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-11-01 18:29:32 +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.
|
||||
"""
|
||||
|
||||
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.")
|
||||
|
||||
split_docs = []
|
||||
for doc in documents:
|
||||
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
|
||||
def test_empty_list(self):
|
||||
with pytest.raises(TypeError, match="TextDocumentSplitter expects a List of Documents as input."):
|
||||
splitter = TextDocumentSplitter()
|
||||
splitter.run(documents=[])
|
||||
splitter = TextDocumentSplitter()
|
||||
res = splitter.run(documents=[])
|
||||
assert res == {"documents": []}
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_unsupported_split_by(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user