Skip to content

Commit

Permalink
- fixes an issue with restoring original headers
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Jun 28, 2022
1 parent dcf4526 commit 3abcf52
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions basico/task_parameterestimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,16 @@ def get_data_from_experiment(experiment, **kwargs):
"""
experiment = get_experiment(experiment, **kwargs)
experiment_file = _get_experiment_file(experiment)
with open(experiment_file) as f:
num_lines = sum(1 for _ in f)
header_row = experiment.getHeaderRow()
original_headers = None
num_lines = 0
separator = experiment.getSeparator()
with open(experiment_file, encoding='utf-8') as f:
for line in f:
num_lines +=1
if num_lines == header_row:
original_headers = line.strip().split(separator)
original_headers = dict(enumerate(original_headers))
have_headers = header_row < num_lines
skip_idx = [x-1 for x in range(1, num_lines+1) if
not (experiment.getFirstRow() <= x <= experiment.getLastRow())]
Expand Down Expand Up @@ -395,12 +402,19 @@ def get_data_from_experiment(experiment, **kwargs):

if rename_headers or not have_headers:
df = pandas.read_csv(experiment_file,
sep=experiment.getSeparator(),
sep=separator,
header=None,
skiprows=skip_idx)
elif original_headers != None and not rename_headers:
df = pandas.read_csv(experiment_file,
sep=separator,
header=None,
skiprows=skip_idx)
df.rename(columns=original_headers, inplace=True)
return df
else:
df = pandas.read_csv(experiment_file,
sep=experiment.getSeparator(),
sep=separator,
skiprows=skip_idx)

if not rename_headers:
Expand Down

0 comments on commit 3abcf52

Please sign in to comment.