Skip to content

Commit 6e66967

Browse files
Make code tolerant to incomplete last line in csv file
1 parent 54503ae commit 6e66967

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

src/auv_nav/parsers/parse_ae2000.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,42 @@ def parse_ae2000(mission: Mission, vehicle: Vehicle, category, ftype, outpath):
102102
"is NaN. Ignoring line and continuing.",
103103
)
104104
continue
105-
datetime = datetime_column[row_index].split(" ")
106-
date = datetime[0].split("/")
105+
datetime_sp = datetime_column[row_index].split(" ")
106+
if len(datetime_sp) < 2:
107+
if row_index != 0 and row_index + 1 == len(datetime_column):
108+
Console.warn(
109+
f"Last row in {filename} is incomplete. Ignoring and continuing."
110+
)
111+
continue
112+
Console.warn(
113+
f"Date-time field in row {row_index + 2} of {filename} is not " # Added 2 to row_index to account for header and 0-indexing
114+
"formatted as expected."
115+
)
116+
date = datetime_sp[0].split("/")
117+
if len(date) < 3:
118+
if row_index != 0 and row_index + 1 == len(datetime_column):
119+
Console.warn(
120+
f"Last row in {filename} is incomplete. Ignoring and continuing."
121+
)
122+
continue
123+
Console.quit(
124+
f"Date field in row {row_index + 2} of {filename} is not formatted as "
125+
"expected."
126+
)
107127
yyyy = int(date[0])
108128
mm = int(date[1])
109129
dd = int(date[2])
110-
timestamp = datetime[1].split(":")
130+
timestamp = datetime_sp[1].split(":")
111131
if len(timestamp) < 3:
132+
if row_index != 0 and row_index + 1 == len(datetime_column):
133+
Console.warn(
134+
f"Last row in {filename} is incomplete. Ignoring and continuing."
135+
)
136+
continue
137+
Console.quit(
138+
f"Time field in row {row_index + 2} of {filename} is not formatted as "
139+
f"expected. Skipping row."
140+
)
112141
continue
113142
hour = int(timestamp[0])
114143
mins = int(timestamp[1])

0 commit comments

Comments
 (0)