Skip to content

Commit 02aa13d

Browse files
Add support for csv files. All existing tests pass.
I validated that csv files will work by reformatting & renaming 'fuels.tab' to 'fuels.csv' in the copperplate0 directory, then changing switch_model/energy_sources/properties.py from 'fuels.tab' to 'fuels.csv', and solving the copperplate0 model. That example ran fine with a mix of .tab and .csv input files.
1 parent a660620 commit 02aa13d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

switch_model/utilities.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,14 @@ def load_aug(switch_data, optional=False, auto_select=False,
406406
second_line = infile.readline()
407407
file_is_empty = (headers_line == '')
408408
file_has_no_data_rows = (second_line == '')
409-
headers = headers_line.strip().split('\t')
409+
suffix = path.split('.')[-1]
410+
if suffix == 'tab':
411+
separator = '\t'
412+
elif suffix == 'csv':
413+
separator = ','
414+
else:
415+
raise switch_model.utilities.InputError('Unrecognized file type for input file {}'.format(path))
416+
headers = headers_line.strip().split(separator)
410417
# Skip if the file is empty.
411418
if optional and file_is_empty:
412419
return

0 commit comments

Comments
 (0)