Skip to content

Commit 3c216a5

Browse files
authored
Merge pull request #3153 from cds-astro/fix-use-names-over-ids
fix: use the real column names rather than the IDs that astropy generates
2 parents 5667705 + 04fcc57 commit 3c216a5

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ vizier
166166

167167
- Fixed search by UCD -- they were ignored. [#3147]
168168

169+
- Fixed column names -- some characters were replaced by ``_`` instead of keeping
170+
the original name [#3153]
171+
169172
vsa
170173
^^^
171174

astroquery/vizier/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ def _parse_vizier_votable(data, *, verbose=False, invalid='warn',
844844
name = t.name
845845
if name not in table_dict.keys():
846846
table_dict[name] = []
847-
table_dict[name] += [t.to_table()]
847+
table_dict[name] += [t.to_table(use_names_over_ids=True)]
848848
for name in table_dict.keys():
849849
if len(table_dict[name]) > 1:
850850
table_dict[name] = tbl.vstack(table_dict[name])

astroquery/vizier/tests/test_vizier_remote.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ def test_vizier_column_restriction(self):
7272
for table in result:
7373
assert 'Bmag' not in table.columns
7474

75+
def test_vizier_column_exotic_characters(self):
76+
# column names can contain any ascii characters. This checks that they are not
77+
# replaced by underscores, see issue #3124
78+
result = Vizier(columns=["r'mag"],
79+
row_limit=1).get_catalogs(catalog="II/336/apass9")[0]
80+
assert "r'mag" in result.colnames
81+
7582
@pytest.mark.parametrize('all', ('all', '*'))
7683
def test_alls_withaddition(self, all):
7784
# Check that all the expected columns are there plus the _r

docs/vizier/vizier.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ radius. Similar to the VizieR web interface, the queries may be further
1414
constrained by specifying a choice of catalogs, keywords as well as filters on
1515
individual columns before retrieving the results.
1616

17+
.. note::
18+
In earlier versions of astroquery (<0.4.8), columns with special characters like
19+
``r'mag`` were renamed into ``r_mag`` and columns starting with a number like
20+
``2MASS`` were prepended with an underscore ``_2MASS``.
21+
In astroquery >=0.4.8, the column names are the same in VizieR's webpages and in
22+
the tables received (for the two examples: you'll see ``r'mag`` and ``2MASS``).
23+
1724
Table Discover
1825
--------------
1926

@@ -182,7 +189,7 @@ To access an individual table from the `~astroquery.utils.TableList` object:
182189

183190
>>> interesting_table = result['IX/8/catalog']
184191
>>> print(interesting_table)
185-
_2XRS RAB1950 DEB1950 Xname ... Int _RA.icrs _DE.icrs
192+
2XRS RAB1950 DEB1950 Xname ... Int _RA.icrs _DE.icrs
186193
... uJy
187194
--------- ------------ ------------ ----- ... --- ------------ ------------
188195
06429-166 06 42 54.000 -16 39 00.00 ... -- 06 45 08.088 -16 42 11.29
@@ -347,7 +354,7 @@ the ``"+"`` in front of ``"_r"``.
347354
>>> vizier = Vizier(columns=["*", "+_r"], catalog="II/246")
348355
>>> result = vizier.query_region("HD 226868", radius="20s")
349356
>>> print(result[0])
350-
_r RAJ2000 DEJ2000 _2MASS Jmag ... Bflg Cflg Xflg Aflg
357+
_r RAJ2000 DEJ2000 2MASS Jmag ... Bflg Cflg Xflg Aflg
351358
deg deg mag ...
352359
------ ---------- ---------- ---------------- ------ ... ---- ---- ---- ----
353360
0.134 299.590280 35.201599 19582166+3512057 6.872 ... 111 000 0 0
@@ -395,8 +402,8 @@ index to the ``agn`` table (not the 0-based python convention).
395402

396403
>>> guide = Vizier(catalog="II/246", column_filters={"Kmag":"<9.0"}).query_region(agn, radius="30s", inner_radius="2s")[0]
397404
>>> guide.pprint()
398-
_q RAJ2000 DEJ2000 _2MASS Jmag ... Rflg Bflg Cflg Xflg Aflg
399-
deg deg mag ...
405+
_q RAJ2000 DEJ2000 2MASS Jmag ... Rflg Bflg Cflg Xflg Aflg
406+
deg deg mag ...
400407
--- ---------- ---------- ---------------- ------ ... ---- ---- ---- ---- ----
401408
1 10.686015 41.269630 00424464+4116106 9.399 ... 20 20 0c0 2 0
402409
1 10.685657 41.269550 00424455+4116103 10.773 ... 200 200 c00 2 0

0 commit comments

Comments
 (0)