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

Add flexible parameters to criteria #1659

Merged

Conversation

olyoberdorf
Copy link

This enhances query_criteria to allow additional arguments to pass through to the raw query. This enables users to call the helper method (query_criteria) but still have access to any new or less common parameters in the webservice.

#1658

@pep8speaks
Copy link

pep8speaks commented Feb 28, 2020

Hello @olyoberdorf! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-03-03 00:09:31 UTC

@astropy-bot astropy-bot bot added the gemini label Feb 28, 2020
@bsipocz bsipocz added this to the v0.4.1 milestone Feb 28, 2020
@@ -156,9 +156,10 @@ def query_object(self, objectname, radius=0.3*units.deg):
return self.query_criteria(objectname=objectname, radius=radius)

@class_or_instance
def query_criteria(self, coordinates=None, radius=0.3*units.deg, pi_name=None, program_id=None, utc_date=None,
def query_criteria(self, *args, coordinates=None, radius=0.3*units.deg, pi_name=None, program_id=None, utc_date=None,
Copy link
Member

Choose a reason for hiding this comment

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

This is an API break, users could have used the kwargs as positional args before, and those will fails with then new added *args. So I would suggest to add it to the end as a new keyword, e.g. rawqueryargs (well, something more sensible, than this)

Copy link
Author

Choose a reason for hiding this comment

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

I've renamed them with the rawquery name prefix and moved args to the back. I ended up putting orderby sandwiched between them to prevent people using it via position. I didn't want future search terms to result in orderby sitting in the middle of the positonal args list.

Prior, orderby was being picked up by the *args, so the explicit add and handling is really just making the signature match the docs.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. We could also switch to keyword only args, definitely in the next refactoring release, but given the gemini module is relatively new, if you want you can make that change any time you wish.

@@ -252,6 +253,17 @@ def query_criteria(self, coordinates=None, radius=0.3*units.deg, pi_name=None, p
'PROCESSED_FLAT',
'PROCESSED_FRINGE',
'PROCESSED_ARC'
orderby : str, optional
Copy link
Member

Choose a reason for hiding this comment

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

this is not in the signature

Copy link
Author

Choose a reason for hiding this comment

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

per above, made it explicit in the signature

@@ -343,7 +371,9 @@ def query_raw(self, *args, **kwargs):
The list of parameters to be passed via the query path to the webserver
kwargs :
The dictionary of parameters to be passed by name=value within the query
path to the webserver
path to the webserver. The `orderby` key value pair has a special
Copy link
Member

Choose a reason for hiding this comment

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

use double backticks. sphinx will try to convert single ones to links and fails to do it for any parameters

Copy link
Author

Choose a reason for hiding this comment

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

done

def test_observations_query_region(self):
""" test query against a region of the sky against actual archive """
result = gemini.Observations.query_region(coords, radius=0.3 * units.deg)
assert isinstance(result, Table)
Copy link
Member

Choose a reason for hiding this comment

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

some check on the content of the Table would be nice in the tests, just to make sure data is returned rather than an empty table (which is the default behaviour for a nonsensical query, if I see correctly)

Copy link
Author

Choose a reason for hiding this comment

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

I've added a length > 0 check. That is still pretty naive but at least it will prevent the default causing a false pass.

docs/gemini/gemini.rst Outdated Show resolved Hide resolved
@@ -83,6 +83,20 @@ and the program ID. For a complete list of available search fields, see
0.0 Full Frame -- Gemini-North True ...
0.0 Full Frame -- Gemini-North True ...

In addition, the criteria query can accept additional parameters via the `args` and `kwargs` optional parameters.
Copy link
Member

Choose a reason for hiding this comment

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

double backticks

Copy link
Member

Choose a reason for hiding this comment

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

also, might be nice to have another extra example with passing in the kwargs

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Author

Choose a reason for hiding this comment

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

also, might be nice to have another extra example with passing in the kwargs

I missed this but made a note of it for next time

@bsipocz
Copy link
Member

bsipocz commented Feb 28, 2020

Some minor comments, otherwise this looks good.

@olyoberdorf - could you also rebase to get rid of the merge commit?

@olyoberdorf
Copy link
Author

olyoberdorf commented Mar 2, 2020

Some minor comments, otherwise this looks good.

@olyoberdorf - could you also rebase to get rid of the merge commit?

Thanks for looking so quickly - I will make those edits and rebase and post back.

@olyoberdorf olyoberdorf force-pushed the add_flexible_parameters_to_criteria branch 2 times, most recently from 409fd93 to d7b8e43 Compare March 2, 2020 21:49
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.

I could spot these two more cases of single vs double backtick usage. Otherwise once CI is all green this is ready to go in.

@@ -252,18 +255,45 @@ def query_criteria(self, coordinates=None, radius=0.3*units.deg, pi_name=None, p
'PROCESSED_FLAT',
'PROCESSED_FRINGE',
'PROCESSED_ARC'
orderby : str, optional
Indicates how the results should be sorted. Values should be like the ones used
in the archive website when sorting a column. For example, `data_label_desc` would
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
in the archive website when sorting a column. For example, `data_label_desc` would
in the archive website when sorting a column. For example, ``data_label_desc`` would

Copy link
Author

Choose a reason for hiding this comment

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

done

In addition, the criteria query can accept additional parameters via the ``*rawqueryargs`` and ``**rawquerykwargs``
optional parameters.

The `orderby` parameter can be used to pass the desired sort order.
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
The `orderby` parameter can be used to pass the desired sort order.
The ``orderby`` parameter can be used to pass the desired sort order.

Copy link
Author

Choose a reason for hiding this comment

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

done

…ria to be passed down to the URL

Added support for ordering results via orderby parameter (properly used as URL query argument)
fixed documentation to latest tweaks for added criteria query args and sort order
Changelog entry for Gemini enhancements
alphabetizing my changelog entry by module name
tagging tests as remote
@olyoberdorf olyoberdorf force-pushed the add_flexible_parameters_to_criteria branch from d7b8e43 to 491b2a3 Compare March 3, 2020 00:09
@bsipocz bsipocz merged commit f452576 into astropy:master Mar 4, 2020
@bsipocz
Copy link
Member

bsipocz commented Mar 4, 2020

Thanks @olyoberdorf!

@olyoberdorf olyoberdorf deleted the add_flexible_parameters_to_criteria branch May 4, 2020 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants