1
1
import os
2
2
import re
3
3
import pandas as pd
4
+ from sys import exit
4
5
5
6
# Define the ISO 8601 timestamp regex
6
7
iso_regex = r"^\s*$|^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}$"
@@ -12,7 +13,7 @@ def is_iso8601(timestamp):
12
13
def validate_csv (file_path ):
13
14
"""Check if the CSV file has correct format"""
14
15
try :
15
- df = pd .read_csv (file_path )
16
+ df = pd .read_csv (file_path , skipinitialspace = True , comment = "#" )
16
17
except Exception as e :
17
18
return False , f"Error reading CSV file: { e } "
18
19
@@ -22,9 +23,10 @@ def validate_csv(file_path):
22
23
23
24
# Validate t0 and t1 columns for correct format
24
25
for index , row in df .iterrows ():
25
- if not is_iso8601 (str (row ['t0' ])) or not is_iso8601 (str (row ['t1' ])):
26
- return False , f"Invalid t0/t1 timestamp format in file { file_path } at row { index + 1 } "
27
-
26
+ if str (row ['t0' ]).strip () not in ['' , 'nan' ] and not is_iso8601 (str (row ['t0' ])):
27
+ return False , f"Invalid t0 timestamp format in file { file_path } at row { index + 1 } "
28
+ if str (row ['t1' ]).strip () not in ['' , 'nan' ] and not is_iso8601 (str (row ['t1' ])):
29
+ return False , f"Invalid t1 timestamp format in file { file_path } at row { index + 1 } "
28
30
return True , "Valid CSV file."
29
31
30
32
def validate_folder (folder_path ):
0 commit comments