Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Limit tabular pipeline to local CSV files, closes #1119

davidmezzetti89d5207b6e3b
diff --git a/src/python/txtai/pipeline/data/tabular.py b/src/python/txtai/pipeline/data/tabular.py
index 54da281a..277949dd 100644
--- a/src/python/txtai/pipeline/data/tabular.py
+++ b/src/python/txtai/pipeline/data/tabular.py
@@ -56,15 +56,16 @@ class Tabular(Pipeline):
dicts = []
for item in items:
- # File path
+ # Local CSV file
if isinstance(item, str):
_, extension = os.path.splitext(item)
extension = extension.replace(".", "").lower()
- if extension == "csv":
+ if extension == "csv" and os.path.exists(item):
df = pd.read_csv(item)
-
- results.append(self.process(df))
+ results.append(self.process(df))
+ else:
+ raise ValueError(f"Invalid local file path or file not found: {item}")
# Dict
if isinstance(item, dict):
diff --git a/test/python/testpipeline/testdata/testtabular.py b/test/python/testpipeline/testdata/testtabular.py
index f65dee05..2d70d555 100644
--- a/test/python/testpipeline/testdata/testtabular.py
+++ b/test/python/testpipeline/testdata/testtabular.py
@@ -73,6 +73,17 @@ class TestTabular(unittest.TestCase):
self.assertEqual(uid, 0)
self.assertEqual(text, "This is a test")
+ def testInvalid(self):
+ """
+ Test invalid file paths
+ """
+
+ with self.assertRaises(ValueError):
+ self.tabular([Utils.PATH + "/article.pdf"])
+
+ with self.assertRaises(ValueError):
+ self.tabular(["https://invalid.path"])
+
def testList(self):
"""
Test parsing a list