diff --git a/openpnm/io/_csv.py b/openpnm/io/_csv.py index de78bc8108..d045aa943d 100644 --- a/openpnm/io/_csv.py +++ b/openpnm/io/_csv.py @@ -1,7 +1,7 @@ import re import numpy as np -from pandas import read_table +from pandas import read_csv from openpnm.io import _parse_filename from openpnm.io._pandas import network_to_pandas, project_to_pandas @@ -44,12 +44,11 @@ def network_from_csv(filename): from openpnm.network import Network fname = _parse_filename(filename=filename, ext='csv') - a = read_table(filepath_or_buffer=fname, - sep=',', - skipinitialspace=True, - index_col=False, - true_values=['T', 't', 'True', 'true', 'TRUE'], - false_values=['F', 'f', 'False', 'false', 'FALSE']) + a = read_csv(filepath_or_buffer=fname, + sep=',', + skipinitialspace=True, + header=0, + low_memory=False) # First parse through all the items and re-merge columns dct = {} @@ -87,6 +86,15 @@ def network_from_csv(filename): if k.startswith('throat.'): dct[k] = v[:Nt, ...] + # This is a fix for pandas loading in all data types as dtype('O') + # if it encounters mixed types in the file. For whatever reason + # the conversion to type 'float64' works without problem, however for + # boolean values, the dtype 'O' persists. That can lead to difficult + # to debug errors later on. Therefore here this fix: + for k, v in dct.items(): + if type(v[0]) is bool: + dct[k] = v.astype(bool) + network = Network() network.update(dct) return network