Skip to content

Commit

Permalink
Refactor: Vectorize Heasarc.query_object_async()'s object arg to acce…
Browse files Browse the repository at this point in the history
…pt iterables of multiple objects
  • Loading branch information
nkphysics committed May 27, 2024
1 parent 25e6521 commit 7824d3d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion astropy_helpers
8 changes: 4 additions & 4 deletions astroquery/heasarc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ def query_object_async(self, object_name, mission, *,
cache=True, get_query_payload=False,
**kwargs):
"""
Query around a specific object within a given mission catalog
Query around a specific objects within a given mission catalog
Parameters
----------
object_name : str
Object to query around. To set search radius use the 'radius'
object_name : str or iterable
Objects to query around. To set search radius use the 'radius'
parameter.
mission : str
Mission table to search from
Expand All @@ -139,7 +139,7 @@ def query_object_async(self, object_name, mission, *,
"""
request_payload = self._args_to_payload(
mission=mission,
entry=object_name,
entry=object_name if isinstance(object_name, str) else "; ".join(object_name),
**kwargs
)

Expand Down
17 changes: 15 additions & 2 deletions astroquery/heasarc/tests/test_heasarc_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from astropy.coordinates import SkyCoord
from astropy import units as u
from astropy.table import unique


@parametrization_local_save_remote
Expand Down Expand Up @@ -83,13 +84,25 @@ def test_mission_cols(self):

def test_query_object_async(self):
mission = 'rosmaster'
object_name = '3c273'
object_names = ['3c273', 'PSR B0531+21']

heasarc = Heasarc()
response = heasarc.query_object_async(object_name, mission=mission)
response = heasarc.query_object_async(object_names, mission=mission)
assert response is not None
assert isinstance(response, (requests.models.Response, MockResponse))

def test_query_object(self):
mission = "nicermastr"
object_names = ("Swift_J1818.0-1607", "SAX_J1808.4-3658")

heasarc = Heasarc()
response = heasarc.query_object(object_name=object_names,
mission=mission)
uresponse = unique(response, keys="NAME")
returned_names = [str(i).replace(" ", "") for i in uresponse["NAME"]]
assert "Swift_J1818.0-1607" in returned_names
assert "SAX_J1808.4-3658" in returned_names

def test_query_region_async(self):
heasarc = Heasarc()
mission = 'rosmaster'
Expand Down
4 changes: 2 additions & 2 deletions astroquery/heasarc/tests/test_heasarc_remote_isdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ def test_mission_cols(self):

def test_query_object_async(self):
mission = 'integral_rev3_scw'
object_name = '3c273'
object_names = ['3c273', "Crab"]

heasarc = Heasarc()
response = heasarc.query_object_async(object_name, mission=mission)
response = heasarc.query_object_async(object_names, mission=mission)
assert response is not None
assert isinstance(response, (requests.models.Response, MockResponse))

Expand Down

0 comments on commit 7824d3d

Please sign in to comment.