From 7b8eab2ba7a22d05997f5f25828457c0547b1d58 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Fri, 7 Oct 2022 11:22:47 -0400 Subject: [PATCH] fix raises for errored csv --- tests/utils/test_utils.py | 2 +- utils/utils.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index 610718ab..c526d68c 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -16,7 +16,7 @@ def test_wrong_seperation(self) -> None: def test_with_header_in_csv(self) -> None: extract_archive(src="tests/data/spacenet.zip") - with pytest.raises(TypeError): + with pytest.raises(ValueError): data = read_csv("tests/tiling/header.csv") ##for row in data: ##aoi = AOI(raster=row['tif'], label=row['gpkg'], split=row['split']) diff --git a/utils/utils.py b/utils/utils.py index 2bc138f6..0995800d 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -318,6 +318,8 @@ def read_csv(csv_file_name: str) -> Dict: row_lengths_set = set() for row in reader: row_lengths_set.update([len(row)]) + if ";" in row[0]: + raise TypeError(f"Elements in rows should be delimited with comma, not semicolon.") if not len(row_lengths_set) == 1: raise ValueError(f"Rows in csv should be of same length. Got rows with length: {row_lengths_set}") row = [str(i) or None for i in row] # replace empty strings to None.