Skip to content

Commit cd64109

Browse files
keflavichbsipocz
authored andcommitted
fix documentation; doctests now pass. This PR includes significant
refactor of some broken code and renames some variables for clarity. The assertions are added because one test case resulted in a supposedly-json file being read in as a string, which resulted in breakage downstream
1 parent 149e87f commit cd64109

File tree

5 files changed

+154
-115
lines changed

5 files changed

+154
-115
lines changed

astroquery/splatalogue/build_species_table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def get_json_species_ids(*, outfile='splat-species.json', base_url=conf.base_url
6767
species[kid['class'][0]][kid['value']] = kid.text
6868

6969
with open(data_path(outfile), 'w') as f:
70+
assert isinstance(species, dict)
7071
json.dump(species, f)
7172

7273
return json.dumps(species)

astroquery/splatalogue/core.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ def set_default_options(self, **kwargs):
7676
"""
7777
self.data.update(self._parse_kwargs(**kwargs))
7878

79-
def get_species_ids(self, *, restr=None, reflags=0, recache=False):
79+
def get_species_ids(self, regex_str=None, *, reflags=0, recache=False):
8080
"""
8181
Get a dictionary of "species" IDs, where species refers to the molecule
8282
name, mass, and chemical composition.
8383
8484
Parameters
8585
----------
86-
restr : str
86+
regex_str : str
8787
String to compile into an re, if specified. Searches table for
8888
species whose names match
8989
reflags : int
@@ -95,7 +95,7 @@ def get_species_ids(self, *, restr=None, reflags=0, recache=False):
9595
--------
9696
>>> import re
9797
>>> import pprint # unfortunate hack required for documentation testing
98-
>>> rslt = Splatalogue.get_species_ids(restr='Formaldehyde')
98+
>>> rslt = Splatalogue.get_species_ids(regex_str='Formaldehyde')
9999
>>> pprint.pprint(rslt)
100100
{'03023 H2CO - Formaldehyde': '194',
101101
'03106 H213CO - Formaldehyde': '324',
@@ -107,7 +107,7 @@ def get_species_ids(self, *, restr=None, reflags=0, recache=False):
107107
'03301 D213CO - Formaldehyde': '1220',
108108
'03315 HDC18O - Formaldehyde': '21141',
109109
'0348 D2C18O - Formaldehyde': '21140'}
110-
>>> rslt = Splatalogue.get_species_ids(restr='H2CO')
110+
>>> rslt = Splatalogue.get_species_ids(regex_str='H2CO')
111111
>>> pprint.pprint(rslt)
112112
{'03023 H2CO - Formaldehyde': '194',
113113
'03109 H2COH+ - Hydroxymethylium ion': '224',
@@ -125,9 +125,9 @@ def get_species_ids(self, *, restr=None, reflags=0, recache=False):
125125
'08903 CH3CHNH2COOH - II - α-Alanine': '1322'}
126126
>>> # note the whitespace, preventing H2CO within other
127127
>>> # more complex molecules
128-
>>> Splatalogue.get_species_ids(restr=' H2CO ')
128+
>>> Splatalogue.get_species_ids(regex_str=' H2CO ')
129129
{'03023 H2CO - Formaldehyde': '194'}
130-
>>> Splatalogue.get_species_ids(restr=' h2co ', reflags=re.IGNORECASE)
130+
>>> Splatalogue.get_species_ids(regex_str=' h2co ', reflags=re.IGNORECASE)
131131
{'03023 H2CO - Formaldehyde': '194'}
132132
133133
"""
@@ -136,8 +136,8 @@ def get_species_ids(self, *, restr=None, reflags=0, recache=False):
136136
if not hasattr(self, '_species_ids'):
137137
self._species_ids = load_species_table.species_lookuptable(recache=recache)
138138

139-
if restr is not None:
140-
return self._species_ids.find(restr, flags=reflags)
139+
if regex_str is not None:
140+
return self._species_ids.find(regex_str, flags=reflags)
141141
else:
142142
return self._species_ids
143143

@@ -319,7 +319,7 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None,
319319
payload['sid[]'] = []
320320
elif chemical_name is not None:
321321
if parse_chemistry_locally:
322-
species_ids = self.get_species_ids(restr=chemical_name, reflags=chem_re_flags)
322+
species_ids = self.get_species_ids(regex_str=chemical_name, reflags=chem_re_flags)
323323
if len(species_ids) == 0:
324324
raise ValueError("No matching chemical species found.")
325325
payload['sid[]'] = list(species_ids.values())

astroquery/splatalogue/data/splat-species.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

astroquery/splatalogue/load_species_table.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ def species_lookuptable(*, filename='splat-species.json', recache=False):
6666
# check to see if the file exists; if not, we run the
6767
# scraping routine
6868
if recache or not os.path.isfile(file_cache):
69-
species = get_json_species_ids(filename)
69+
species = get_json_species_ids(outfile=filename)
70+
assert isinstance(species, dict)
7071
else:
7172
with open(data_path(filename), 'r') as f:
7273
species = json.load(f)
74+
assert isinstance(species, dict)
7375
lookuptable = SpeciesLookuptable(dict((v, k) for d in species.values()
7476
for k, v in d.items()))
7577

0 commit comments

Comments
 (0)