From f15e7e0a8b70e249d72e3d8bbcc5ad3535eadc64 Mon Sep 17 00:00:00 2001 From: Sam Bianco Date: Sun, 25 Aug 2024 22:16:28 -0400 Subject: [PATCH 1/3] case-insensitive query criteria --- CHANGES.rst | 3 +++ astroquery/mast/discovery_portal.py | 4 ++-- astroquery/mast/tests/test_mast_remote.py | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4f651aa759..861d7feae4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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``. [#3085] + 0.4.7 (2024-03-08) ================== diff --git a/astroquery/mast/discovery_portal.py b/astroquery/mast/discovery_portal.py index 8c4a5f30eb..517079094c 100644 --- a/astroquery/mast/discovery_portal.py +++ b/astroquery/mast/discovery_portal.py @@ -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 \ diff --git a/astroquery/mast/tests/test_mast_remote.py b/astroquery/mast/tests/test_mast_remote.py index 6fa71bae63..e36e83cfe7 100644 --- a/astroquery/mast/tests/test_mast_remote.py +++ b/astroquery/mast/tests/test_mast_remote.py @@ -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: @@ -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: From 6de6d7f95f17625570840ca4ee1f6c9cfd66e9e5 Mon Sep 17 00:00:00 2001 From: Sam Bianco Date: Sun, 25 Aug 2024 22:23:42 -0400 Subject: [PATCH 2/3] changelog --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 861d7feae4..830f829f55 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -189,7 +189,7 @@ mast and ``mast.Catalogs.query_criteria``. [#3084] - Support for case-insensitive criteria keyword arguments in ``mast.Observations.query_criteria`` and - ``mast.Catalogs.query_criteria``. [#3085] + ``mast.Catalogs.query_criteria``. [#3087] 0.4.7 (2024-03-08) From ecde7c53004a78692882554e0943b6881a061483 Mon Sep 17 00:00:00 2001 From: Sam Bianco Date: Tue, 27 Aug 2024 09:41:17 -0400 Subject: [PATCH 3/3] Fix failing test --- astroquery/mast/tests/test_mast_remote.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/astroquery/mast/tests/test_mast_remote.py b/astroquery/mast/tests/test_mast_remote.py index e36e83cfe7..c434882405 100644 --- a/astroquery/mast/tests/test_mast_remote.py +++ b/astroquery/mast/tests/test_mast_remote.py @@ -686,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") @@ -711,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")