Skip to content

Commit

Permalink
#49 fix an issue when using pandas dataframes for setting compartment…
Browse files Browse the repository at this point in the history
… sizes
  • Loading branch information
fbergmann committed Apr 18, 2024
1 parent 4f77af6 commit 92e2ee5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion basico/model_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2897,7 +2897,7 @@ def _set_compartment(compartment, c_model, **kwargs):
_set_expression(compartment, kwargs['expression'], model=c_model.getObjectDataModel())
c_model.setCompileFlag(True)
if 'dimensionality' in kwargs:
compartment.setDimensionality(kwargs['dimensionality'])
compartment.setDimensionality(int(kwargs['dimensionality']))
if 'notes' in kwargs:
compartment.setNotes(kwargs['notes'])
if 'sbml_id' in kwargs:
Expand Down
41 changes: 41 additions & 0 deletions tests/test_basico_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,26 @@ def test_compartment(self):
self.assertEqual(v['type'], 'assignment')
self.assertEqual(v['expression'], 'Time')
self.assertEqual(v['initial_expression'], '')
self.assertEqual(v['dimensionality'], 3)


# change dimensions to two
basico.set_compartment('v', exact=True, dimensionality=2)
v_df = basico.get_compartments('v')
v = basico.as_dict(v_df)
self.assertEqual(v['dimensionality'], 2)

basico.set_compartment('v', exact=True, dimensionality=v['dimensionality'])
basico.set_compartment('v', exact=True, dimensionality=v_df.iloc[0]['dimensionality'])

# apply all recorded changes
basico.set_compartment(exact=True, **v)


basico.remove_compartment('v')
self.assertIsNone(basico.get_compartments('v', exact=True))


def test_global_parameters(self):
basico.add_parameter('p', initial_value=3)
v = basico.get_parameters('p', exact=True)
Expand Down Expand Up @@ -532,5 +549,29 @@ def test_retrieval_from_multiple_models(self):
basico.remove_datamodel(dm1)
basico.remove_datamodel(dm2)

def test_expresssions(self):
dm = basico.new_model(name='Test Model');
basico.add_species('X');
basico.add_species('Y');
basico.add_parameter('a', initial_value=1);

basico.add_parameter('b', initial_value=1);
basico.set_parameters('b', exact=True, expression='{Values[a].InitialValue}/2', status='assignment')
params1 = basico.as_dict(basico.get_parameters(type='assignment'))
basico.set_parameters('b', exact=True, expression='Values[a].InitialValue/2', status='assignment')
params2 = basico.as_dict(basico.get_parameters(type='assignment'))

basico.add_parameter('c', initial_value=1);
basico.set_parameters('c', exact=True, expression='{[X]}+{[Y]}', status='assignment')
params31 = basico.as_dict(basico.get_parameters(type='assignment'))
basico.set_parameters('c', exact=True, expression=' {[X]} + {[Y]}', status='assignment')
params3 = basico.as_dict(basico.get_parameters(type='assignment'))
basico.set_parameters('c', exact=True, expression=' [X] + [Y]', status='assignment')
params4 = basico.as_dict(basico.get_parameters(type='assignment'))
params = basico.as_dict(basico.get_parameters(type='assignment'))


basico.remove_datamodel(dm);

if __name__ == "__main__":
unittest.main()

0 comments on commit 92e2ee5

Please sign in to comment.