Skip to content

Commit

Permalink
Add support for csv files. All existing tests pass.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
josiahjohnston committed Mar 8, 2019
1 parent a660620 commit 02aa13d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion switch_model/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,14 @@ def load_aug(switch_data, optional=False, auto_select=False,
second_line = infile.readline()
file_is_empty = (headers_line == '')
file_has_no_data_rows = (second_line == '')
headers = headers_line.strip().split('\t')
suffix = path.split('.')[-1]
if suffix == 'tab':
separator = '\t'
elif suffix == 'csv':
separator = ','
else:
raise switch_model.utilities.InputError('Unrecognized file type for input file {}'.format(path))
headers = headers_line.strip().split(separator)
# Skip if the file is empty.
if optional and file_is_empty:
return
Expand Down

0 comments on commit 02aa13d

Please sign in to comment.