Skip to content

Commit df3b6fc

Browse files
committed
Remove needless argument checks from gaia
`astroquery.gaia.GaiaClass` contained a handful of needless argument checks: - In `load_data()` separately checking for `retrieval_type` being `None` is not needed because the value is checked later on, unless `avoid_datatype_check` is explicitly set to `True`. - In `load_data()` checking for `ids` being `None` only makes a difference if `None` is the explicitly specified value, but any other possible invalid value would pass this check, so it is not very useful. - In `cross_match()` several arguments were given default values and the code then checked if any of those arguments had the default value. It is better to not specify the default value at all and to let Python itself ensure that the mandatory argument values are specified.
1 parent 03c8420 commit df3b6fc

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

astroquery/gaia/core.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL',
218218
-------
219219
A table object
220220
"""
221-
222-
if retrieval_type is None:
223-
raise ValueError("Missing mandatory argument 'retrieval_type'")
224-
225221
now = datetime.now()
226222
now_formatted = now.strftime("%Y%m%d_%H%M%S")
227223
temp_dirname = "temp_" + now_formatted
@@ -239,9 +235,6 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL',
239235

240236
path = os.path.dirname(output_file)
241237

242-
if ids is None:
243-
raise ValueError("Missing mandatory argument 'ids'")
244-
245238
if avoid_datatype_check is False:
246239
# we need to check params
247240
rt = str(retrieval_type).upper()
@@ -757,9 +750,9 @@ def load_user(self, user_id, *, verbose=False):
757750
return self.is_valid_user(user_id=user_id,
758751
verbose=verbose)
759752

760-
def cross_match(self, *, full_qualified_table_name_a=None,
761-
full_qualified_table_name_b=None,
762-
results_table_name=None,
753+
def cross_match(self, *, full_qualified_table_name_a,
754+
full_qualified_table_name_b,
755+
results_table_name,
763756
radius=1.0,
764757
background=False,
765758
verbose=False):
@@ -785,12 +778,6 @@ def cross_match(self, *, full_qualified_table_name_a=None,
785778
-------
786779
Boolean indicating if the specified user is valid
787780
"""
788-
if full_qualified_table_name_a is None:
789-
raise ValueError("Table name A argument is mandatory")
790-
if full_qualified_table_name_b is None:
791-
raise ValueError("Table name B argument is mandatory")
792-
if results_table_name is None:
793-
raise ValueError("Results table name argument is mandatory")
794781
if radius < 0.1 or radius > 10.0:
795782
raise ValueError(f"Invalid radius value. Found {radius}, valid range is: 0.1 to 10.0")
796783

astroquery/gaia/tests/test_gaiatap.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ def test_cross_match_invalid_radius(cross_match_kwargs, radius):
245245

246246

247247
@pytest.mark.parametrize(
248-
"missing_kwarg,msg",
249-
[("full_qualified_table_name_a", "Table name A"),
250-
("full_qualified_table_name_b", "Table name B"),
251-
("results_table_name", "Results table name")])
252-
def test_cross_match_missing_mandatory_kwarg(cross_match_kwargs, missing_kwarg, msg):
248+
"missing_kwarg",
249+
["full_qualified_table_name_a", "full_qualified_table_name_b", "results_table_name"])
250+
def test_cross_match_missing_mandatory_kwarg(cross_match_kwargs, missing_kwarg):
253251
del cross_match_kwargs[missing_kwarg]
254-
with pytest.raises(ValueError, match=rf"^{msg} argument is mandatory$"):
252+
with pytest.raises(
253+
TypeError, match=rf"missing 1 required keyword-only argument: '{missing_kwarg}'$"
254+
):
255255
GAIA_QUERIER.cross_match(**cross_match_kwargs)
256256

257257

0 commit comments

Comments
 (0)