Skip to content

Commit

Permalink
fix: non-existent filters now raise an error instead of failing silently
Browse files Browse the repository at this point in the history
  • Loading branch information
ManonMarchand committed Jan 21, 2025
1 parent 668edf3 commit b8fac83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ simbad

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

- Fixed non existing flux filters as votable fields would fail silently [#3186]

Infrastructure, Utility and Other Changes and Additions
-------------------------------------------------------

Expand Down
11 changes: 8 additions & 3 deletions astroquery/simbad/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def add_votable_fields(self, *args):
"""

# the legacy way of adding fluxes
args = list(args)
args = set(args)
fluxes_to_add = []
args_copy = args.copy()
for arg in args_copy:
Expand All @@ -403,9 +403,10 @@ def add_votable_fields(self, *args):
# output options
output_options = self.list_votable_fields()
# fluxes are case-dependant
fluxes = output_options[output_options["type"] == "filter name"]["name"]
fluxes = set(output_options[output_options["type"] == "filter name"]["name"])
# add fluxes
fluxes_to_add += [flux for flux in args if flux in fluxes]
fluxes_from_names = set(flux for flux in args if flux in fluxes)
fluxes_to_add += fluxes_from_names
if fluxes_to_add:
self.joins.append(_Join("allfluxes", _Column("basic", "oid"),
_Column("allfluxes", "oidref")))
Expand All @@ -416,6 +417,10 @@ def add_votable_fields(self, *args):
self.columns_in_output.append(_Column("allfluxes", flux + "_", flux))
else:
self.columns_in_output.append(_Column("allfluxes", flux))
# remove the arguments already added
args -= fluxes_from_names
# remove filters from output options
output_options = output_options[output_options["type"] != "filter name"]

# casefold args because we allow case difference for every other argument (legacy behavior)
args = set(map(str.casefold, args))
Expand Down
3 changes: 3 additions & 0 deletions astroquery/simbad/tests/test_simbad.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ def test_add_votable_fields_errors():
with pytest.warns(DeprecationWarning, match=r"The notation \'flux\(XXX\)\' is deprecated since 0.4.8 *"):
simbad_instance.add_votable_fields("flux(u)")
assert "u_" in str(simbad_instance.columns_in_output)
# big letter J filter exists, but not small letter j
with pytest.raises(ValueError, match="'j' is not one of the accepted options *"):
simbad_instance.add_votable_fields("j")
with pytest.raises(ValueError, match="Coordinates conversion and formatting is no longer supported*"):
simbad_instance.add_votable_fields("coo(s)", "dec(d)")
with pytest.raises(ValueError, match="Catalog Ids are no longer supported as an output option.*"):
Expand Down

0 comments on commit b8fac83

Please sign in to comment.