💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Index zero and False values in the tabular pipeline (#1207)
Yash Raj Pandey27542ca64b8e
diff --git a/src/python/txtai/pipeline/data/tabular.py b/src/python/txtai/pipeline/data/tabular.pyindex 277949dd..40ea1c2d 100644--- a/src/python/txtai/pipeline/data/tabular.py+++ b/src/python/txtai/pipeline/data/tabular.py@@ -135,7 +135,7 @@ class Tabular(Pipeline):parts = []for column in columns:column = self.column(row[column])- if column:+ if column is not None and column != "":parts.append(str(column))return ". ".join(parts) if parts else Nonediff --git a/test/python/testpipeline/testdata/testtabular.py b/test/python/testpipeline/testdata/testtabular.pyindex 2d70d555..d08eda2b 100644--- a/test/python/testpipeline/testdata/testtabular.py+++ b/test/python/testpipeline/testdata/testtabular.py@@ -23,6 +23,36 @@ class TestTabular(unittest.TestCase):cls.tabular = Tabular("id", ["text"])+ def testFalsyValues(self):+ """+ Test that zero and False are indexed as content+ """++ tabular = Tabular("id", ["quantity", "text"])++ # A quantity of 0 is real data. Before this was fixed, the truthy check in concat+ # dropped it and the row indexed as "Widget", losing the quantity.+ rows = tabular([{"id": 1, "quantity": 0, "text": "Widget"}])+ self.assertEqual(rows[0][1], "0. Widget")++ rows = tabular([{"id": 2, "quantity": False, "text": "Widget"}])+ self.assertEqual(rows[0][1], "False. Widget")++ def testNullValues(self):+ """+ Test that null and empty values are still skipped+ """++ tabular = Tabular("id", ["quantity", "text"])++ # NaN is the null marker column() normalizes to None, and an empty string adds+ # nothing but a separator. Both stay excluded.+ rows = tabular([{"id": 1, "quantity": float("nan"), "text": "Widget"}])+ self.assertEqual(rows[0][1], "Widget")++ rows = tabular([{"id": 2, "quantity": "", "text": "Widget"}])+ self.assertEqual(rows[0][1], "Widget")+def testContent(self):"""Test parsing additional content