Skip to content

Commit d26c586

Browse files
committed
add blank table handling for new returns from heasarc
1 parent a867890 commit d26c586

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

astroquery/heasarc/core.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ def _fallback(self, text):
233233

234234
return Table_read(data, hdu=1)
235235

236+
def _blank_table_fallback(self, data):
237+
"""
238+
In late 2022, we started seeing examples where the null result came
239+
back as a FITS file with an ImageHDU and no BinTableHDU.
240+
"""
241+
with fits.open(data) as fh:
242+
comments = fh[1].header['COMMENT']
243+
emptytable = Table()
244+
emptytable.meta['COMMENT'] = comments
245+
warnings.warn(NoResultsWarning("No matching rows were found in the query."))
246+
return emptytable
247+
236248
def _parse_result(self, response, verbose=False):
237249
# if verbose is False then suppress any VOTable related warnings
238250
if not verbose:
@@ -258,6 +270,9 @@ def _parse_result(self, response, verbose=False):
258270
return self._fallback(response.text)
259271
except Exception:
260272
return self._old_w3query_fallback(response.content)
273+
except AttributeError:
274+
return self._blank_table_fallback(data)
275+
261276

262277
def _args_to_payload(self, **kwargs):
263278
"""

0 commit comments

Comments
 (0)