Skip to content

Commit dd38fbd

Browse files
committed
Error when filtering by nonexistent column
1 parent 9b13f19 commit dd38fbd

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

astroquery/mast/tests/test_mast.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,6 @@ def test_missions_filter_products(patch_post):
374374
filtered = mast.MastMissions.filter_products(products, extension='fits')
375375
assert len(filtered) > 0
376376

377-
# Filter by non-existing column
378-
with pytest.warns(InputWarning):
379-
mast.MastMissions.filter_products(products, invalid=True)
380-
381377
# Numeric filtering
382378
# Single integer value
383379
filtered = mast.MastMissions.filter_products(products, size=11520)
@@ -412,6 +408,10 @@ def test_missions_filter_products(patch_post):
412408
# Invalid filter value
413409
mast.MastMissions.filter_products(products, size='invalid')
414410

411+
# Error when filtering by non-existing column
412+
with pytest.raises(InvalidQueryError, match="Column 'non_existing' not found in product table."):
413+
mast.MastMissions.filter_products(products, non_existing='value')
414+
415415

416416
def test_missions_download_products(patch_post, tmp_path):
417417
# Check string input
@@ -720,10 +720,6 @@ def test_observations_filter_products(patch_post):
720720
filtered = mast.Observations.filter_products(products, extension='fits')
721721
assert len(filtered) > 0
722722

723-
# Filter by non-existing column
724-
with pytest.warns(InputWarning):
725-
mast.Observations.filter_products(products, invalid=True)
726-
727723
# Numeric filtering
728724
filtered = mast.Observations.filter_products(products, size='<50000')
729725
assert all(filtered['size'] < 50000)
@@ -732,6 +728,10 @@ def test_observations_filter_products(patch_post):
732728
with pytest.raises(InvalidQueryError, match="Could not parse numeric filter 'invalid' for column 'size'"):
733729
filtered = mast.Observations.filter_products(products, size='invalid')
734730

731+
# Filter by non-existing column
732+
with pytest.raises(InvalidQueryError, match="Column 'invalid' not found in product table."):
733+
mast.Observations.filter_products(products, invalid=True)
734+
735735

736736
def test_observations_download_products(patch_post, tmpdir):
737737
# actually download the products

astroquery/mast/tests/test_mast_remote.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,6 @@ def test_missions_filter_products(self):
297297
assert isinstance(filtered, Table)
298298
assert all(filtered['category'] == 'CALIBRATED')
299299

300-
# Filter by non-existing column
301-
with pytest.warns(InputWarning):
302-
filtered = MastMissions.filter_products(products,
303-
invalid=True)
304-
305300
def test_missions_download_products(self, tmp_path):
306301
def check_filepath(path):
307302
assert path.is_file()

astroquery/mast/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ def apply_column_filters(products, filters):
416416
# Applying column-based filters
417417
for colname, vals in filters.items():
418418
if colname not in products.colnames:
419-
warnings.warn(f"Column '{colname}' not found in product table.", InputWarning)
420-
continue
419+
raise InvalidQueryError(f"Column '{colname}' not found in product table.")
421420

422421
col_data = products[colname]
423422
# If the column is an integer or float, accept numeric filters

0 commit comments

Comments
 (0)