Skip to content

Commit c30b9df

Browse files
authored
Table getters: drop pre-existing table index unless it matches the PEtab format (#262)
1 parent 128da31 commit c30b9df

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

petab/conditions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def get_condition_df(
4040
)
4141

4242
if not isinstance(condition_file.index, pd.RangeIndex):
43-
condition_file.reset_index(inplace=True)
43+
condition_file.reset_index(
44+
drop=condition_file.index.name != CONDITION_ID,
45+
inplace=True,
46+
)
4447

4548
try:
4649
condition_file.set_index([CONDITION_ID], inplace=True)

petab/mapping.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def get_mapping_df(
3636
)
3737

3838
if not isinstance(mapping_file.index, pd.RangeIndex):
39-
mapping_file.reset_index(inplace=True)
39+
mapping_file.reset_index(
40+
drop=mapping_file.index.name != PETAB_ENTITY_ID,
41+
inplace=True,
42+
)
4043

4144
for col in MAPPING_DF_REQUIRED_COLS:
4245
if col not in mapping_file.columns:

petab/observables.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def get_observable_df(
4747
)
4848

4949
if not isinstance(observable_file.index, pd.RangeIndex):
50-
observable_file.reset_index(inplace=True)
50+
observable_file.reset_index(
51+
drop=observable_file.index.name != OBSERVABLE_ID,
52+
inplace=True,
53+
)
5154

5255
try:
5356
observable_file.set_index([OBSERVABLE_ID], inplace=True)

petab/parameters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ def get_parameter_df(
8282
)
8383

8484
if not isinstance(parameter_df.index, pd.RangeIndex):
85-
parameter_df.reset_index(inplace=True)
85+
parameter_df.reset_index(
86+
drop=parameter_file.index.name != PARAMETER_ID,
87+
inplace=True,
88+
)
8689

8790
try:
8891
parameter_df.set_index([PARAMETER_ID], inplace=True)

0 commit comments

Comments
 (0)