diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d32e817ac0..a07a5e7f8f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -25,3 +25,4 @@ Performance Improvements Bug Fixes --------- +- Fixed a bug in the config layer parsing of PositionD from a string. (#1299) diff --git a/galsim/config/value.py b/galsim/config/value.py index 6672439730..82b9c09ca5 100644 --- a/galsim/config/value.py +++ b/galsim/config/value.py @@ -451,8 +451,9 @@ def _GetPositionValue(param): """Convert a tuple or a string that looks like "a,b" into a galsim.PositionD. """ try: - x = float(param[0]) - y = float(param[1]) + x, y = param + x = float(x) + y = float(y) except (ValueError, TypeError): try: x, y = param.split(',') diff --git a/tests/test_config_value.py b/tests/test_config_value.py index 7b8cf86535..1682882088 100644 --- a/tests/test_config_value.py +++ b/tests/test_config_value.py @@ -1432,6 +1432,7 @@ def test_pos_value(): 'val1' : galsim.PositionD(0.1,0.2), 'val2' : '0.1, 0.2', 'val3' : None, + 'val4' : '123.4, 567.8' 'xy1' : { 'type' : 'XY', 'x' : 1.3, 'y' : 2.4 }, 'ran1' : { 'type' : 'RandomCircle', 'radius' : 3 }, 'ran2' : { 'type' : 'RandomCircle', 'radius' : 1, 'center' : galsim.PositionD(3,7) }, @@ -1487,6 +1488,10 @@ def test_pos_value(): val3 = galsim.config.ParseValue(config,'val3',config, galsim.PositionD)[0] np.testing.assert_equal(val3, None) + val4 = galsim.config.ParseValue(config,'val4',config, galsim.PositionD)[0] + np.testing.assert_almost_equal(val4.x, 123.4) + np.testing.assert_almost_equal(val4.y, 567.8) + xy1 = galsim.config.ParseValue(config,'xy1',config, galsim.PositionD)[0] np.testing.assert_almost_equal(xy1.x, 1.3) np.testing.assert_almost_equal(xy1.y, 2.4) @@ -1594,6 +1599,7 @@ def test_pos_value(): # Finally, these value got changed, so they won't match the original # unless we manually set them back to the original strings. clean_config['val2'] = '0.1, 0.2' + clean_config['val4'] = '123.4, 567.8' clean_config['cur2'] = '@input.val2' clean_config['input']['val2'] = '0.3, 0.4' assert clean_config == orig_config