Skip to content

Commit

Permalink
Merge pull request #2153 from eerovaher/gaia-config-use
Browse files Browse the repository at this point in the history
Fix the bug that caused `MAIN_GAIA_TABLE` in `astroquery.gaia` to not work
  • Loading branch information
keflavich authored Oct 18, 2021
2 parents 8cdf185 + 561011f commit 7de9084
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^

Expand Down
12 changes: 6 additions & 6 deletions astroquery/gaia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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
Expand Down Expand Up @@ -426,7 +426,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)
Expand Down Expand Up @@ -486,7 +486,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,
Expand Down Expand Up @@ -563,7 +563,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,
Expand All @@ -580,7 +580,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,
Expand Down Expand Up @@ -631,7 +631,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,
Expand Down
16 changes: 16 additions & 0 deletions astroquery/gaia/tests/test_gaiatap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 7de9084

Please sign in to comment.