From 08681f34c1130a515697df7b9115e079e773a3d1 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Sun, 10 Jan 2021 12:46:16 +0000 Subject: [PATCH] fixed some of the cmdline args to change the types --- binarycpython/tests/test_distributions.py | 1 - binarycpython/utils/grid.py | 27 ++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/binarycpython/tests/test_distributions.py b/binarycpython/tests/test_distributions.py index ec9788947..c06fa2e11 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 04759ed7c..0f0e55abe 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 -- GitLab