-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Simplify coordinates.concatenate_representations()
#18477
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
base: main
Are you sure you want to change the base?
Simplify coordinates.concatenate_representations()
#18477
Conversation
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
||
if any( | ||
"s" not in r.differentials or type(r.differentials["s"]) != dif_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function already checked a few lines earlier that "s"
is in all r.differentials
and raised a ValueError
if that wasn't the case, so checking it again here was redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice simplification. Inline a suggestion for a further simplification - plus two nitpicks that you should feel free to ignore.
values = _concatenate_components( | ||
[r.differentials["s"] for r in reps], dif_type.attr_classes.keys() | ||
dif_type = type(differentials[0]) | ||
if any(type(differential) is not dif_type for differential in differentials): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not worth rerunning CI for, but could be ... in differentials[1:]
@@ -275,15 +275,17 @@ def get_constellation(coord, short_name=False, constellation_list="iau"): | |||
return names | |||
|
|||
|
|||
def _concatenate_components(reps_difs, names): | |||
def _concatenate_components(reps_difs, target_type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the change, but think when we go here anyway, we might as well make it even simpler by just using reps_difs[0].attr_classes
below and not pass in target_type
altogether.
In principle, could also do the check that all the classes are the same here, but then it would change the error message, so probably not worth it.
rep_type = type(reps[0]) | ||
if any(type(r) != rep_type for r in reps): | ||
if any(type(rep) is not rep_type for rep in reps): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do ... in reps[1:]
p.s. I forgot to mention: #18193 will replace |
Description
I am simplifying
coordinates.concatenate_representations()
. That functions makes use of the_concatenate_components()
function. Slightly expanding the private function allows removing some duplicated code fromconcatenate_representations()
, so that change is included here too.