mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
Fix Tabular handling of explicitly selected falsy ID columns (#1332)
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user