Skip to content

Commit 7ebbcf5

Browse files
committed
Make mandatory kwarg, propagate exception
1 parent 743f9bb commit 7ebbcf5

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
@@ -245,7 +245,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
245245
self._validate_criteria(**criteria)
246246

247247
# Put coordinates and radius into consistent format
248-
coordinates = commons.parse_coordinates(coordinates, 'icrs')
248+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
249249

250250
# If radius is just a number, assume arcminutes
251251
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
@@ -1256,3 +1256,37 @@ def test_zcut_get_cutouts(patch_post, tmpdir):
12561256
assert isinstance(cutout_list, list)
12571257
assert len(cutout_list) == 1
12581258
assert isinstance(cutout_list[0], fits.HDUList)
1259+
1260+
1261+
################
1262+
# Utils tests #
1263+
################
1264+
1265+
1266+
def test_parse_input_location(patch_post):
1267+
# Test with coordinates
1268+
coord = SkyCoord(23.34086, 60.658, unit="deg")
1269+
loc = mast.utils.parse_input_location(coordinates=coord)
1270+
assert isinstance(loc, SkyCoord)
1271+
assert loc.ra == coord.ra
1272+
assert loc.dec == coord.dec
1273+
1274+
# Test with object name
1275+
obj_coord = SkyCoord(124.531756290083, -68.3129998725044, unit="deg")
1276+
loc = mast.utils.parse_input_location(objectname="TIC 307210830")
1277+
assert isinstance(loc, SkyCoord)
1278+
assert loc.ra == obj_coord.ra
1279+
assert loc.dec == obj_coord.dec
1280+
1281+
# Error if both coordinates and object name are provided
1282+
with pytest.raises(InvalidQueryError, match="Only one of objectname and coordinates may be specified"):
1283+
mast.utils.parse_input_location(coordinates=coord, objectname="M101")
1284+
1285+
# Error if neither coordinates nor object name is provided
1286+
with pytest.raises(InvalidQueryError, match="One of objectname and coordinates must be specified"):
1287+
mast.utils.parse_input_location()
1288+
1289+
# Warn if resolver is specified without an object name
1290+
with pytest.warns(InputWarning, match="Resolver is only used when resolving object names"):
1291+
loc = mast.utils.parse_input_location(coordinates=coord, resolver="SIMBAD")
1292+
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)