Skip to content

Commit c043346

Browse files
authored
Merge pull request #3087 from snbianco/ASB-28434-case-insensitive
Support case-insensitive query criteria
2 parents 01c4d29 + ecde7c5 commit c043346

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

CHANGES.rst

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ mast
188188
- Present users with an error rather than a warning when nonexistent query criteria are used in ``mast.Observations.query_criteria``
189189
and ``mast.Catalogs.query_criteria``. [#3084]
190190

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

192195
0.4.7 (2024-03-08)
193196
==================

astroquery/mast/discovery_portal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ def build_filter_set(self, column_config_name, service_name=None, **filters):
404404
if np.isscalar(value,):
405405
value = [value]
406406

407-
# Get the column type and separator
408-
col_info = caom_col_config.get(colname)
407+
# Get the column type and separator with case-insensitive lookup
408+
col_info = next((v for k, v in caom_col_config.items() if k.lower() == colname.lower()), None)
409409
if not col_info:
410410
closest_match = difflib.get_close_matches(colname, caom_col_config.keys(), n=1)
411411
error_msg = f"Filter '{colname}' does not exist. Did you mean '{closest_match[0]}'?" if closest_match \

astroquery/mast/tests/test_mast_remote.py

+29-10
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ def test_observations_query_criteria(self):
274274
intentType="calibration")
275275
assert (result["intentType"] == "calibration").all()
276276

277+
# with case-insensitive keyword arguments
278+
result = Observations.query_criteria(Instrument_Name="*WFPC2*",
279+
proposal_ID=8169,
280+
T_min=[51361, 51362])
281+
assert isinstance(result, Table)
282+
assert len(result) == 13
283+
277284
def test_observations_query_criteria_invalid_keyword(self):
278285
# attempt to make a criteria query with invalid keyword
279286
with pytest.raises(InvalidQueryError) as err_no_alt:
@@ -679,19 +686,9 @@ def check_result(result, row, exp_values):
679686
radius=0.01*u.deg, catalog="panstarrs",
680687
table="mean")
681688
row = np.where((result['objName'] == 'PSO J322.4622+12.1920') & (result['yFlags'] == 16777496))
682-
second_id = result[1]['objID']
683689
assert isinstance(result, Table)
684690
np.testing.assert_allclose(result[row]['distance'], 0.039381703406789904)
685691

686-
result = Catalogs.query_region("322.49324 12.16683",
687-
radius=0.01*u.deg, catalog="panstarrs",
688-
table="mean",
689-
pagesize=1,
690-
page=2)
691-
assert isinstance(result, Table)
692-
assert len(result) == 1
693-
assert second_id == result[0]['objID']
694-
695692
result = Catalogs.query_region("158.47924 -7.30962",
696693
radius=in_radius,
697694
catalog="Galex")
@@ -704,9 +701,19 @@ def check_result(result, row, exp_values):
704701
radius=in_radius,
705702
catalog="tic")
706703
row = np.where(result['ID'] == '841736289')
704+
second_id = result[1]['ID']
707705
check_result(result, row, {'gaiaqflag': 1})
708706
np.testing.assert_allclose(result[row]['RA_orig'], 158.475246786483)
709707

708+
result = Catalogs.query_region("158.47924 -7.30962",
709+
radius=in_radius,
710+
catalog="tic",
711+
pagesize=1,
712+
page=2)
713+
assert isinstance(result, Table)
714+
assert len(result) == 1
715+
assert second_id == result[0]['ID']
716+
710717
result = Catalogs.query_region("158.47924 -7.30962",
711718
radius=in_radius,
712719
catalog="ctl")
@@ -892,6 +899,18 @@ def check_result(result, exp_vals):
892899
assert isinstance(result, Table)
893900
assert result['distance'][0] <= result['distance'][1]
894901

902+
# with case-insensitive keyword arguments
903+
result = Catalogs.query_criteria(catalog="Tic",
904+
bMAG=[30, 50],
905+
objtype="STAR")
906+
check_result(result, {'ID': '81609218'})
907+
908+
result = Catalogs.query_criteria(catalog="DiskDetective",
909+
STATE=["inactive", "disabled"],
910+
oVaL=[8, 10],
911+
Multi=[3, 7])
912+
check_result(result, {'designation': 'J003920.04-300132.4'})
913+
895914
def test_catalogs_query_criteria_invalid_keyword(self):
896915
# attempt to make a criteria query with invalid keyword
897916
with pytest.raises(InvalidQueryError) as err_no_alt:

0 commit comments

Comments
 (0)