Skip to content

Commit 873fc23

Browse files
committed
Make mandatory kwarg, propagate exception
1 parent 43c951c commit 873fc23

File tree

7 files changed

+43
-13
lines changed

7 files changed

+43
-13
lines changed

astroquery/mast/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def query_region_async(self, coordinates, *, radius=0.2*u.deg, catalog="Hsc",
204204
"""
205205

206206
# Put coordinates and radius into consistent format
207-
coordinates = commons.parse_coordinates(coordinates, 'icrs')
207+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
208208

209209
# if radius is just a number we assume degrees
210210
radius = coord.Angle(radius, u.deg)

astroquery/mast/missions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
219219
self._validate_criteria(**criteria)
220220

221221
# Put coordinates and radius into consistent format
222-
coordinates = commons.parse_coordinates(coordinates, 'icrs')
222+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
223223

224224
# If radius is just a number, assume arcminutes
225225
radius = coord.Angle(radius, u.arcmin)

astroquery/mast/observations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def query_region_async(self, coordinates, *, radius=0.2*u.deg, pagesize=None, pa
235235
"""
236236

237237
# Put coordinates and radius into consistent format
238-
coordinates = commons.parse_coordinates(coordinates, 'icrs')
238+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
239239

240240
# if radius is just a number we assume degrees
241241
radius = coord.Angle(radius, u.deg)
@@ -364,7 +364,7 @@ def query_region_count(self, coordinates, *, radius=0.2*u.deg, pagesize=None, pa
364364
"""
365365

366366
# build the coordinates string needed by ObservationsClass._caom_filtered_position
367-
coordinates = commons.parse_coordinates(coordinates, 'icrs')
367+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
368368

369369
# if radius is just a number we assume degrees
370370
radius = coord.Angle(radius, u.deg)

astroquery/mast/tests/test_mast.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,3 +1197,37 @@ def test_zcut_get_cutouts(patch_post, tmpdir):
11971197
assert isinstance(cutout_list, list)
11981198
assert len(cutout_list) == 1
11991199
assert isinstance(cutout_list[0], fits.HDUList)
1200+
1201+
1202+
################
1203+
# Utils tests #
1204+
################
1205+
1206+
1207+
def test_parse_input_location(patch_post):
1208+
# Test with coordinates
1209+
coord = SkyCoord(23.34086, 60.658, unit="deg")
1210+
loc = mast.utils.parse_input_location(coordinates=coord)
1211+
assert isinstance(loc, SkyCoord)
1212+
assert loc.ra == coord.ra
1213+
assert loc.dec == coord.dec
1214+
1215+
# Test with object name
1216+
obj_coord = SkyCoord(124.531756290083, -68.3129998725044, unit="deg")
1217+
loc = mast.utils.parse_input_location(objectname="TIC 307210830")
1218+
assert isinstance(loc, SkyCoord)
1219+
assert loc.ra == obj_coord.ra
1220+
assert loc.dec == obj_coord.dec
1221+
1222+
# Error if both coordinates and object name are provided
1223+
with pytest.raises(InvalidQueryError, match="Only one of objectname and coordinates may be specified"):
1224+
mast.utils.parse_input_location(coordinates=coord, objectname="M101")
1225+
1226+
# Error if neither coordinates nor object name is provided
1227+
with pytest.raises(InvalidQueryError, match="One of objectname and coordinates must be specified"):
1228+
mast.utils.parse_input_location()
1229+
1230+
# Warn if resolver is specified without an object name
1231+
with pytest.warns(InputWarning, match="Resolver is only used when resolving object names"):
1232+
loc = mast.utils.parse_input_location(coordinates=coord, resolver="SIMBAD")
1233+
assert isinstance(loc, SkyCoord)

astroquery/mast/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def parse_input_location(*, coordinates=None, objectname=None, resolver=None):
235235

236236
# Parse coordinates, if given
237237
if coordinates:
238-
obj_coord = commons.parse_coordinates(coordinates, 'icrs')
238+
obj_coord = commons.parse_coordinates(coordinates, return_frame='icrs')
239239

240240
return obj_coord
241241

astroquery/utils/commons.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
ASTROPY_LT_7_1_1 = not minversion('astropy', '7.1.1')
4141

4242

43-
def parse_coordinates(coordinates, return_frame=None):
43+
def parse_coordinates(coordinates, *, return_frame=None):
4444
"""
4545
Takes a string or astropy.coordinates object. Checks if the
4646
string is parsable as an `astropy.coordinates`
@@ -100,10 +100,7 @@ def parse_coordinates(coordinates, return_frame=None):
100100

101101
# Convert to requested frame, if given
102102
if return_frame and c.frame.name != return_frame.lower():
103-
try:
104-
c = c.transform_to(return_frame)
105-
except ValueError:
106-
warnings.warn(f"Failed to transform coordinates to requested frame: {return_frame}.", InputWarning)
103+
c = c.transform_to(return_frame)
107104

108105
return c
109106

astroquery/utils/tests/test_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import astropy.utils.data as aud
1616
from astropy.logger import log
1717

18-
from ...exceptions import InputWarning
1918
from ...utils import chunk_read, chunk_report, class_or_instance, commons
2019
from ...utils.process_asyncs import async_to_sync_docstr, async_to_sync
2120
from ...utils.docstr_chompers import remove_sections, prepend_docstr_nosections
@@ -100,8 +99,8 @@ def test_parse_coordinates_return_frame():
10099
assert galactic.frame.name == 'galactic'
101100
assert coords.frame.name == 'icrs'
102101

103-
# Warn if transformation fails
104-
with pytest.warns(InputWarning, match='Failed to transform coordinates'):
102+
# ValueError if transformation fails
103+
with pytest.raises(ValueError):
105104
coords = commons.parse_coordinates(galactic, return_frame='invalid')
106105

107106

0 commit comments

Comments
 (0)