in src/loading_manifest/common_manifest.py [0:0]
def csv_colname_to_colindex(csv_file, colnames, expected_colindex, encoding='utf-8-sig'):
colindex = list()
firstrow = list()
with open(csv_file, mode='r', encoding=encoding) as infile:
reader = csv.reader(infile)
for rows in reader:
for colname in rows:
firstrow.append(colname.strip().upper())
break
for colname in colnames:
try:
index = firstrow.index(colname.strip().upper())
except ValueError:
index = -1
colindex.append(index)
t_colindex = tuple(colindex)
if expected_colindex is not None and len(expected_colindex) > 0:
if t_colindex != tuple(expected_colindex):
logging.warning("Index in csv file is not as expected. Please double check.")
logging.warning(" Columns: %s", colnames)
logging.warning(" Indices: %s", t_colindex)
logging.warning(" Expected: %s", tuple(expected_colindex))
return t_colindex