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

Simplify simbad code #2494

Merged
merged 10 commits into from
Aug 17, 2022
Merged

Simplify simbad code #2494

merged 10 commits into from
Aug 17, 2022

Conversation

eerovaher
Copy link
Member

I have applied various small simplifications throughout astroquery/simbad/core.py. See the commit messages for details.

The wildcards allowed by `Simbad` are stored in a class constant
together with their descriptions. A separate constant that stored the
wildcards without the descriptions but in order had become unneccessary
because starting from Python 3.7 `dict` keys retain insertion order.
The local Boolean variable `vector` is checked in a few if- and
elif-statements, but it is guaranteed to be `True` and can therefore be
removed.
The removed function duplicated the functionality
`astropy.utils.isiterable()`.
The single use of the `copy` module has been replaced with calling
`list.copy()`.
`SimbadBibcodeResult.table` and `SimbadObjectIDsResult.table` have been
simplified. Most importantly they no longer construct the required
`Table` row-by-row because adding rows to a `Table` is expensive.
Various small simplifications throughout the module.
@codecov
Copy link

codecov bot commented Aug 16, 2022

Codecov Report

Merging #2494 (35b13ec) into main (902c758) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2494      +/-   ##
==========================================
- Coverage   62.90%   62.86%   -0.05%     
==========================================
  Files         133      133              
  Lines       17308    17276      -32     
==========================================
- Hits        10888    10860      -28     
+ Misses       6420     6416       -4     
Impacted Files Coverage Δ
astroquery/simbad/core.py 90.64% <100.00%> (-0.21%) ⬇️
astroquery/astrometry_net/core.py 47.64% <0.00%> (-0.83%) ⬇️
astroquery/esa/hubble/core.py 86.47% <0.00%> (+0.35%) ⬆️
astroquery/alma/core.py 43.35% <0.00%> (+0.55%) ⬆️

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

@bsipocz bsipocz added the simbad label Aug 17, 2022
@bsipocz bsipocz added this to the v0.4.7 milestone Aug 17, 2022
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.

There is is a bug in one of the scenarios (vector coords + string scalar radius), which is also a bug in the current main, but the refactoring should better fix it while rewriting the code.

print("{key} : {value}\n".format(key=key,
value=self.WILDCARDS[key]))
return
print("\n\n".join(f"{k} : {v}" for k, v in self.WILDCARDS.items()))
Copy link
Member

Choose a reason for hiding this comment

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

it's ok to keep it like this, but overall I value non-single-letter variables even when the intention is clear like in this line. (comment is for here and also for cases below)

elif vector and _has_length(radius) and len(radius) != len(ra):
raise ValueError("Mismatch between radii and coordinates")
elif vector and not _has_length(radius):
if isiterable(radius):
Copy link
Member

Choose a reason for hiding this comment

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

as I see at this point radius can still be a string, this would add a bug for a single string radius for a list of RA case. Maybe also add a test for that case? (as I see vector queries are totally missing from the local tests and for multicord tests only quantity scalar radius is being used for the remote tests)

@bsipocz
Copy link
Member

bsipocz commented Aug 17, 2022

Changelog entry will be needed for the bugfix part.

@bsipocz bsipocz added the bug label Aug 17, 2022
The new tests reveal a problem when radius is passed as a `str` and
multiple coordinates are specified.
It is now possible to specify multiple coordinates together with a
single radius as a `str`.
@eerovaher
Copy link
Member Author

I have fixed the bug and improved test coverage.

The new test asserts that the expected `ValueError` is raised if
multiple coordinates are specified together with an incompatible number
of radii.
@bsipocz
Copy link
Member

bsipocz commented Aug 17, 2022

Thanks, this is all good now!

@bsipocz bsipocz merged commit f0de9d4 into astropy:main Aug 17, 2022
@eerovaher eerovaher deleted the simbad-refractor branch August 17, 2022 22:11
ceb8 pushed a commit to orionlee/astroquery that referenced this pull request Sep 27, 2022
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.

None yet

2 participants