diff --git a/binarycpython/tests/test_distributions.py b/binarycpython/tests/test_distributions.py index ec9788947fdafb4bceddd330c46e1ef1c1f6c198..c06fa2e11e2850f3b3f6b2a2ec2482fde0330c55 100644 --- a/binarycpython/tests/test_distributions.py +++ b/binarycpython/tests/test_distributions.py @@ -216,7 +216,6 @@ class TestDistributions(unittest.TestCase): # for m=0.5 m = 0.5 -<<<<<<< HEAD self.assertLess(np.abs(imf_chabrier2003(m)-0.581457346702825), self.tolerance, msg="Difference is bigger than the tolerance") # For m = 2 diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 04759ed7cb7254e82dab691e87a68639fc1c6db6..0f0e55abe3ded62f979d291f81524678f5ae16b0 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -225,9 +225,30 @@ class Population: split = cmdline_arg.split("=") parameter = split[0] value = split[1] - - # TODO: convert to correct type here - + old_value_found = False + + # Find an old value + if parameter in self.grid_options: + old_value = self.grid_options[parameter] + old_value_found = True + + elif parameter in self.defaults: + old_value = self.defaults[parameter] + old_value_found = True + + elif parameter in self.custom_options: + old_value = self.custom_options[parameter] + old_value_found = True + + # (attempt to) convert + if old_value_found: + try: + verbose_print("Converting type of {} from {} to {}".format(parameter, type(value), type(old_value)), self.grid_options['verbosity'], 1) + value = type(old_value)(value) + verbose_print("Success!", self.grid_options['verbosity'], 1) + + except ValueError as e: + verbose_print("Tried to convert the given parameter {}/value {} to its correct type {} (from old value {}). But that wasn't possible.".format(parameter, value, type(old_value), old_value), self.grid_options['verbosity'], 0) # Add to dict cmdline_dict[parameter] = value