Skip to content

Commit ad6c014

Browse files
committed
Merge pull request #467 from keflavich/issue467
astroquery.vizier not retrieving selected columns
2 parents f14efcd + 9357325 commit ad6c014

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ install:
7272
- source activate test
7373

7474
# CORE DEPENDENCIES
75-
- if [[ $SETUP_CMD != egg_info ]]; then $CONDA_INSTALL numpy=$NUMPY_VERSION pytest pip Cython; fi
75+
- if [[ $SETUP_CMD != egg_info ]]; then $CONDA_INSTALL numpy=$NUMPY_VERSION pytest pip Cython jinja2; fi
7676
- if [[ $SETUP_CMD != egg_info ]]; then $PIP_INSTALL pytest-xdist; fi
7777

7878
# ASTROPY

astroquery/vizier/core.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import warnings
66
import json
7+
import copy
78

89
from astropy.extern import six
910
import astropy.units as u
@@ -56,7 +57,8 @@ def __init__(self, columns=["*"], column_filters={}, catalog=None, keywords=None
5657
def columns(self):
5758
""" Columns to include. The special keyword 'all' will return ALL
5859
columns from ALL retrieved tables. """
59-
return self._columns
60+
# columns need to be immutable but still need to be a list
61+
return list(tuple(self._columns))
6062

6163
@columns.setter
6264
def columns(self, values):
@@ -459,12 +461,16 @@ def _args_to_payload(self, *args, **kwargs):
459461
# process: columns
460462
columns = kwargs.get('columns')
461463
if columns is None:
462-
columns = self.columns
464+
columns = copy.copy(self.columns)
463465
else:
464466
columns = self.columns + columns
465467

466-
if 'all' in columns:
467-
columns.remove('all')
468+
# keyword names that can mean 'all' need to be treated separately
469+
alls = ['all','*']
470+
if any(x in columns for x in alls):
471+
for x in alls:
472+
if x in columns:
473+
columns.remove(x)
468474
body['-out.all'] = 2
469475

470476
# process: columns - always request computed positions in degrees
@@ -485,6 +491,7 @@ def _args_to_payload(self, *args, **kwargs):
485491
else:
486492
columns_out += [column]
487493
body['-out.add'] = ','.join(columns_out)
494+
body['-out'] = columns_out
488495
if len(sorts_out) > 0:
489496
body['-sort'] = ','.join(sorts_out)
490497
# process: maximum rows returned

astroquery/vizier/tests/test_vizier_remote.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ def test_query_Vizier_instance(self):
5151
catalog=["NOMAD", "UCAC"])
5252
assert isinstance(result, commons.TableList)
5353

54+
def test_vizier_column_restriction(self):
55+
# Check that the column restriction worked. At least some of these
56+
# catalogs include Bmag's
57+
v = vizier.core.Vizier(columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
58+
column_filters={"Vmag":">10"}, keywords=["optical", "xry"])
59+
result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
60+
for table in result:
61+
assert 'Bmag' not in table.columns
62+
63+
@pytest.mark.parametrize('all',('all','*'))
64+
def test_alls_withaddition(self, all):
65+
# Check that all the expected columns are there plus the _r
66+
# (radius from target) that we've added
67+
v = vizier.core.Vizier(columns=[all, "+_r"], catalog="II/246")
68+
result = v.query_region("HD 226868", radius="20s")
69+
table = result['II/246/out']
70+
assert 'Jmag' in table.columns
71+
assert '_r' in table.columns
72+
5473
def test_get_catalogs(self):
5574
result = vizier.core.Vizier.get_catalogs('J/ApJ/706/83')
5675
assert isinstance(result, commons.TableList)
@@ -73,12 +92,16 @@ def test_multicoord(self):
7392
targets = commons.ICRSCoordGenerator(ra=[299.590, 299.90],
7493
dec=[35.201, 35.201],
7594
unit=(u.deg, u.deg))
95+
# Regression test: the columns of the default should never
96+
# be modified from default
97+
assert vizier.core.Vizier.columns == ['*']
7698
result = vizier.core.Vizier.query_region(targets,
7799
radius=10 * u.arcsec,
78100
catalog=["HIP", "NOMAD", "UCAC"])
79101

80102
assert len(result) >= 5
81103
assert 'I/239/hip_main' in result.keys()
104+
assert 'HIP' in result['I/239/hip_main'].columns
82105
assert result['I/239/hip_main']['HIP'] == 98298
83106

84107
def test_findcatalog_maxcatalog(self):

docs/vizier/vizier.rst

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,25 @@ this Vizier instance:
207207
208208
>>> result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
209209
>>> print(result)
210-
TableList with 2 tables:
211-
'0:I/289/out' with 3 column(s) and 18 row(s)
212-
'1:I/322A/out' with 4 column(s) and 10 row(s)
213-
210+
TableList with 3 tables:
211+
'0:I/297/out' with 3 column(s) and 50 row(s)
212+
'1:I/289/out' with 3 column(s) and 18 row(s)
213+
'2:I/322A/out' with 3 column(s) and 10 row(s)
214+
214215
>>> print(result['I/322A/out'])
215-
_RAJ2000 DEJ2000 Vmag _DEJ2000
216-
---------- ----------- ------ ----------
217-
299.572419 35.1942342 15.986 35.194234
218-
299.580291 35.1768889 13.274 35.176889
219-
299.582571 35.1852253 14.863 35.185225
220-
299.594172 35.1799948 14.690 35.179995
221-
299.601402 35.1981078 14.644 35.198108
222-
299.617669 35.1869987 14.394 35.186999
223-
299.561498 35.2016928 15.687 35.201693
224-
299.570217 35.2256634 14.878 35.225663
225-
299.601081 35.2333378 13.170 35.233338
226-
299.617995 35.2058637 13.946 35.205864
216+
_RAJ2000 _DEJ2000 Vmag
217+
deg deg mag
218+
---------- ---------- ------
219+
299.572419 35.194234 15.986
220+
299.580291 35.176889 13.274
221+
299.582571 35.185225 14.863
222+
299.594172 35.179995 14.690
223+
299.601402 35.198108 14.644
224+
299.617669 35.186999 14.394
225+
299.561498 35.201693 15.687
226+
299.570217 35.225663 14.878
227+
299.601081 35.233338 13.170
228+
299.617995 35.205864 13.946
227229
228230
When specifying the columns of the query, sorting of the returned table can be
229231
requested by adding ``+`` (or ``-`` for reverse sorting order) in front of the column

0 commit comments

Comments
 (0)