Skip to content

Commit de90983

Browse files
committed
Add docstrings to utils.py
1 parent 5fa63fb commit de90983

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

astroquery/eso/core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from ..exceptions import RemoteServiceError, NoResultsWarning, LoginError
3232
from ..query import QueryWithLogin
3333
from ..utils import schema
34-
from .utils import py2adql, _split_str_as_list_of_str, sanitize_val, to_cache, eso_hash
34+
from .utils import py2adql, _split_str_as_list_of_str, adql_sanitize_val, to_cache, eso_hash
3535
import pyvo
3636

3737
__doctest_skip__ = ['EsoClass.*']
@@ -112,18 +112,22 @@ def timeout(self):
112112
# [W1203 - logging-fstring-interpolation]
113113
@staticmethod
114114
def log_info(message):
115+
"Wrapper for logging function"
115116
log.info("%s", message)
116117

117118
@staticmethod
118119
def log_warning(message):
120+
"Wrapper for logging function"
119121
log.warning("%s", message)
120122

121123
@staticmethod
122124
def log_error(message):
125+
"Wrapper for logging function"
123126
log.error("%s", message)
124127

125128
@staticmethod
126129
def log_debug(message):
130+
"Wrapper for logging function"
127131
log.debug("%s", message)
128132

129133
@timeout.setter
@@ -393,7 +397,7 @@ def _query_instrument_or_collection(self,
393397

394398
# TODO
395399
# Check whether v is string or number, put in single quotes if string
396-
where_constraints_strlist = [f"{k} = {sanitize_val(v)}" for k, v in filters.items()] + coord_constraint
400+
where_constraints_strlist = [f"{k} = {adql_sanitize_val(v)}" for k, v in filters.items()] + coord_constraint
397401
where_constraints = [where_collections_str] + where_constraints_strlist
398402
query = py2adql(table=query_on.table_name, columns=columns, where_constraints=where_constraints,
399403
top=self.ROW_LIMIT)
@@ -465,7 +469,7 @@ def query_main(self, *, column_filters=None, columns=None,
465469
columns = columns or []
466470
filters = {**dict(kwargs), **column_filters}
467471

468-
where_constraints_strlist = [f"{k} = {sanitize_val(v)}" for k, v in filters.items()]
472+
where_constraints_strlist = [f"{k} = {adql_sanitize_val(v)}" for k, v in filters.items()]
469473
where_constraints = where_constraints_strlist
470474

471475
if print_help:

astroquery/eso/utils.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/usr/bin/env/python
2-
from typing import Union, List
3-
import pickle
2+
3+
"""
4+
utils.py: helper functions for the astropy.eso module
5+
"""
6+
47
import copy
5-
from astroquery import log
68
import hashlib
9+
import pickle
10+
from typing import Union, List
11+
12+
from astroquery import log
713

814

915
def _split_str_as_list_of_str(column_str: str):
@@ -14,7 +20,10 @@ def _split_str_as_list_of_str(column_str: str):
1420
return column_list
1521

1622

17-
def sanitize_val(x):
23+
def adql_sanitize_val(x):
24+
"""
25+
If the value is a string, put it into single quotes
26+
"""
1827
if isinstance(x, str):
1928
return f"'{x}'"
2029
else:
@@ -23,9 +32,13 @@ def sanitize_val(x):
2332

2433
def py2adql(table: str, columns: Union[List, str] = None, where_constraints: List = None,
2534
order_by: str = '', order_by_desc=True, top: int = None):
35+
"""
36+
Return the adql string corresponding to the parameters passed
37+
"""
2638
# Initialize / validate
2739
query_string = None
28-
wc = [] if where_constraints is None else where_constraints[:] # do not modify the original list
40+
# do not modify the original list
41+
wc = [] if where_constraints is None else where_constraints[:]
2942
if isinstance(columns, str):
3043
columns = _split_str_as_list_of_str(columns)
3144
if columns is None or len(columns) < 1:
@@ -50,12 +63,18 @@ def py2adql(table: str, columns: Union[List, str] = None, where_constraints: Lis
5063

5164

5265
def eso_hash(query_str: str, url: str):
66+
"""
67+
Return a hash given an adql query string and an url.
68+
"""
5369
request_key = (query_str, url)
5470
h = hashlib.sha224(pickle.dumps(request_key)).hexdigest()
5571
return h
5672

5773

5874
def to_cache(table, cache_file):
75+
"""
76+
Dump a table to a pickle file
77+
"""
5978
log.debug("Caching data to %s", cache_file)
6079

6180
table = copy.deepcopy(table)

0 commit comments

Comments
 (0)