Skip to content

Commit c36b19a

Browse files
committed
Included proper use of context manager for warning filter
1 parent 20bf0d4 commit c36b19a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

astroquery/esasky/core.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,22 @@ def query(self, query, *, output_file=None, output_format="votable", verbose=Fal
102102
output_format : str, optional, default 'votable'
103103
possible values 'votable' or 'csv'
104104
verbose : bool, optional, default 'False'
105-
flag to display information about the process
105+
flag to display information about the process and warnings when
106+
the data doesn't conform to its standard.
106107
107108
Returns
108109
-------
109110
A table object
110111
"""
111112
if not verbose:
112-
commons.suppress_vo_warnings()
113-
warnings.filterwarnings("ignore", category=astropy.units.core.UnitsWarning)
114-
job = self._tap.launch_job(query=query, output_file=output_file, output_format=output_format, verbose=verbose,
115-
dump_to_file=output_file is not None)
113+
with warnings.catch_warnings():
114+
commons.suppress_vo_warnings()
115+
warnings.filterwarnings("ignore", category=astropy.units.core.UnitsWarning)
116+
job = self._tap.launch_job(query=query, output_file=output_file, output_format=output_format,
117+
verbose=verbose, dump_to_file=output_file is not None)
118+
else:
119+
job = self._tap.launch_job(query=query, output_file=output_file, output_format=output_format,
120+
verbose=verbose, dump_to_file=output_file is not None)
116121
return job.get_results()
117122

118123
def get_tables(self, *, only_names=True, verbose=False, cache=True):

0 commit comments

Comments
 (0)