Skip to content

Commit

Permalink
fix raises for errored csv
Browse files Browse the repository at this point in the history
  • Loading branch information
mpelchat04 committed Oct 7, 2022
1 parent d46abbb commit 7b8eab2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
2 changes: 2 additions & 0 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7b8eab2

Please sign in to comment.