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

Parameter validation on MastMissions queries #3126

Merged
merged 5 commits into from
Nov 6, 2024

Conversation

snbianco
Copy link
Contributor

@snbianco snbianco commented Nov 5, 2024

Checks the validity of criteria keyword arguments on MastMissions queries. Raises an InvalidQueryError if an invalid parameter is passed rather then sending them to the API to be ignored. If the invalid parameter is close to a valid keyword, the user is prompted with the closest match.

I also altered the MastMissions.get_column_list method to save the column list for each mission in a dictionary class attribute called columns. This way, we do not make unnecessary API calls.

I added a test to test_mast_remote.py and modified some in test_mast.py that were not passing in arguments correctly.

@dr-rodriguez @astrojimig

@snbianco snbianco added the mast label Nov 5, 2024
@snbianco
Copy link
Contributor Author

snbianco commented Nov 5, 2024

There are a few tests that might fail due to an unrelated issue that we've been having with PS1 queries. If they happen, the failures would be for the Catalogs.query_criteria function where catalog='panstarrs'. I'm working on getting this sorted out.

Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 71.28713% with 29 lines in your changes missing coverage. Please review.

Project coverage is 67.53%. Comparing base (701a4e3) to head (ed3bdff).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
astroquery/mast/collections.py 73.77% 16 Missing ⚠️
astroquery/mast/missions.py 69.44% 11 Missing ⚠️
astroquery/mast/utils.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3126      +/-   ##
==========================================
+ Coverage   67.49%   67.53%   +0.04%     
==========================================
  Files         233      233              
  Lines       18420    18487      +67     
==========================================
+ Hits        12433    12486      +53     
- Misses       5987     6001      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@snbianco snbianco marked this pull request as ready for review November 5, 2024 20:15
@snbianco snbianco requested a review from bsipocz November 5, 2024 20:16
Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments in line and bigger picture ones:

  • I think it may be useful for the users to have a method that actually lists all the possibly kwargs?

  • I'm sure there are a couple of related open issues for this as weeding out the everything swallowing **kwargs is a thing I would have liked to see for a while. Could you please cross link those, so we can close a couple of things? So, overall thank you.


Parameters
----------
**kwargs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**kwargs
**criteria

# Create Table with parsed data
col_table = Table(rows=rows, names=('name', 'data_type', 'description'))
self.columns[self.mission] = col_table
except Exception:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this is inherited code, but we should be more specific and only except specific exceptions rather than staying this super general. And if we need to stay this general, capture the exception and raise the same more specific type of it rather than reraise the generic Exception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to catch more specific exceptions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to programatically generate this file? If yes, does it take long?
(I'm asking as files like this tend to diverge from actual server side behaviour super quickly)

Copy link
Contributor Author

@snbianco snbianco Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is only being used for the non-remote test suite, and programmatically generating it would require a connection. Because it's describing a table schema that already exists (and the query results are being mocked as well), I don't think we should have any issues with server-side changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Then just maybe add a readme file in the data directory that describes how to generate this file, if needed, in the future.

@snbianco
Copy link
Contributor Author

snbianco commented Nov 5, 2024

Some minor comments in line and bigger picture ones:

  • I think it may be useful for the users to have a method that actually lists all the possibly kwargs?
  • I'm sure there are a couple of related open issues for this as weeding out the everything swallowing **kwargs is a thing I would have liked to see for a while. Could you please cross link those, so we can close a couple of things? So, overall thank you.

For your first point, there is the MastMissions.get_column_list method that returns a table of valid columns for the relevant mission. For the second, I've linked some related issues:

@bsipocz
Copy link
Member

bsipocz commented Nov 5, 2024

Should I do that in this PR or just stick to the MastMissions class and address the rest later?

It's OK to do that in a follow up. Also, given that there are 50+ options, I think it's a good middle ground to explicitly refer to the method that lists the possible options rather than actually adding them to the docstring.

Relevant, but this is still an issue for the Catalogs.query_object function

OK, so if something similar could be done for catalogs, too then we can at least cross that topic off for mast. I'll still need to address it for any of the other modules that do it.

@snbianco
Copy link
Contributor Author

snbianco commented Nov 6, 2024

I made some changes in Catalogs.query_region to do parameter checking, so the issue in the description of #2109 should be fixed.

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! One remaining comment about validating params for query_region, too, otherwise it all looks good.

@@ -109,10 +110,18 @@ def query_region_async(self, coordinates, *, radius=0.2*u.deg, catalog="Hsc",
'dec': coordinates.dec.deg,
'radius': radius.deg}

# valid criteria keywords
valid_criteria = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but I would move this into the conditional as you only use it in the else part

# Determine API connection and service name
if catalog.lower() in self._service_api_connection.SERVICES:
self._current_connection = self._service_api_connection
service = catalog

# adding additional user specified parameters
for prop, value in criteria.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance to validate these, or there is way to large a scatter in what's allowed for each of these catalogs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the only service that runs through Catalogs.MAST (currently), and thus the service API connection, is PanSTARRS. I added Catalogs._get_service_col_config and Catalogs._validate_service_criteria to fetch the column metadata for PanSTARRS and check parameters.

@bsipocz bsipocz added this to the v0.4.8 milestone Nov 6, 2024
@snbianco
Copy link
Contributor Author

snbianco commented Nov 6, 2024

The last commit is a super quick add for getting cloud URIs of HLSPs!

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good now!

@bsipocz bsipocz merged commit e150df1 into astropy:main Nov 6, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants