Skip to content

Commit 5a3f9be

Browse files
authored
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.
1 parent bcc18c5 commit 5a3f9be

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ sbpy.activity.gas
2525
- Replaced calls to the deprecated function `scipy.integrate.romberg` with
2626
`scipy.integrate.quad`. [#412]
2727

28+
sbpy.names
29+
^^^^^^^^^^
30+
- Fixed `sbpy.Names.to_packed()' to raise an error in cases of invalid
31+
cometary designations with fragment specifiers (e.g., "2024 A-A" and
32+
"2024 A-AA" now correctly raise TargetNameParseError exceptions) [#417]
33+
2834

2935
0.5.0 (2024-08-28)
3036
==================

sbpy/data/names.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ def to_packed(s):
130130
):
131131
if s[-2] == '-':
132132
frag = s[-1]
133-
num = s[6:-2]
133+
if len(s[:-2]) > 6:
134+
num = s[6:-2]
135+
else:
136+
raise TargetNameParseError(
137+
('{} cannot be turned into a '
138+
'packed designation').format(s))
134139
else:
135140
frag = '0'
136141
num = s[6:]

sbpy/data/tests/test_names.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ def test_parse_comet():
238238
with pytest.raises(TargetNameParseError):
239239
Names.parse_comet('2001 a2')
240240

241+
with pytest.raises(TargetNameParseError):
242+
Names.parse_comet('2024 A-A')
243+
244+
with pytest.raises(TargetNameParseError):
245+
Names.parse_comet('2024 A')
246+
241247

242248
def test_parse_asteroid():
243249
"""Test asteroid name parsing."""

0 commit comments

Comments
 (0)