From 98d84293f4d0f674fe3b33f45107b7bd1f53c667 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Fri, 13 Nov 2026 19:01:16 +0100 Subject: [PATCH 1/2] Skip CSVs with fewer than six columns in folder imports The folder parser sends the rows of every CSV other than _classes.csv as the annotation of the images they name. A table of image metadata in the folder fails every listed image's annotation save, and when it sorts before the folder's annotation CSV it is used in that CSV's place. The server's CSV parser reads boxes only from rows of six or more columns, so the folder parser now reads a CSV as annotations only when it is _classes.csv or has at least six columns, and skips other CSVs with a warning. Co-Authored-By: Claude Opus 5.5 --- roboflow/util/folderparser.py | 14 ++++++++++++++ tests/util/test_folderparser.py | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/roboflow/util/folderparser.py b/roboflow/util/folderparser.py index 047cdaee..32be6bde 100644 --- a/roboflow/util/folderparser.py +++ b/roboflow/util/folderparser.py @@ -290,6 +290,7 @@ def _filterIndividualAnnotations(image, annotation, format, imgRefMap, annotatio def _loadAnnotations(folder, annotations): valid_extensions = {".json", ".csv", ".jsonl"} annotations = [a for a in annotations if a["extension"] in valid_extensions] + annotations = [a for a in annotations if a["extension"] != ".csv" or _is_annotation_csv(folder, a)] for ann in annotations: extension = ann["extension"] if extension == ".json": @@ -309,6 +310,19 @@ def _loadAnnotations(folder, annotations): return annotations +def _is_annotation_csv(folder, ann): + # _classes.csv holds multi-label classification. The rows of any other CSV go to the server, whose CSV + # parser reads boxes only from rows of six or more columns: a narrower CSV, like a table of image metadata, + # holds no annotations. + if ann["name"] == "_classes.csv": + return True + with open(f"{folder}{ann['file']}") as f: + columns = len(f.readline().split(",")) + if columns < 6: + print(f"warning: skipping {ann['file']}: annotation CSVs have at least six columns") + return columns >= 6 + + def _read_jsonl(path): data = [] with open(path) as file: diff --git a/tests/util/test_folderparser.py b/tests/util/test_folderparser.py index 4f9ddb5b..89373b01 100644 --- a/tests/util/test_folderparser.py +++ b/tests/util/test_folderparser.py @@ -1,3 +1,5 @@ +import contextlib +import io import json import os import tempfile @@ -54,6 +56,26 @@ def test_parse_mosquitos_csv(self): expected += "train_10308.jpeg,1058,943,japonicus/koreicus,28,187,908,815\n" assert testImage["annotationfile"]["rawText"] == expected + def test_parse_csv_skips_metadata_csv(self): + # A metadata table lists the same images as the annotation CSV, and sorts before it. + with tempfile.TemporaryDirectory() as tmpdir: + os.makedirs(os.path.join(tmpdir, "train")) + for name in ("a.jpg", "b.jpg"): + open(os.path.join(tmpdir, "train", name), "wb").close() + annotations = "filename,width,height,class,xmin,ymin,xmax,ymax\na.jpg,640,480,cat,10,20,110,220\n" + with open(os.path.join(tmpdir, "train", "_annotations.csv"), "w") as f: + f.write(annotations) + with open(os.path.join(tmpdir, "metadata.csv"), "w") as f: + f.write("filename,split,count,status\na.jpg,train,1,ok\nb.jpg,train,0,ok\n") + + with contextlib.redirect_stdout(io.StringIO()) as stdout: + parsed = folderparser.parsefolder(tmpdir) + + images = {i["file"]: i for i in parsed["images"]} + self.assertEqual(images["/train/a.jpg"]["annotationfile"], {"name": "annotation.csv", "rawText": annotations}) + self.assertIsNone(images["/train/b.jpg"].get("annotationfile")) + self.assertIn("/metadata.csv", stdout.getvalue()) + def test_paligemma_format(self): folder = f"{thisdir}/../datasets/paligemma" parsed = folderparser.parsefolder(folder) From 62d43ee3e73e882fa711ad52f828997c29abe2a9 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Fri, 13 Nov 2026 19:02:13 +0100 Subject: [PATCH 2/2] Add the changelog entry for skipped folder CSVs Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de8e4fd..07fcdb86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,14 @@ All notable changes to this project will be documented in this file. YOLOv10. Existing models remain available for inference, and YOLO dataset formats remain supported ([#572](https://github.com/roboflow/roboflow-python/pull/572)). +### Fixed + +- Folder uploads (`upload_dataset()` and `roboflow image upload `) skip + a CSV with fewer than six columns, such as a table of image metadata, with a + warning. Before, its rows were sent as the annotation of every image they + named, which failed the save, even when the folder's annotation CSV also + listed the image ([#583](https://github.com/roboflow/roboflow-python/pull/583)). + ## 1.7.3 ### Added