Skip to content

Conversation

keflavich
Copy link
Contributor

Splatalogue was modified to accept only keyword-specified arguments, but Splatalogue.query_lines() is not valid. Currently, all of the docs have invalid examples as a result. This simple modification fixes the problem. The standard usage is, and should be:

Splatalogue.query_lines(min_frequency, max_frequency)

the alternative, which is presently being enforced, should be optional:

Splatalogue.query_lines(min_frequency=min_frequency, max_frequency=max_frequency)

There's another optional approach that is supported either way:

Splatalogue.query_lines(band='alma3')

@codecov
Copy link

codecov bot commented Mar 31, 2023

Codecov Report

Merging #2696 (8c24bb6) into main (529721b) will increase coverage by 0.00%.
The diff coverage is 87.50%.

@@           Coverage Diff           @@
##             main    #2696   +/-   ##
=======================================
  Coverage   65.73%   65.74%           
=======================================
  Files         233      233           
  Lines       17842    17844    +2     
=======================================
+ Hits        11729    11732    +3     
+ Misses       6113     6112    -1     
Impacted Files Coverage Δ
astroquery/splatalogue/load_species_table.py 89.47% <0.00%> (ø)
astroquery/splatalogue/core.py 87.82% <100.00%> (+0.80%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@bsipocz
Copy link
Member

bsipocz commented Mar 31, 2023

Hmm, the docs still has the doctest-skip-all, thus we haven't notice this before.

Why do you feel strongly against requiring being explicit? E.g. in practice all the parameters are optional as you either need the min/max or the bandname, so just assuming that if two are given they would be min/max is not exactly great.

So, what about updating the docs instead, and enabling remote testing on it?

@keflavich
Copy link
Contributor Author

The band name should be regarded as optional, imo, and the min/max frequency should not. They are only technically optional, in the literal sense of a query can be executed without raising an immediate error if you give a band name. You cannot execute successful queries without providing either a tight pair of frequencies or a band name plus a chemical name.

This is a module I'm intimately familiar with, and I believe Splatalogue.query_lines(1*u.GHz, 2*u.GHz) is both the most common and most appropriate pattern. I'd be much happier deprecating/blocking the 'band' query and making min_frequency, max_frequency required non-keyword arguments than leaving the module as is. query_lines(minfreq, maxfreq) is much closer in spirit to query_object(name) or query_region(coordinates) than it is to a generic query(**kwargs) function.

I did some searching for use cases on github, too, and all uses I saw (that were not astroquery clones or my own test cases....) use positional arguments.

https://github.com/search?p=4&q=splatalogue.query_lines&type=Code

That said, I do think we should update the docs to use explicit keywords in all examples.

@keflavich
Copy link
Contributor Author

I don't understand the readthedocs failure. I'm not sure if it's related or not; the traceback makes no sense.

@keflavich
Copy link
Contributor Author

The error messages were nonsense, but were caused by doubling up sphinx block directives

@bsipocz
Copy link
Member

bsipocz commented Apr 3, 2023

The error messages were nonsense, but were caused by doubling up sphinx block directives

Interesting, this never caused an issue before, the doubling up just caused an ugly rendering.

@keflavich
Copy link
Contributor Author

Maybe it was because I put them on consecutive lines? The message never told me what I was doing was wrong specifically, but it caused errors in every other module.

@bsipocz
Copy link
Member

bsipocz commented Apr 3, 2023

We had them in consecutive lines in all the other PRs that were opted in for the testing, but most of those was a while ago and likely used older sphinx. I haven't checked, but it might become more strict. Anyway, I'm glad you find the fix.

@bsipocz
Copy link
Member

bsipocz commented Apr 3, 2023

This is a module I'm intimately familiar with, and I believe Splatalogue.query_lines(1u.GHz, 2u.GHz) is both the most common and most appropriate pattern. I'd be much happier deprecating/blocking the 'band' query and making min_frequency, max_frequency required non-keyword arguments than leaving the module as is. query_lines(minfreq, maxfreq) is much closer in spirit to query_object(name) or query_region(coordinates) than it is to a generic query(**kwargs) function.

OK. I still don't like it from the pure API design POV, but could live with the two positional arguments. I would not think making them mandatory would make things better, the band kward feels very useful.

@keflavich
Copy link
Contributor Author

The main change in this PR is this one:

def query_lines_async(self, min_frequency=None, max_frequency=None, *,

so I kept the arguments as optional positional arguments.

I also made regex_str:

def get_species_ids(self, regex_str=None, *, reflags=0, recache=False):

a positional argument, since the intent of that function is to search.

Otherwise, this is all documentation fixes. It's ready for review.

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.

OK, some more comments. The main blocker is the kwarg rename, it should be done with a deprecation decorator.

And please add a changelog about the rename, too.

def get_species_ids(self, *, restr=None, reflags=0, recache=False):
def get_species_ids(self, regex_str=None, *, reflags=0, recache=False):
Copy link
Member

Choose a reason for hiding this comment

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

This renaming of an arg is an API change that has to be done with the deprecation decorator. Unless restr was added since 0.4.6.

Copy link
Member

Choose a reason for hiding this comment

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

and if rename happens, you may want to use a name that's more informative. Maybe species_regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'm willing to abandon that. restr wasn't great, it was just short. It... kind of was never intended to be a kwarg, just an internal required positional variable.

Copy link
Member

Choose a reason for hiding this comment

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

haha, good reminder that internal stuff should be named well, too. Or at least the stuff that ends up in signatures and docstrings.
I'm happy to push commits to this, but it will need to wait until at least the evening.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I will revisit this when I can; may not be this evening either

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed the variable, but I still prefer to keep it as a positional argument. I added the deprecation warning.

@@ -66,10 +66,12 @@ def species_lookuptable(*, filename='splat-species.json', recache=False):
# check to see if the file exists; if not, we run the
# scraping routine
if recache or not os.path.isfile(file_cache):
species = get_json_species_ids(filename)
species = get_json_species_ids(outfile=filename)
Copy link
Member

Choose a reason for hiding this comment

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

there are some patchy test coverage around this load/build methods, and even __main__, so would be nice to clean up that, too (can be done separately, I've just spotted it now).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, agreed - I already expanded test coverage a bit, I think? but, some stuff is still not caught

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've not done anything with this but suggest we merge anyway.

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.

More comments regarding the documentation, basically the asserts should go, but otherwise things are looking good.

@@ -1,5 +1,3 @@
.. doctest-skip-all
Copy link
Member

Choose a reason for hiding this comment

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

Interesting why the examples work in this without remote-data? Would it make sense to make it opt-out to use the shipped json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Many of them are labeled remote-data; only a couple work without it.

@keflavich
Copy link
Contributor Author

@bsipocz any idea what's going on with the dev deps build? Looks like pyvo and codecov don't get along?

@bsipocz
Copy link
Member

bsipocz commented Apr 12, 2023

any idea what's going on with the dev deps build? Looks like pyvo and codecov don't get along?

Ahh, so codecov actually bite us. cc @pllim
I'll fix this separately.

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.

When CI is all clean, this is good to go.

@bsipocz bsipocz merged commit ac341f3 into astropy:main Apr 13, 2023
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.

2 participants