From 3a37b07228e10cfa8eec038526b1804c0d4c3149 Mon Sep 17 00:00:00 2001 From: MARCHAND MANON Date: Tue, 17 Dec 2024 13:48:36 +0100 Subject: [PATCH 1/2] fix: use the real column names rather than the IDs that astropy generates --- CHANGES.rst | 3 +++ astroquery/vizier/core.py | 2 +- astroquery/vizier/tests/test_vizier_remote.py | 7 +++++++ docs/vizier/vizier.rst | 8 ++++---- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0a95d9945c..922130fda7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -163,6 +163,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 ^^^ diff --git a/astroquery/vizier/core.py b/astroquery/vizier/core.py index ae44501774..3531f862e3 100644 --- a/astroquery/vizier/core.py +++ b/astroquery/vizier/core.py @@ -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]) diff --git a/astroquery/vizier/tests/test_vizier_remote.py b/astroquery/vizier/tests/test_vizier_remote.py index 66dd2a0f05..2945a12937 100644 --- a/astroquery/vizier/tests/test_vizier_remote.py +++ b/astroquery/vizier/tests/test_vizier_remote.py @@ -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 diff --git a/docs/vizier/vizier.rst b/docs/vizier/vizier.rst index df3fe3c883..ee71de2839 100644 --- a/docs/vizier/vizier.rst +++ b/docs/vizier/vizier.rst @@ -182,7 +182,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 @@ -347,7 +347,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 @@ -395,8 +395,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 From 04fcc570a790331efb8481a7a9ebb87a2d1668bb Mon Sep 17 00:00:00 2001 From: MARCHAND MANON Date: Tue, 17 Dec 2024 15:20:10 +0100 Subject: [PATCH 2/2] docs: add note about the column names fix Co-authored-by: keflavich --- docs/vizier/vizier.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/vizier/vizier.rst b/docs/vizier/vizier.rst index ee71de2839..49952517de 100644 --- a/docs/vizier/vizier.rst +++ b/docs/vizier/vizier.rst @@ -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 --------------