From 5a3f9be343867bacb593e2e15517bdc51c657b39 Mon Sep 17 00:00:00 2001 From: hhsieh00 Date: Tue, 12 Nov 2024 04:01:49 -1000 Subject: [PATCH] identify invalid comet designation with fragment (#417) Added code to check to see if comet designation without a fragment is a valid designation or not (e.g., not passing 2024 A-A when 2024 A is not a valid designation). Basically just checks to see if the remaining designation without the fragment suffix has enough characters to be turned into a normal packed designation. --- CHANGES.rst | 6 ++++++ sbpy/data/names.py | 7 ++++++- sbpy/data/tests/test_names.py | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index e6d8e67a..f0f11a0f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -25,6 +25,12 @@ sbpy.activity.gas - Replaced calls to the deprecated function `scipy.integrate.romberg` with `scipy.integrate.quad`. [#412] +sbpy.names +^^^^^^^^^^ +- Fixed `sbpy.Names.to_packed()' to raise an error in cases of invalid + cometary designations with fragment specifiers (e.g., "2024 A-A" and + "2024 A-AA" now correctly raise TargetNameParseError exceptions) [#417] + 0.5.0 (2024-08-28) ================== diff --git a/sbpy/data/names.py b/sbpy/data/names.py index 1fcaf918..b37e0238 100644 --- a/sbpy/data/names.py +++ b/sbpy/data/names.py @@ -130,7 +130,12 @@ def to_packed(s): ): if s[-2] == '-': frag = s[-1] - num = s[6:-2] + if len(s[:-2]) > 6: + num = s[6:-2] + else: + raise TargetNameParseError( + ('{} cannot be turned into a ' + 'packed designation').format(s)) else: frag = '0' num = s[6:] diff --git a/sbpy/data/tests/test_names.py b/sbpy/data/tests/test_names.py index bd280467..38d1db3e 100644 --- a/sbpy/data/tests/test_names.py +++ b/sbpy/data/tests/test_names.py @@ -238,6 +238,12 @@ def test_parse_comet(): with pytest.raises(TargetNameParseError): Names.parse_comet('2001 a2') + with pytest.raises(TargetNameParseError): + Names.parse_comet('2024 A-A') + + with pytest.raises(TargetNameParseError): + Names.parse_comet('2024 A') + def test_parse_asteroid(): """Test asteroid name parsing."""