From 12b03591efd3a85b4500daa9f761c3788e271af9 Mon Sep 17 00:00:00 2001 From: Eero Vaher Date: Fri, 24 Sep 2021 14:27:13 +0200 Subject: [PATCH 1/2] Add a regression test for issues #2093 and #2099 Currently querying the Gaia archive can return results from `gaiadr2.gaia_source` even if the user has specified that they wish to query a different table. This commit adds a regression test to see if the right table actually gets queried. --- astroquery/gaia/tests/test_gaiatap.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/astroquery/gaia/tests/test_gaiatap.py b/astroquery/gaia/tests/test_gaiatap.py index 53d9ed8f3d..77abccb2ee 100644 --- a/astroquery/gaia/tests/test_gaiatap.py +++ b/astroquery/gaia/tests/test_gaiatap.py @@ -18,6 +18,7 @@ import os import pytest +from astroquery.gaia import conf from astroquery.gaia.core import GaiaClass from astroquery.gaia.tests.DummyTapHandler import DummyTapHandler from astroquery.utils.tap.conn.tests.DummyConnHandler import DummyConnHandler @@ -344,6 +345,21 @@ def test_cone_search_async(self): None, np.int32) + # Regression test for #2093 and #2099 - changing the MAIN_GAIA_TABLE + # had no effect. + # The preceding tests should have used the default value. + assert 'gaiadr2.gaia_source' in job.parameters['query'] + # Test changing the table name through conf. + conf.MAIN_GAIA_TABLE = 'name_from_conf' + job = tap.cone_search_async(sc, radius) + assert 'name_from_conf' in job.parameters['query'] + # Changing the value through the class should overrule conf. + tap.MAIN_GAIA_TABLE = 'name_from_class' + job = tap.cone_search_async(sc, radius) + assert 'name_from_class' in job.parameters['query'] + # Cleanup. + conf.reset('MAIN_GAIA_TABLE') + def __check_results_column(self, results, columnName, description, unit, dataType): c = results[columnName] From 561011f1dac8430debabcd5fe417f4dcb429b6cd Mon Sep 17 00:00:00 2001 From: Eero Vaher Date: Fri, 24 Sep 2021 14:55:27 +0200 Subject: [PATCH 2/2] Make the MAIN_GAIA_TABLE option work It is now possible to change the table Gaia queries are made from through the MAIN_GAIA_TABLE config item or class attribute at runtime. If the class attribute is specified then it will take precedence over the config item. --- CHANGES.rst | 6 ++++++ astroquery/gaia/core.py | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index eeda626a4b..0a5024f9da 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,12 @@ casda - Add ability to stage and download non image data which have been found through the CASDA obscore table. [#2158] +gaia +^^^^ + +- The bug which caused changing the ``MAIN_GAIA_TABLE`` option to have no + effect has been fixed [#2153] + vizier ^^^^^^ diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index dd3e29cb7a..a3acfb481a 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -39,7 +39,7 @@ class GaiaClass(TapPlus): """ Proxy class to default TapPlus object (pointing to Gaia Archive) """ - MAIN_GAIA_TABLE = conf.MAIN_GAIA_TABLE + MAIN_GAIA_TABLE = None MAIN_GAIA_TABLE_RA = conf.MAIN_GAIA_TABLE_RA MAIN_GAIA_TABLE_DEC = conf.MAIN_GAIA_TABLE_DEC ROW_LIMIT = conf.ROW_LIMIT @@ -427,7 +427,7 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, dist ASC """.format(**{'row_limit': "TOP {0}".format(self.ROW_LIMIT) if self.ROW_LIMIT > 0 else "", 'ra_column': self.MAIN_GAIA_TABLE_RA, 'dec_column': self.MAIN_GAIA_TABLE_DEC, - 'columns': columns, 'table_name': self.MAIN_GAIA_TABLE, 'ra': ra, 'dec': dec, + 'columns': columns, 'table_name': self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE, 'ra': ra, 'dec': dec, 'width': widthDeg.value, 'height': heightDeg.value}) if async_job: job = self.launch_job_async(query, verbose=verbose) @@ -487,7 +487,7 @@ def query_object_async(self, coordinate, radius=None, width=None, """ return self.__query_object(coordinate, radius, width, height, async_job=True, verbose=verbose, columns=columns) - def __cone_search(self, coordinate, radius, table_name=MAIN_GAIA_TABLE, + def __cone_search(self, coordinate, radius, table_name=None, ra_column_name=MAIN_GAIA_TABLE_RA, dec_column_name=MAIN_GAIA_TABLE_DEC, async_job=False, @@ -564,7 +564,7 @@ def __cone_search(self, coordinate, radius, table_name=MAIN_GAIA_TABLE, """.format(**{'ra_column': ra_column_name, 'row_limit': "TOP {0}".format(self.ROW_LIMIT) if self.ROW_LIMIT > 0 else "", 'dec_column': dec_column_name, 'columns': columns, 'ra': ra, 'dec': dec, - 'radius': radiusDeg, 'table_name': table_name}) + 'radius': radiusDeg, 'table_name': table_name or self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE}) if async_job: return self.launch_job_async(query=query, @@ -581,7 +581,7 @@ def __cone_search(self, coordinate, radius, table_name=MAIN_GAIA_TABLE, dump_to_file=dump_to_file) def cone_search(self, coordinate, radius=None, - table_name=MAIN_GAIA_TABLE, + table_name=None, ra_column_name=MAIN_GAIA_TABLE_RA, dec_column_name=MAIN_GAIA_TABLE_DEC, output_file=None, @@ -632,7 +632,7 @@ def cone_search(self, coordinate, radius=None, dump_to_file=dump_to_file, columns=columns) def cone_search_async(self, coordinate, radius=None, - table_name=MAIN_GAIA_TABLE, + table_name=None, ra_column_name=MAIN_GAIA_TABLE_RA, dec_column_name=MAIN_GAIA_TABLE_DEC, background=False,