Skip to content

Commit fde4c66

Browse files
committed
Fixing long lines, minor cleanup
1 parent e0dbe1c commit fde4c66

File tree

1 file changed

+41
-28
lines changed
  • astroquery/nasa_exoplanet_archive

1 file changed

+41
-28
lines changed

astroquery/nasa_exoplanet_archive/core.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from . import conf
2828

2929
# Import TAP client
30-
# from astroquery.utils.tap.core import TapPlus # This package will be deprecated, use PyVO
3130
import pyvo
3231

3332
# Objects exported when calling from astroquery.nasa_exoplanet_archive import *
@@ -82,11 +81,15 @@
8281
}
8382

8483
CONVERTERS = dict(koi_quarters=[ascii.convert_numpy(str)])
85-
OBJECT_TABLES = {"exoplanets": "pl_", "compositepars": "fpl_", "exomultpars": "mpl_"}
8684

87-
# 'ps' and 'pscomppars' are the main tables of detected exoplanets. Calls to the old tables ('exoplanets', 'compositepars', 'exomultpars') will return errors and urge the user to call the 'ps' or 'pscomppars' tables
88-
OBJECT_TABLES = {"ps": "pl_", "pscomppars": "pl_", "exoplanets": "pl_", "compositepars": "fpl_", "exomultpars": "mpl_"}
89-
MAP_TABLEWARNINGS = {"exoplanets": "Planetary Systems (PS)", "compositepars": "Planetary System Composite Parameters table (PSCompPars)", "exomultpars": "Planetary Systems (PS)"}
85+
# 'ps' and 'pscomppars' are the main tables of detected exoplanets.
86+
# Calls to the old tables ('exoplanets', 'compositepars', 'exomultpars') will
87+
# return errors and urge the user to call the 'ps' or 'pscomppars' tables
88+
OBJECT_TABLES = {"ps": "pl_", "pscomppars": "pl_", "exoplanets": "pl_",
89+
"compositepars": "fpl_", "exomultpars": "mpl_"}
90+
MAP_TABLEWARNINGS = {"exoplanets": "Planetary Systems (PS)",
91+
"compositepars": "Planetary System Composite Parameters table (PSCompPars)",
92+
"exomultpars": "Planetary Systems (PS)"}
9093

9194

9295
def get_access_url(service='tap'):
@@ -111,17 +114,20 @@ class InvalidTableError(InvalidQueryError):
111114
pass
112115

113116

114-
# Class decorator, async_to_sync, modifies NasaExoplanetArchiveClass to convert all query_x_async methods to query_x methods
117+
# Class decorator, async_to_sync, modifies NasaExoplanetArchiveClass to convert
118+
# all query_x_async methods to query_x methods
115119
@async_to_sync
116120
class NasaExoplanetArchiveClass(BaseQuery):
117121
"""
118122
The interface for querying the NASA Exoplanet Archive TAP and API services
119123
120124
A full discussion of the available tables and query syntax is available on the documentation
121-
pages for `TAP <https://exoplanetarchive.ipac.caltech.edu/docs/TAP/usingTAP.html>`_ and `API <https://exoplanetarchive.ipac.caltech.edu/docs/program_interfaces.html>`_.
125+
pages for `TAP <https://exoplanetarchive.ipac.caltech.edu/docs/TAP/usingTAP.html>`_ and
126+
`API <https://exoplanetarchive.ipac.caltech.edu/docs/program_interfaces.html>`_.
122127
"""
123128

124-
# When module us imported, __init__.py runs and loads a configuration object, setting the configuration parameters con.url, conf.timeout and conf.cache
129+
# When module us imported, __init__.py runs and loads a configuration object,
130+
# setting the configuration parameters con.url, conf.timeout and conf.cache
125131
URL_API = conf.url_api
126132
URL_TAP = conf.url_tap
127133
TIMEOUT = conf.timeout
@@ -176,8 +182,16 @@ def query_criteria_async(self, table, get_query_payload=False, cache=None, **cri
176182

177183
# Warn if old table is requested
178184
if table in MAP_TABLEWARNINGS.keys():
179-
# warnings.warn("The '{0}' table is stale and will be depracated in the Archive 2.0 release. Use the 'ps' table. See https://exoplanetarchive.ipac.caltech.edu/docs/ps-pscp_release_notes.html".format(table), InputWarning, )
180-
raise InvalidTableError("The ``{0}`` table is no longer updated and has been replaced by the {1} table, which is connected to the Exoplanet Archive TAP service. Although the argument keywords of the called method should still work on the new table, the allowed values could have changed since the database column names have changed; this document contains the current definitions and a mapping between the new and deprecated names: https://exoplanetarchive.ipac.caltech.edu/docs/API_PS_columns.html. You might also want to review the TAP User Guide for help on creating a new query for the most current data: https://exoplanetarchive.ipac.caltech.edu/docs/TAP/usingTAP.html.".format(table, MAP_TABLEWARNINGS[table]))
185+
raise InvalidTableError(
186+
"The `{0}` table is no longer updated and has been replacedby the `{1}` table, which"
187+
" is connected to the Exoplanet Archive TAP service. Although the argument keywords "
188+
"of the called method should still work on the new table, the allowed values could "
189+
"have changed since the database column names have changed; this document contains "
190+
"the current definitions and a mapping between the new and deprecated names: "
191+
"https://exoplanetarchive.ipac.caltech.edu/docs/API_PS_columns.html. You might also "
192+
"want to review the TAP User Guide for help on creating a new query for the most "
193+
"current data: https://exoplanetarchive.ipac.caltech.edu/docs/TAP/usingTAP.html."
194+
.format(table, MAP_TABLEWARNINGS[table]))
181195

182196
# Deal with lists of columns instead of comma separated strings
183197
criteria = copy.copy(criteria)
@@ -191,7 +205,8 @@ def query_criteria_async(self, table, get_query_payload=False, cache=None, **cri
191205
# with the other options too
192206
# Get the format, or set it to "ipac" if not given. Makes more sense to use CSV here.
193207
criteria["format"] = criteria.get("format", "ipac")
194-
# Less formats are allowed for TAP, so this needs to be updated. Default is VOTable (vot?, xml?), also csv and tsv are allowed
208+
# Less formats are allowed for TAP, so this needs to be updated. Default
209+
# is VOTable (vot?, xml?), also csv and tsv are allowed
195210
if "json" in criteria["format"].lower():
196211
raise InvalidQueryError("The 'json' format is not supported")
197212

@@ -325,33 +340,23 @@ def query_object_async(self, object_name, *, table="ps", get_query_payload=False
325340
.. [2] `NASA Exoplanet Archive API Documentation
326341
<https://exoplanetarchive.ipac.caltech.edu/docs/program_interfaces.html>`_
327342
"""
328-
# if table.lower() in ["ps"]: # actually want to check if default was used, but wasn't working ...
329-
# warnings.warn("The default table for this query method has changed after Archive 2.0 release. The ``ps`` table is being used, and is likely to return multiple rows for an object query. See https://exoplanetarchive.ipac.caltech.edu/docs/API_PS_columns.html", InputWarning, )
330343

331344
prefix = OBJECT_TABLES.get(table, None)
332345
if prefix is None:
333-
raise InvalidQueryError(
334-
"Invalid table '{0}'. The allowed options are: 'ps' and 'pscomppars'".format(
335-
table
336-
)
337-
)
346+
raise InvalidQueryError(f"Invalid table '{table}'. The allowed options are: 'ps' and 'pscomppars'")
338347

339348
if regularize:
340349
object_name = self._regularize_object_name(object_name)
341350

342351
if "where" in criteria:
343-
warnings.warn(
344-
"Any filters using the 'where' argument are ignored in ``query_object``. Consider using ``query_criteria`` instead.",
345-
InputWarning,
346-
)
352+
warnings.warn("Any filters using the 'where' argument are ignored "
353+
"in ``query_object``. Consider using ``query_criteria`` instead.", InputWarning)
347354
if table in self.TAP_TABLES:
348355
criteria["where"] = "hostname='{1}' OR {0}name='{1}'".format(prefix, object_name.strip())
349356
else:
350357
criteria["where"] = "{0}hostname='{1}' OR {0}name='{1}'".format(prefix, object_name.strip())
351358

352-
return self.query_criteria_async(
353-
table, get_query_payload=get_query_payload, cache=cache, **criteria,
354-
)
359+
return self.query_criteria_async(table, get_query_payload=get_query_payload, cache=cache, **criteria)
355360

356361
@class_or_instance
357362
def query_aliases(self, object_name, *, cache=None):
@@ -614,13 +619,21 @@ def _request_to_sql(self, request_payload):
614619
if "order" in request_payload.keys():
615620
request_payload["order by"] = request_payload.pop("order")
616621
if "format" in request_payload.keys():
617-
responseformat = request_payload.pop("format") # figure out what to do with the format keyword
622+
# TODO figure out what to do with the format keyword
623+
responseformat = request_payload.pop("format")
618624
if "ra" in request_payload.keys(): # means this is a `query_region` call
619-
request_payload["where"] = "contains(point('icrs',ra,dec),circle('icrs',{0},{1},{2}))=1".format(request_payload["ra"], request_payload["dec"], request_payload["radius"])
625+
request_payload["where"] = ("contains(point('icrs',ra,dec),circle('icrs',{0},{1},{2}))=1"
626+
.format(request_payload["ra"], request_payload["dec"],
627+
request_payload["radius"]))
620628
del request_payload["ra"], request_payload["dec"], request_payload["radius"]
621629
if "where" in request_payload:
622630
if "pl_hostname" in request_payload["where"]: # means this is a `query_object`
623-
request_payload["where"] = "pl_hostname or pl_name like {0}".format(request_payload["where"][request_payload["where"].find("=")+2:request_payload["where"].find("OR")-2]) # This is a bit hacky since we are getting this from the request_payload (downstream) instead of directly from object_name
631+
# This is a bit hacky since we are getting this from the request_payload (downstream)
632+
# instead of directly from object_name
633+
name = request_payload["where"][
634+
request_payload["where"].find("=")+2:request_payload["where"].find("OR")-2]
635+
request_payload["where"] = f"pl_hostname or pl_name like {name}"
636+
624637
query_opt = " ".join("{0} {1}".format(key, value) for key, value in request_payload.items())
625638
tap_query = "{0} {1}".format(query_req, query_opt)
626639

0 commit comments

Comments
 (0)