Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Fix Tabular handling of explicitly selected falsy ID columns (#1332)

HuaTNA84aa1c81c77f
diff --git a/src/python/txtai/pipeline/data/tabular.py b/src/python/txtai/pipeline/data/tabular.py
index 0cf5243d..ece0007a 100644
--- a/src/python/txtai/pipeline/data/tabular.py
+++ b/src/python/txtai/pipeline/data/tabular.py
@@ -99,14 +99,14 @@ class Tabular(Pipeline):
columns = self.textcolumns
if not columns:
columns = list(df.columns)
- if self.idcolumn:
+ if self.idcolumn is not None:
columns.remove(self.idcolumn)
# Transform into (id, text, tag) tuples
# Tuple iteration preserves column types instead of coercing each row to one dtype.
for index, values in zip(df.index, df.itertuples(index=False, name=None)):
row = dict(zip(df.columns, values))
- uid = row[self.idcolumn] if self.idcolumn else index
+ uid = row[self.idcolumn] if self.idcolumn is not None else index
uid = uid if uid is not None else index
text = self.concat(row, columns)
diff --git a/test/python/testpipeline/testdata/testtabular.py b/test/python/testpipeline/testdata/testtabular.py
index 040dab56..fc30568b 100644
--- a/test/python/testpipeline/testdata/testtabular.py
+++ b/test/python/testpipeline/testdata/testtabular.py
@@ -157,6 +157,16 @@ class TestTabular(unittest.TestCase):
self.assertIsNone(data["metadata"])
+ def testFalsyIDColumn(self):
+ """
+ Explicit column labels are used for IDs and excluded from default text.
+ """
+
+ for column in ("", 0, "id"):
+ with self.subTest(column=column):
+ rows = Tabular(idcolumn=column)([{column: "doc-7", "text": "hello"}])
+ self.assertEqual(rows, [("doc-7", "hello", None)])
+
def testNoColumns(self):
"""
Test creating text without specifying columns