Skip to content

Allow the use of Distribution in Representations and SkyCoord - #15395

Merged
mhvk merged 5 commits into
astropy:mainfrom
mhvk:distribution-representations
Oct 3, 2023
Merged

mhvk merged 5 commits into
astropy:mainfrom
mhvk:distribution-representations

Conversation

@mhvk

@mhvk mhvk commented Sep 27, 2023

Copy link
Copy Markdown
Contributor

This pull request is updates the Distribution class to allow it to be used inside representations. After the PRs to get things to work with EarthLocation, the changes here are rather minimal: support concatenate and a small fix in how broadcast_arrays is dealt with (plus a very small change in registration of representations, just for the tests to work more easily); the bulk of this PR is extra tests.

Note that the support is not yet complete. E.g., the way representations do __repr__ means that the repr gives no sign that distributions are used. I think the best way to fix this, though, is through support of array2string for representations, which is a bit beyond what I can do here (similarly, Distribution.__repr__ should go via array2string so that one can indicate what are the samples more easily). There perhaps also is a more general question of whether things like SkyCoord should just allow Distribution to be used, or whether they should also gain a .distribution property.

Anyway, I think it makes sense to proceed in small steps, so just go with what is here first...

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@mhvk mhvk added this to the v6.0 milestone Sep 27, 2023
@mhvk
mhvk requested review from eteq and nstarman September 27, 2023 13:25
@github-actions

Copy link
Copy Markdown
Contributor

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.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@mhvk
mhvk force-pushed the distribution-representations branch from b4521d2 to 1e04dcc Compare September 27, 2023 13:26

@nstarman nstarman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's wonderful how few changes are actually required!

if cls.__name__ == "BaseRepresentation":
# Register representation name (except for bases on which other representations
# are built, but which cannot themselves be used).
if cls.__name__.startswith("Base"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is good given the current check, but it would be nice to have a check not based on strings but on e.g. if the class is abstract.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed that this is not a very nice heuristic... But for another time!

Comment thread astropy/uncertainty/core.py Resolved
Comment thread astropy/uncertainty/core.py Resolved
Comment thread astropy/uncertainty/function_helpers.py Resolved
Also adjust broadcast_arrays to ensure that regular arrays are
not turned into Distribution after broadcasting.
@mhvk
mhvk force-pushed the distribution-representations branch from 1e04dcc to 446bbb5 Compare September 27, 2023 16:22
@mhvk
mhvk force-pushed the distribution-representations branch from 446bbb5 to 9de420c Compare September 27, 2023 17:58

@nstarman nstarman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! I like the code / test ratio.
We've identified some things for followup, so this PR is ready.
Probably want other Coordinates maintainers to OK this?

@mhvk

mhvk commented Oct 1, 2023

Copy link
Copy Markdown
Contributor Author

Thanks! I asked @eteq offline for a quick review, as the other uncertainty maintainer. Though I think you've covered it, thanks!!

@pllim

pllim commented Oct 3, 2023

Copy link
Copy Markdown
Member

@mhvk , I'll leave it to your discretion on when to merge then. But I would advise against waiting till the last minute before feature freeze.

@mhvk
mhvk merged commit 4ac37c7 into astropy:main Oct 3, 2023
@mhvk

mhvk commented Oct 3, 2023

Copy link
Copy Markdown
Contributor Author

Thanks, all, merged!

@mhvk
mhvk deleted the distribution-representations branch October 3, 2023 20:57
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