Skip to content

Commit

Permalink
Merge pull request #3087 from snbianco/ASB-28434-case-insensitive
Browse files Browse the repository at this point in the history
Support case-insensitive query criteria
  • Loading branch information
bsipocz authored Aug 28, 2024
2 parents 01c4d29 + ecde7c5 commit c043346
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
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
39 changes: 29 additions & 10 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 @@ -679,19 +686,9 @@ def check_result(result, row, exp_values):
radius=0.01*u.deg, catalog="panstarrs",
table="mean")
row = np.where((result['objName'] == 'PSO J322.4622+12.1920') & (result['yFlags'] == 16777496))
second_id = result[1]['objID']
assert isinstance(result, Table)
np.testing.assert_allclose(result[row]['distance'], 0.039381703406789904)

result = Catalogs.query_region("322.49324 12.16683",
radius=0.01*u.deg, catalog="panstarrs",
table="mean",
pagesize=1,
page=2)
assert isinstance(result, Table)
assert len(result) == 1
assert second_id == result[0]['objID']

result = Catalogs.query_region("158.47924 -7.30962",
radius=in_radius,
catalog="Galex")
Expand All @@ -704,9 +701,19 @@ def check_result(result, row, exp_values):
radius=in_radius,
catalog="tic")
row = np.where(result['ID'] == '841736289')
second_id = result[1]['ID']
check_result(result, row, {'gaiaqflag': 1})
np.testing.assert_allclose(result[row]['RA_orig'], 158.475246786483)

result = Catalogs.query_region("158.47924 -7.30962",
radius=in_radius,
catalog="tic",
pagesize=1,
page=2)
assert isinstance(result, Table)
assert len(result) == 1
assert second_id == result[0]['ID']

result = Catalogs.query_region("158.47924 -7.30962",
radius=in_radius,
catalog="ctl")
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

0 comments on commit c043346

Please sign in to comment.