Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support case-insensitive query criteria #3087

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ mast
- Present users with an error rather than a warning when nonexistent query criteria are used in ``mast.Observations.query_criteria``
and ``mast.Catalogs.query_criteria``. [#3084]

- Support for case-insensitive criteria keyword arguments in ``mast.Observations.query_criteria`` and
``mast.Catalogs.query_criteria``. [#3087]


0.4.7 (2024-03-08)
==================
Expand Down
4 changes: 2 additions & 2 deletions astroquery/mast/discovery_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ def build_filter_set(self, column_config_name, service_name=None, **filters):
if np.isscalar(value,):
value = [value]

# Get the column type and separator
col_info = caom_col_config.get(colname)
# Get the column type and separator with case-insensitive lookup
col_info = next((v for k, v in caom_col_config.items() if k.lower() == colname.lower()), None)
if not col_info:
closest_match = difflib.get_close_matches(colname, caom_col_config.keys(), n=1)
error_msg = f"Filter '{colname}' does not exist. Did you mean '{closest_match[0]}'?" if closest_match \
Expand Down
19 changes: 19 additions & 0 deletions astroquery/mast/tests/test_mast_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ def test_observations_query_criteria(self):
intentType="calibration")
assert (result["intentType"] == "calibration").all()

# with case-insensitive keyword arguments
result = Observations.query_criteria(Instrument_Name="*WFPC2*",
proposal_ID=8169,
T_min=[51361, 51362])
assert isinstance(result, Table)
assert len(result) == 13

def test_observations_query_criteria_invalid_keyword(self):
# attempt to make a criteria query with invalid keyword
with pytest.raises(InvalidQueryError) as err_no_alt:
Expand Down Expand Up @@ -892,6 +899,18 @@ def check_result(result, exp_vals):
assert isinstance(result, Table)
assert result['distance'][0] <= result['distance'][1]

# with case-insensitive keyword arguments
result = Catalogs.query_criteria(catalog="Tic",
bMAG=[30, 50],
objtype="STAR")
check_result(result, {'ID': '81609218'})

result = Catalogs.query_criteria(catalog="DiskDetective",
STATE=["inactive", "disabled"],
oVaL=[8, 10],
Multi=[3, 7])
check_result(result, {'designation': 'J003920.04-300132.4'})

def test_catalogs_query_criteria_invalid_keyword(self):
# attempt to make a criteria query with invalid keyword
with pytest.raises(InvalidQueryError) as err_no_alt:
Expand Down
Loading