Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Return all rows when Tabular is called with a single dict

michaelkillgta81fee3b62a7a
diff --git a/src/python/txtai/pipeline/data/tabular.py b/src/python/txtai/pipeline/data/tabular.py
index 58a75c7f..5a2fea3e 100644
--- a/src/python/txtai/pipeline/data/tabular.py
+++ b/src/python/txtai/pipeline/data/tabular.py
@@ -78,7 +78,13 @@ class Tabular(Pipeline):
if dicts:
df = pd.DataFrame(dicts)
- results.extend(self.process(df))
+ rows = self.process(df)
+
+ # A single dict input returns all of its rows, same as a single CSV file input
+ if not isinstance(data, list):
+ return rows
+
+ results.extend(rows)
return results[0] if not isinstance(data, list) else results
diff --git a/test/python/testpipeline/testdata/testtabular.py b/test/python/testpipeline/testdata/testtabular.py
index dcd9ac80..4a15a7a3 100644
--- a/test/python/testpipeline/testdata/testtabular.py
+++ b/test/python/testpipeline/testdata/testtabular.py
@@ -73,6 +73,20 @@ class TestTabular(unittest.TestCase):
self.assertEqual(uid, 0)
self.assertEqual(text, "This is a test")
+ def testDictSingle(self):
+ """
+ Test parsing a single dict that is not wrapped in a list
+ """
+
+ row = {"id": 0, "text": "This is a test", "flag": 1}
+
+ # A single dict returns its list of rows, same as a single CSV file
+ self.assertEqual(self.tabular(row), [(0, "This is a test", None)])
+
+ # Content rows must not be dropped
+ tabular = Tabular("id", ["text"], True)
+ self.assertEqual(tabular(row), [(0, "This is a test", None), (0, row, None)])
+
def testFalsyIDColumn(self):
"""
Explicit column labels are used for IDs and excluded from default text.