Skip to content

Commit a5cea1d

Browse files
authored
Merge pull request #2611 from bsipocz/vizier_fix_nonvo_return_type
BUG: Vizier fix non-VO return_type and minor maintenance
2 parents 113148f + 383bdb6 commit a5cea1d

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,11 @@ vizier
442442

443443
- It is now possible to specify 'galatic' centers in region queries to
444444
have box queries oriented along the galactic axes. [#2152]
445+
445446
- Optional keyword arguments are now keyword only. [#2610]
446447

448+
- Fix parsing vizier_tsvfile returns. [#2611]
449+
447450

448451
Infrastructure, Utility and Other Changes and Additions
449452
-------------------------------------------------------

astroquery/vizier/core.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class VizierClass(BaseQuery):
4545
schema.Or([_str_schema], _str_schema, None),
4646
error="catalog must be a list of strings or a single string")
4747

48-
def __init__(self, columns=["*"], column_filters={}, catalog=None,
48+
def __init__(self, *, columns=["*"], column_filters={}, catalog=None,
4949
keywords=None, ucd="", timeout=conf.timeout,
5050
vizier_server=conf.server, row_limit=conf.row_limit):
5151
"""
@@ -178,7 +178,7 @@ def keywords(self, value):
178178
def keywords(self):
179179
self._keywords = None
180180

181-
def find_catalogs(self, keywords, include_obsolete=False, verbose=False,
181+
def find_catalogs(self, keywords, *, include_obsolete=False, verbose=False,
182182
max_catalogs=None, return_type='votable'):
183183
"""
184184
Search Vizier for catalogs based on a set of keywords, e.g. author name
@@ -244,7 +244,7 @@ def find_catalogs(self, keywords, include_obsolete=False, verbose=False,
244244

245245
return result
246246

247-
def get_catalogs_async(self, catalog, verbose=False, return_type='votable',
247+
def get_catalogs_async(self, catalog, *, verbose=False, return_type='votable',
248248
get_query_payload=False):
249249
"""
250250
Query the Vizier service for a specific catalog
@@ -677,7 +677,7 @@ def _parse_result(self, response, *, get_catalog_names=False, verbose=False,
677677
"""
678678
if response.content[:5] == b'<?xml':
679679
try:
680-
return parse_vizier_votable(
680+
return _parse_vizier_votable(
681681
response.content, verbose=verbose, invalid=invalid,
682682
get_catalog_names=get_catalog_names)
683683
except Exception as ex:
@@ -691,7 +691,7 @@ def _parse_result(self, response, *, get_catalog_names=False, verbose=False,
691691
"self.parsed_result.\n Exception: " +
692692
str(self.table_parse_error))
693693
elif response.content[:5] == b'#\n# ':
694-
return parse_vizier_tsvfile(response.content, verbose=verbose)
694+
return _parse_vizier_tsvfile(response.content, verbose=verbose)
695695
elif response.content[:6] == b'SIMPLE':
696696
return fits.open(BytesIO(response.content),
697697
ignore_missing_end=True)
@@ -710,19 +710,19 @@ def valid_keywords(self):
710710
return self._valid_keyword_dict
711711

712712

713-
def parse_vizier_tsvfile(data, *, verbose=False):
713+
def _parse_vizier_tsvfile(data, *, verbose=False):
714714
"""
715715
Parse a Vizier-generated list of tsv data tables into a list of astropy
716716
Tables.
717717
718718
Parameters
719719
----------
720-
data : ascii str
721-
An ascii string containing the vizier-formatted list of tables
720+
data : response content bytes
721+
Bytes containing the vizier-formatted list of tables
722722
"""
723723

724724
# http://stackoverflow.com/questions/4664850/find-all-occurrences-of-a-substring-in-python
725-
split_indices = [m.start() for m in re.finditer('\n\n#', data)]
725+
split_indices = [m.start() for m in re.finditer(b'\n\n#', data)]
726726
# we want to slice out chunks of the file each time
727727
split_limits = zip(split_indices[:-1], split_indices[1:])
728728
tables = [ascii.read(BytesIO(data[a:b]), format='fast_tab', delimiter='\t',
@@ -731,8 +731,8 @@ def parse_vizier_tsvfile(data, *, verbose=False):
731731
return tables
732732

733733

734-
def parse_vizier_votable(data, *, verbose=False, invalid='warn',
735-
get_catalog_names=False):
734+
def _parse_vizier_votable(data, *, verbose=False, invalid='warn',
735+
get_catalog_names=False):
736736
"""
737737
Given a votable as string, parse it into dict or tables
738738
"""

astroquery/vizier/tests/test_vizier_remote.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ def test_query_region_async_galactic(self):
4949
assert "-c=G" in payload
5050

5151
def test_query_Vizier_instance(self):
52-
v = vizier.core.Vizier(
53-
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
54-
column_filters={"Vmag": ">10"}, keywords=["optical", "xry"])
52+
with pytest.warns(UserWarning, match="xry : No such keyword"):
53+
v = vizier.core.Vizier(
54+
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
55+
column_filters={"Vmag": ">10"}, keywords=["optical", "xry"])
5556

5657
result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
5758
assert isinstance(result, commons.TableList)
@@ -64,7 +65,7 @@ def test_vizier_column_restriction(self):
6465
# catalogs include Bmag's
6566
v = vizier.core.Vizier(
6667
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
67-
column_filters={"Vmag": ">10"}, keywords=["optical", "xry"])
68+
column_filters={"Vmag": ">10"}, keywords=["optical", "X-ray"])
6869

6970
result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
7071
for table in result:
@@ -97,7 +98,8 @@ def test_regressiontest_invalidtable(self):
9798
keywords=['Radio', 'IR'], row_limit=5000)
9899
C = SkyCoord(359.61687 * u.deg, -0.242457 * u.deg, frame="galactic")
99100

100-
V.query_region(C, radius=2 * u.arcmin)
101+
with pytest.warns(UserWarning, match="VOTABLE parsing raised exception"):
102+
V.query_region(C, radius=2 * u.arcmin)
101103

102104
def test_multicoord(self):
103105

@@ -133,3 +135,10 @@ def test_findcatalog_ucd(self):
133135
assert len(result) >= 628
134136
# important part: we're testing that UCD is parsed and some catalogs are ruled out
135137
assert len(ucdresult) < len(result)
138+
139+
def test_asu_tsv_return_type(self):
140+
V = vizier.core.Vizier()
141+
result = V.query_object("HD 226868", catalog=["NOMAD", "UCAC"], return_type='asu-tsv', cache=False)
142+
143+
assert isinstance(result, list)
144+
assert len(result) == 3

docs/vizier/vizier.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ on the Vizier class.
230230
231231
>>> v = Vizier(columns=['_RAJ2000', '_DEJ2000','B-V', 'Vmag', 'Plx'],
232232
... column_filters={"Vmag":">10"}, keywords=["optical", "xry"])
233-
234233
WARNING: xry : No such keyword [astroquery.vizier.core]
235234
236235
Note that whenever an unknown keyword is specified, a warning is emitted and

0 commit comments

Comments
 (0)