Skip to content

Commit c7f77d5

Browse files
committed
fix: non-existent filters now raise an error instead of failing silently
1 parent acc5b91 commit c7f77d5

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ simbad
3030

3131
- Fix the deprecated votable fields ``otype(V)`` and ``otype(S)`` [#3186]
3232

33+
- Fixed non existing flux filters as votable fields would fail silently [#3186]
34+
3335
Infrastructure, Utility and Other Changes and Additions
3436
-------------------------------------------------------
3537

astroquery/simbad/core.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def add_votable_fields(self, *args):
381381
"""
382382

383383
# the legacy way of adding fluxes
384-
args = list(args)
384+
args = set(args)
385385
fluxes_to_add = []
386386
args_copy = args.copy()
387387
for arg in args_copy:
@@ -403,9 +403,10 @@ def add_votable_fields(self, *args):
403403
# output options
404404
output_options = self.list_votable_fields()
405405
# fluxes are case-dependant
406-
fluxes = output_options[output_options["type"] == "filter name"]["name"]
406+
fluxes = set(output_options[output_options["type"] == "filter name"]["name"])
407407
# add fluxes
408-
fluxes_to_add += [flux for flux in args if flux in fluxes]
408+
fluxes_from_names = set(flux for flux in args if flux in fluxes)
409+
fluxes_to_add += fluxes_from_names
409410
if fluxes_to_add:
410411
self.joins.append(_Join("allfluxes", _Column("basic", "oid"),
411412
_Column("allfluxes", "oidref")))
@@ -416,6 +417,10 @@ def add_votable_fields(self, *args):
416417
self.columns_in_output.append(_Column("allfluxes", flux + "_", flux))
417418
else:
418419
self.columns_in_output.append(_Column("allfluxes", flux))
420+
# remove the arguments already added
421+
args -= fluxes_from_names
422+
# remove filters from output options
423+
output_options = output_options[output_options["type"] != "filter name"]
419424

420425
# casefold args because we allow case difference for every other argument (legacy behavior)
421426
args = set(map(str.casefold, args))

astroquery/simbad/tests/test_simbad.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ def test_add_votable_fields_errors():
274274
with pytest.warns(DeprecationWarning, match=r"The notation \'flux\(XXX\)\' is deprecated since 0.4.8 *"):
275275
simbad_instance.add_votable_fields("flux(u)")
276276
assert "u_" in str(simbad_instance.columns_in_output)
277+
# big letter J filter exists, but not small letter j
278+
with pytest.raises(ValueError, match="'j' is not one of the accepted options *"):
279+
simbad_instance.add_votable_fields("j")
277280
with pytest.raises(ValueError, match="Coordinates conversion and formatting is no longer supported*"):
278281
simbad_instance.add_votable_fields("coo(s)")
279282
with pytest.warns(DeprecationWarning, match=r"\'dec\(d\)\' has been renamed \'dec\'. *"):

0 commit comments

Comments
 (0)