Skip to content

Commit 6e2bb25

Browse files
committed
Fix NAIF ID typos in Most: nafid -> naifid
Fixes astropy#3605. The MOST cgi-bin API expects 'naifid' but the astroquery code had 'nafid' (missing the 'i') in multiple places, causing NAIF ID queries to fail. Confirmed against the IRSA MOST API docs. Changes in astroquery/ipac/irsa/most.py: - _validate_nafid_input_type: fix the dict key checked and the error message - _validate_input: fix the dispatch key and the unrecognized-input error message - get_images and query_object signatures: add obj_naifid parameter, keep obj_nafid as deprecated - get_images and query_object bodies: handle the deprecated 'nafid_input' input_mode and 'obj_nafid' keyword, remapping to the correct names with AstropyDeprecationWarning - qparams dict in query_object: fix the POST key from 'obj_nafid' to 'obj_naifid' Added two tests: - test_naifid_input: verifies the corrected spelling works - test_nafid_deprecation: verifies the deprecated spellings emit AstropyDeprecationWarning
1 parent 44f3749 commit 6e2bb25

3 files changed

Lines changed: 78 additions & 9 deletions

File tree

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ imcce
128128
- Change the URL for SkyBot and Miriade Web Services [#3595]
129129
- Adapted the ``Miriade`` Class to the new outputs of the Web Service [#3595]
130130

131+
ipac.irsa
132+
^^^^^^^^^
133+
134+
- Fix NAIF ID input mode in ``Most``: the parameter and value ``nafid``
135+
were typos; the API expects ``naifid``. Old ``obj_nafid`` keyword and
136+
``"nafid_input"`` ``input_mode`` still work but emit
137+
``AstropyDeprecationWarning``. [#3607]
138+
131139

132140
mast
133141
^^^^

astroquery/ipac/irsa/most.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from astropy.io import votable, fits
99
from astropy.table import Table
10+
from astropy.utils.exceptions import AstropyDeprecationWarning
1011

1112
from astroquery.query import BaseQuery
1213
from astroquery.utils import class_or_instance
@@ -56,8 +57,8 @@ def _validate_nafid_input_type(self, params):
5657
If the input does not have the minimum required parameters set to
5758
an at least truthy value.
5859
"""
59-
if not params.get("obj_nafid", False):
60-
raise ValueError("When input type is 'nafid_input' key 'obj_nafid' is required.")
60+
if not params.get("obj_naifid", False):
61+
raise ValueError("When input type is 'naifid_input' key 'obj_naifid' is required.")
6162

6263
def _validate_mpc_input_type(self, params):
6364
"""
@@ -148,15 +149,15 @@ def _validate_input(self, params):
148149

149150
if input_type == "name_input":
150151
self._validate_name_input_type(params)
151-
elif input_type == "nafid_input":
152+
elif input_type == "naifid_input":
152153
self._validate_nafid_input_type(params)
153154
elif input_type == "mpc_input":
154155
self._validate_mpc_input_type(params)
155156
elif input_type == "manual_input":
156157
self._validate_manual_input_type(params)
157158
else:
158159
raise ValueError(
159-
"Unrecognized 'input_type'. Expected `name_input`, `nafid_input` "
160+
"Unrecognized 'input_type'. Expected `name_input`, `naifid_input` "
160161
f"`mpc_input` or `manual_input`, got {input_type} instead."
161162
)
162163

@@ -230,7 +231,7 @@ def list_catalogs(self):
230231
return catalogs
231232

232233
def get_images(self, catalog="wise_merge", input_mode="name_input", ephem_step=0.25,
233-
obs_begin=None, obs_end=None, obj_name=None, obj_nafid=None, obj_type=None,
234+
obs_begin=None, obs_end=None, obj_name=None, obj_nafid=None, obj_naifid=None, obj_type=None,
234235
mpc_data=None, body_designation=None, epoch=None, eccentricity=None,
235236
inclination=None, arg_perihelion=None, ascend_node=None, semimajor_axis=None,
236237
mean_anomaly=None, perih_dist=None, perih_time=None, get_query_payload=False,
@@ -328,6 +329,22 @@ def get_images(self, catalog="wise_merge", input_mode="name_input", ephem_step=0
328329
images : list
329330
A list of `~astropy.io.fits.HDUList` objects.
330331
"""
332+
# Handle deprecated parameters
333+
if obj_nafid is not None and obj_naifid is None:
334+
warnings.warn(
335+
"'obj_nafid' is deprecated; use 'obj_naifid' instead (the API parameter is 'obj_naifid').",
336+
AstropyDeprecationWarning,
337+
stacklevel=2,
338+
)
339+
obj_naifid = obj_nafid
340+
if input_mode == "nafid_input":
341+
warnings.warn(
342+
"'nafid_input' is deprecated; use 'naifid_input' instead (the API value is 'naifid_input').",
343+
AstropyDeprecationWarning,
344+
stacklevel=2,
345+
)
346+
input_mode = "naifid_input"
347+
331348
# We insist on output_mode being regular so that it executes quicker,
332349
# and we insist on tarballs so the download is quicker. We ignore
333350
# whatever else user provides, but leave the parameters as arguments to
@@ -339,7 +356,7 @@ def get_images(self, catalog="wise_merge", input_mode="name_input", ephem_step=0
339356
obs_end=obs_end,
340357
ephem_step=ephem_step,
341358
obj_name=obj_name,
342-
obj_nafid=obj_nafid,
359+
obj_naifid=obj_naifid,
343360
obj_type=obj_type,
344361
mpc_data=mpc_data,
345362
body_designation=body_designation,
@@ -378,7 +395,7 @@ def get_images(self, catalog="wise_merge", input_mode="name_input", ephem_step=0
378395
@class_or_instance
379396
def query_object(self, catalog="wise_merge", input_mode="name_input", output_mode="Regular",
380397
ephem_step=0.25, with_tarballs=False, obs_begin=None, obs_end=None,
381-
obj_name=None, obj_nafid=None, obj_type=None, mpc_data=None,
398+
obj_name=None, obj_nafid=None, obj_naifid=None, obj_type=None, mpc_data=None,
382399
body_designation=None, epoch=None, eccentricity=None, inclination=None,
383400
arg_perihelion=None, ascend_node=None, semimajor_axis=None, mean_anomaly=None,
384401
perih_dist=None, perih_time=None, get_query_payload=False):
@@ -498,6 +515,22 @@ def query_object(self, catalog="wise_merge", input_mode="name_input", output_mod
498515
in ``"VOTable"`` an `~astropy.io.votable.tree.VOTableFile`. See
499516
module help for more details on the content of these tables.
500517
"""
518+
# Handle deprecated parameters
519+
if obj_nafid is not None and obj_naifid is None:
520+
warnings.warn(
521+
"'obj_nafid' is deprecated; use 'obj_naifid' instead (the API parameter is 'obj_naifid').",
522+
AstropyDeprecationWarning,
523+
stacklevel=2,
524+
)
525+
obj_naifid = obj_nafid
526+
if input_mode == "nafid_input":
527+
warnings.warn(
528+
"'nafid_input' is deprecated; use 'naifid_input' instead (the API value is 'naifid_input').",
529+
AstropyDeprecationWarning,
530+
stacklevel=2,
531+
)
532+
input_mode = "naifid_input"
533+
501534
# This is a map between the keyword names used by the MOST cgi-bin
502535
# service and their more user-friendly names. For example,
503536
# input_type -> input_mode or fits_region_files --> with tarballs
@@ -510,7 +543,7 @@ def query_object(self, catalog="wise_merge", input_mode="name_input", output_mod
510543
"ephem_step": ephem_step,
511544
"fits_region_files": "on" if with_tarballs else "",
512545
"obj_name": obj_name,
513-
"obj_nafid": obj_nafid,
546+
"obj_naifid": obj_naifid,
514547
"obj_type": obj_type,
515548
"mpc_data": mpc_data,
516549
"body_designation": body_designation,

astroquery/ipac/irsa/tests/test_most.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
from astropy.io import votable
88
from astropy.table import Table
9+
from astropy.utils.diff import report_diff_values
10+
from astropy.utils.exceptions import AstropyDeprecationWarning
911
from astroquery.utils.mocks import MockResponse
1012
from astroquery.ipac.irsa import Most
11-
from astropy.utils.diff import report_diff_values
1213

1314

1415
# each MOST query is given a PID and a temporary directory availible publicly
@@ -248,3 +249,30 @@ def test_gator(patch_requests):
248249
tbl = Table.read(data_path("most_gator.tbl"), format="ipac")
249250
silent_stream = io.StringIO()
250251
assert report_diff_values(tbl, response, silent_stream)
252+
253+
254+
def test_naifid_input(patch_requests):
255+
"""NAIF ID input mode works with the correct 'naifid_input' spelling."""
256+
response = Most.query_object(
257+
obj_naifid="606",
258+
input_mode="naifid_input",
259+
output_mode="Brief",
260+
)
261+
assert len(response) > 0
262+
263+
264+
def test_nafid_deprecation(patch_requests):
265+
"""Deprecated 'obj_nafid' and 'nafid_input' emit AstropyDeprecationWarning."""
266+
with pytest.warns(AstropyDeprecationWarning, match="obj_naifid"):
267+
Most.query_object(
268+
obj_nafid="606",
269+
input_mode="naifid_input",
270+
output_mode="Brief",
271+
)
272+
273+
with pytest.warns(AstropyDeprecationWarning, match="naifid_input"):
274+
Most.query_object(
275+
obj_naifid="606",
276+
input_mode="nafid_input",
277+
output_mode="Brief",
278+
)

0 commit comments

Comments
 (0)