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

Feature simbad query tap #2856

Merged
merged 23 commits into from
Jan 26, 2024
Merged

Conversation

ManonMarchand
Copy link
Member

@ManonMarchand ManonMarchand commented Oct 19, 2023

Hello,

What this PR does

Add Simbad.query tap functionality to the simbad module. This is called like this:

from astroquery.simbad import Simbad
Simbad.query_tap("SELECT top 5 from ref")

This feature comes with helpers methods to explore SIMBAD's relational schema.

  • Simbad.list_tables() returns the public tables of SIMBAD
  • Simbad.list_columns(*args, keyword: str = None) returns the columns corresponding to the entry table(s) and with matches for the given keyword
  • Simbad.list_linked_tables(table: str) returns the non obvious (i.e. the columns don't have the same names) possible joins

Properties to connect to the tap endpoint:

  • Simbad.simbad_mirrors is a set of the two simbad's mirrors
  • Simbad.mirror takes the value of conf.server at instantiation but can be switched later
  • Simbad.tap is created from the current Simbad.mirror

And the private method

  • _adql_parameter
    that will be called when building adql queries from user inputs (to silently escape invalid characters and reserved sql vocabulary)

Documentation-wise

I took the liberty to add a graphviz graph of simbad's schema since sphinx-graphviz is already in the dependencies of sphinx-automodapi but we can remove it if needed.

The documentation on queries are now organized in a rough

  • everything about objects
  • everything about bibliography
  • queries that mix both
    This might need discussion too ?

That was also a lot of text and I'm not a native-english speaker, if someone has the time to point mistakes/unclear parts I'd love feedback.

Next steps

This PR only adds new methods. The rework to solve #1468 will be based on Simbad.query_tap and the two private functions introduced here.

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (885734b) 66.53% compared to head (f776ef8) 66.56%.
Report is 110 commits behind head on main.

❗ Current head f776ef8 differs from pull request most recent head ccf93cb. Consider uploading reports for the commit ccf93cb to get more accurate results

Files Patch % Lines
astroquery/simbad/core.py 80.64% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2856      +/-   ##
==========================================
+ Coverage   66.53%   66.56%   +0.03%     
==========================================
  Files         235      235              
  Lines       18114    18162      +48     
==========================================
+ Hits        12052    12090      +38     
- Misses       6062     6072      +10     

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

@ManonMarchand
Copy link
Member Author

From the oldest dependencies test, it looks like DALOverflowWarning was introduced in this commit astropy/pyvo@82ed24d in pyvo v1.4.2 should I avoid using it?

@pep8speaks
Copy link

pep8speaks commented Oct 19, 2023

Hello @ManonMarchand! 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 2024-01-26 16:41:53 UTC

@ManonMarchand ManonMarchand force-pushed the feature_Simbad_query_TAP branch 2 times, most recently from a9dce73 to 9d0abcb Compare October 19, 2023 14:22
@ManonMarchand
Copy link
Member Author

On the coverage, some lines are marked as missed but are tested in test_simbad_remote.py, is it normal?

@bsipocz
Copy link
Member

bsipocz commented Oct 19, 2023

Thank you so much! I'll try to get a timely review for this.

To answer the questions above:

On the coverage, some lines are marked as missed but are tested in test_simbad_remote.py, is it normal?

yes, do ignore the number here, its main purpose is to check whether there is a significant drop in coverage and we are aware that the actual percentage is most often larger when one includes the remote tests (I tend to run those numbers for significantly big PRs like this one as part of the review).

Re pyvo 1.4.2: that version is a bit too new to mandate as a minimum required version. Maybe you could do a try/except import and later a version dependent conditional?

@ManonMarchand
Copy link
Member Author

ManonMarchand commented Oct 20, 2023

I added the try/except clause for DALOverflowWarning 🙂

edit: the new failure does not seem related

@bsipocz bsipocz added this to the v0.4.7 milestone Nov 8, 2023
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 made a couple of comments while travelling, will come back for another fine combing before merging, but honestly I don't think anything else critical will be found.

astroquery/simbad/core.py Outdated Show resolved Hide resolved
astroquery/simbad/core.py Outdated Show resolved Hide resolved
astroquery/simbad/core.py Outdated Show resolved Hide resolved
astroquery/simbad/core.py Outdated Show resolved Hide resolved
astroquery/simbad/core.py Outdated Show resolved Hide resolved
astroquery/simbad/core.py Outdated Show resolved Hide resolved
astroquery/simbad/tests/test_simbad_remote.py Outdated Show resolved Hide resolved
docs/simbad/query_tap.rst Outdated Show resolved Hide resolved
docs/simbad/query_tap.rst Outdated Show resolved Hide resolved
@ManonMarchand ManonMarchand force-pushed the feature_Simbad_query_TAP branch 3 times, most recently from 16784cf to b86d6aa Compare November 9, 2023 14:01
@ManonMarchand
Copy link
Member Author

ManonMarchand commented Nov 9, 2023

Oups, I was squashing my commits and rebased too far sorry. I have no idea how to fix that

@bsipocz
Copy link
Member

bsipocz commented Nov 9, 2023

Oups, I was squashing my commits and rebased too far sorry. I have no idea how to fix that

I suspect you rebased on an outdated commit, rather than the freshly fetched main branch from the astropy/upstream remote.

@ManonMarchand
Copy link
Member Author

Will it be an issue when merging?

@bsipocz
Copy link
Member

bsipocz commented Nov 9, 2023

Will it be an issue when merging?

No, I'll do a rebase before merge ;)

@ManonMarchand
Copy link
Member Author

ManonMarchand commented Nov 10, 2023

I added caching on query_tap in today's commits (sorry for changing while you were reviewing). It only works when there are no uploaded tables in the query parameters since astropy tables are not hashable (and thus cannot be parameters in a function wrapped in lru_cache). I still think it can be very useful: uploaded tables are quite rare.

It also made me realize that there were no examples of uploaded table in the narrative docs so I made one up.

EDIT : and I'll stop changing stuff so that you can review, sorry again.

astroquery/simbad/core.py Outdated Show resolved Hide resolved
@bsipocz
Copy link
Member

bsipocz commented Nov 10, 2023

EDIT : and I'll stop changing stuff so that you can review, sorry again.

No worries, do add as many changes as you wish, you can always add the review label, or ping me when done and I'll come back then.

@ManonMarchand
Copy link
Member Author

No worries, do add as many changes as you wish, you can always add the review label, or ping me when done and I'll come back then.

All done :)

Copy link
Contributor

@keflavich keflavich left a comment

Choose a reason for hiding this comment

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

I have a couple nitpicky English comments, but this looks great and the documentation is super helpful.

docs/simbad/query_tap.rst Outdated Show resolved Hide resolved
docs/simbad/query_tap.rst Outdated Show resolved Hide resolved
docs/simbad/query_tap.rst Show resolved Hide resolved
docs/simbad/query_tap.rst Outdated Show resolved Hide resolved
docs/simbad/simbad.rst Outdated Show resolved Hide resolved
@ManonMarchand
Copy link
Member Author

All done for Adam comments

ManonMarchand and others added 19 commits January 26, 2024 10:49
SimbadClass.query_tap wraps the pyvo.dal.TAPService.run_async method. This commit also add the SimbadClass.simbad_mirrors and SimbadClass.tap attributes.
queries are now in three sections:

- objects-related queries

- bibliography-related queries

- mixed type queries
this commit also adds two private methods useful when building queries from users input: _adql_parameter and _adql_name.
we also add a graphviz file that represents a quick view of simbad's tables
list_columns now accept a 'keyword' keyword argument to filter the output columns

find_linked_tables is also renamed to list_linked_tables for homogenity
The caching decorator could not be applied for the uploaded tables because the astropy table objects are non-hashable. This implementation only caches calls without uploads as I could not find a workaround.
Co-authored-by: Adam Ginsburg <[email protected]>
@ManonMarchand
Copy link
Member Author

ManonMarchand commented Jan 26, 2024

I removed the _adql_name function because it didn't prove useful in the next steps of astroquery.simbad's refactoring.

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 @ManonMarchand, this should go in now.

@bsipocz bsipocz merged commit 1f3c12f into astropy:main Jan 26, 2024
7 of 8 checks passed
@ManonMarchand ManonMarchand deleted the feature_Simbad_query_TAP branch January 29, 2024 16:22
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.

5 participants