Skip to content

Commit 4f27027

Browse files
committed
add support to Row in locate_data
1 parent 6b4bd04 commit 4f27027

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Service fixes and enhancements
1717
heasarc
1818
^^^^^^^
1919

20-
- Add support for astropy.table.Row in Heasarc.download_data. [#3270]
20+
- Add support for astropy.table.Row in Heasarc.download_data and Heasarc.locate_data. [#3270]
2121

2222

2323
Infrastructure, Utility and Other Changes and Additions

astroquery/heasarc/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def locate_data(self, query_result=None, catalog_name=None):
470470
471471
Parameters
472472
----------
473-
query_result : `astropy.table.Table`, optional
473+
query_result : `astropy.table.Table` or `astropy.table.Row`, optional
474474
A table that contain the search results. Typically as
475475
returned by query_region. If None, use the table from the
476476
most recent query_region call.
@@ -492,8 +492,14 @@ def locate_data(self, query_result=None, catalog_name=None):
492492
else:
493493
query_result = self._last_result
494494

495+
if isinstance(query_result, Row):
496+
query_result = query_result.table[[query_result.index]]
497+
495498
if not isinstance(query_result, Table):
496-
raise TypeError('query_result need to be an astropy.table.Table')
499+
raise TypeError(
500+
'query_result need to be an astropy.table.Table or '
501+
'astropy.table.Row'
502+
)
497503

498504
# make sure we have a column __row
499505
if '__row' not in query_result.colnames:

astroquery/heasarc/tests/test_heasarc.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,28 @@ def test_locate_data():
274274
Heasarc.locate_data()
275275

276276
with pytest.raises(
277-
TypeError, match="query_result need to be an astropy.table.Table"
277+
TypeError, match=(
278+
"query_result need to be an astropy.table.Table or astropy.table.Row"
279+
)
278280
):
279281
Heasarc.locate_data([1, 2])
280282

281283
with pytest.raises(ValueError, match="No __row column found"):
282284
Heasarc.locate_data(Table({"id": [1, 2, 3.0]}), catalog_name="xray")
283285

284286

287+
def test_locate_data_row():
288+
table = Table({"id": [1, 2, 3.0]})
289+
290+
# we cannot do full call as this is not remote,
291+
# but if we check that we error on __row not input type
292+
with pytest.raises(ValueError, match="No __row column found"):
293+
Heasarc.locate_data(table[0], catalog_name="xray")
294+
295+
with pytest.raises(ValueError, match="No __row column found"):
296+
Heasarc.locate_data(table[0:2], catalog_name="xray")
297+
298+
285299
def test_download_data__empty():
286300
with pytest.raises(ValueError, match="Input links table is empty"):
287301
Heasarc.download_data(Table())

0 commit comments

Comments
 (0)