Try to convert the units to the default unit

This commit is contained in:
Lukas Klass 2020-06-08 11:35:48 +02:00
parent 13372c493e
commit 3b337749b7

View File

@ -98,9 +98,12 @@ def readCSV(file: str, units: list = None, format_: str = None) -> Table:
if all([re.search("\\[.+\\]", x) for x in data.colnames]):
# Extract units from headers and apply them on the columns
# noinspection PyArgumentList
units = [u.Unit(re.findall("(?<=\\[).+(?=\\])", x)[0]) for x in data.colnames]
units_header = [u.Unit(re.findall("(?<=\\[).+(?=\\])", x)[0]) for x in data.colnames]
for i in range(len(data.columns)):
data[data.colnames[i]].unit = units[i]
data[data.colnames[i]].unit = units_header[i]
if units is not None and len(units) == len(data.columns):
for i in range(len(data.columns)):
data[data.colnames[i]] = data[data.colnames[i]].to(units[i])
# Use default units
elif units is not None and len(units) == len(data.columns):
for i in range(len(data.columns)):