Skip to content

Commit

Permalink
Unicode-compliant file reading and writing throughout the package.
Browse files Browse the repository at this point in the history
  • Loading branch information
julienmalard committed Apr 30, 2018
1 parent 457e47a commit addf9fd
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 13 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
build/
*.vdf
*.2mdl
.idea/workspace.xml
.idea/*
pysd.egg*
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/pysd.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pysd/py_backend/vensim/table2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def read_tabular(table_file, sheetname='Sheet1'):
if extension in ['xls', 'xlsx']:
table = pd.read_excel(table_file, sheetname=sheetname)
elif extension == 'csv':
table = pd.read_csv(table_file)
table = pd.read_csv(table_file, encoding='UTF-8')
elif extension == 'tab':
table = pd.read_csv(table_file, sep='\t')
table = pd.read_csv(table_file, sep='\t', encoding='UTF-8')
else:
raise ValueError('Unknown file or table type')
else:
Expand Down
8 changes: 4 additions & 4 deletions pysd/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def bounds_test(result, bounds=None, errors='return'):
if bounds.split('.')[-1] in ['xls', 'xlsx']:
bounds = _pd.read_excel(bounds, sheetname='Bounds', index_col='Real Name')
elif bounds.split('.')[-1] == 'csv':
bounds = _pd.read_csv(bounds, index_col='Real Name')
bounds = _pd.read_csv(bounds, index_col='Real Name', encoding='UTF-8')
elif bounds.split('.')[-1] == 'tab':
bounds = _pd.read_csv(bounds, sep='\t', index_col='Real Name')
bounds = _pd.read_csv(bounds, sep='\t', index_col='Real Name', encoding='UTF-8')
else:
raise ValueError('Unknown file type: bounds')
else:
Expand Down Expand Up @@ -328,9 +328,9 @@ def sample_pspace(model, param_list=None, bounds=None, samples=100, seed=None):
if bounds.split('.')[-1] in ['xls', 'xlsx']:
bounds = _pd.read_excel(bounds, sheetname='Bounds', index_col='Real Name')
elif bounds.split('.')[-1] == 'csv':
bounds = _pd.read_csv(bounds, index_col='Real Name')
bounds = _pd.read_csv(bounds, index_col='Real Name', encoding='UTF-8')
elif bounds.split('.')[-1] == 'tab':
bounds = _pd.read_csv(bounds, sep='\t', index_col='Real Name')
bounds = _pd.read_csv(bounds, sep='\t', index_col='Real Name', encoding='UTF-8')
else:
raise ValueError('Unknown file type: bounds')
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TestIntegrationExamples(unittest.TestCase):
''' % {'tests': ''.join(tests)})

with open('integration_test_pysd.py', 'w') as ofile:
with open('integration_test_pysd.py', 'w', encoding='UTF-8') as ofile:
ofile.write(file_string)

print('generated %i integration tests' % len(tests))
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def runner(model_file):

# load canonical output
try:
canon = pd.read_csv(directory + '/output.csv', index_col='Time')
canon = pd.read_csv(directory + '/output.csv', index_col='Time', encoding='UTF-8')
except IOError:
try:
canon = pd.read_table(directory + '/output.tab', index_col='Time')
canon = pd.read_table(directory + '/output.tab', index_col='Time', encoding='UTF-8')
except IOError:
raise IOError('Canonical output file not found')

Expand Down

0 comments on commit addf9fd

Please sign in to comment.