Skip to content

Commit e5235c7

Browse files
authored
Merge pull request #1837 from nandita11/sha-value_error
Add NoResultWarning for empty table in sha
2 parents c3a1366 + cdfa5fc commit e5235c7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ sha
7878

7979
- Change URL to https. [#2108]
8080

81+
- A ``NoResultsWarning`` is now returned when there is return of any empty
82+
table. [#1837]
83+
8184

8285
Infrastructure, Utility and Other Changes and Additions
8386
-------------------------------------------------------

astroquery/sha/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import os
44
import io
55
import requests
6+
import warnings
67
import numpy as np
78
from astropy.table import Table
89
import astropy.io.fits as fits
9-
10+
from ..exceptions import NoResultsWarning
1011

1112
__all__ = ['query', 'save_file', 'get_file']
1213
id_parse = re.compile(r'ID\=(\d+)')
@@ -144,7 +145,12 @@ def parse_line(line, cs=cs):
144145
dtypes = _map_dtypes(type_names, field_widths)
145146
# To table
146147
# transpose data for appropriate table instance handling
147-
table = Table(list(zip(*data)), names=col_names, dtype=dtypes)
148+
149+
if len(data) > 0:
150+
table = Table(list(zip(*data)), names=col_names, dtype=dtypes)
151+
else:
152+
warnings.warn(NoResultsWarning("No matching rows were found in the query."))
153+
table = Table()
148154
return table
149155

150156

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from astropy.table import Table
4+
5+
from astroquery import sha
6+
from astroquery.exceptions import NoResultsWarning
7+
8+
9+
@pytest.mark.remote_data
10+
def test_query_no_results():
11+
# Test for issue #1836
12+
with pytest.warns(NoResultsWarning):
13+
result = sha.query(ra=219.57741, dec=64.171525, size=0.001)
14+
15+
assert isinstance(result, Table)
16+
assert len(result) == 0

0 commit comments

Comments
 (0)