Skip to content

Commit

Permalink
Merge pull request #3153 from cds-astro/fix-use-names-over-ids
Browse files Browse the repository at this point in the history
fix: use the real column names rather than the IDs that astropy generates
  • Loading branch information
bsipocz authored Dec 19, 2024
2 parents 5667705 + 04fcc57 commit 3c216a5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ vizier

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

- Fixed column names -- some characters were replaced by ``_`` instead of keeping
the original name [#3153]

vsa
^^^

Expand Down
2 changes: 1 addition & 1 deletion astroquery/vizier/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def _parse_vizier_votable(data, *, verbose=False, invalid='warn',
name = t.name
if name not in table_dict.keys():
table_dict[name] = []
table_dict[name] += [t.to_table()]
table_dict[name] += [t.to_table(use_names_over_ids=True)]
for name in table_dict.keys():
if len(table_dict[name]) > 1:
table_dict[name] = tbl.vstack(table_dict[name])
Expand Down
7 changes: 7 additions & 0 deletions astroquery/vizier/tests/test_vizier_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def test_vizier_column_restriction(self):
for table in result:
assert 'Bmag' not in table.columns

def test_vizier_column_exotic_characters(self):
# column names can contain any ascii characters. This checks that they are not
# replaced by underscores, see issue #3124
result = Vizier(columns=["r'mag"],
row_limit=1).get_catalogs(catalog="II/336/apass9")[0]
assert "r'mag" in result.colnames

@pytest.mark.parametrize('all', ('all', '*'))
def test_alls_withaddition(self, all):
# Check that all the expected columns are there plus the _r
Expand Down
15 changes: 11 additions & 4 deletions docs/vizier/vizier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ radius. Similar to the VizieR web interface, the queries may be further
constrained by specifying a choice of catalogs, keywords as well as filters on
individual columns before retrieving the results.

.. note::
In earlier versions of astroquery (<0.4.8), columns with special characters like
``r'mag`` were renamed into ``r_mag`` and columns starting with a number like
``2MASS`` were prepended with an underscore ``_2MASS``.
In astroquery >=0.4.8, the column names are the same in VizieR's webpages and in
the tables received (for the two examples: you'll see ``r'mag`` and ``2MASS``).

Table Discover
--------------

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

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

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

0 comments on commit 3c216a5

Please sign in to comment.