Skip to content

cosmo: comoving_transverse_distance(z1, z2) - #18803

Merged
nstarman merged 4 commits into
astropy:mainfrom
nstarman:cosmo/api/comoving_transverse_distance_z1_z2
Jul 13, 2026
Merged

nstarman merged 4 commits into
astropy:mainfrom
nstarman:cosmo/api/comoving_transverse_distance_z1_z2

Conversation

@nstarman

@nstarman nstarman commented Oct 30, 2025 •

Copy link
Copy Markdown
Member

Make the 2-argument form of comoving_transverse_distance public.

Requires #18800, #18807

  • 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.

@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?
  • 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.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@nstarman nstarman moved this from Triage to In Progress in Cosmology, the Expansion Oct 30, 2025
@nstarman
nstarman force-pushed the cosmo/api/comoving_transverse_distance_z1_z2 branch 2 times, most recently from b5a7998 to df807a5 Compare October 30, 2025 16:31
@nstarman
nstarman force-pushed the cosmo/api/comoving_transverse_distance_z1_z2 branch 2 times, most recently from 99bf161 to 1500054 Compare October 30, 2025 17:37
@nstarman
nstarman force-pushed the cosmo/api/comoving_transverse_distance_z1_z2 branch from 1500054 to 8194bc5 Compare November 16, 2025 18:30
@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Apr 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@nstarman nstarman added keep-open and removed Close? Tell stale bot that this issue/PR is stale labels Apr 20, 2026
@nstarman
nstarman force-pushed the cosmo/api/comoving_transverse_distance_z1_z2 branch 5 times, most recently from 099554e to 44efc73 Compare April 27, 2026 15:16
@nstarman
nstarman marked this pull request as ready for review April 27, 2026 15:58
@nstarman
nstarman requested a review from a team as a code owner April 27, 2026 15:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR makes FLRW.comoving_transverse_distance support the public 2-argument calling form (z1, z2), aligning it with existing 2-argument distance APIs in astropy.cosmology.

Changes:

  • Update FLRW.comoving_transverse_distance to accept an optional second redshift argument (z2) and implement the (z1, z2) behavior directly.
  • Update cosmology test suite to use the public 2-argument method instead of the former private helper.
  • Add a cosmology changelog fragment documenting the new capability.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
docs/changes/cosmology/18803.feature.rst Documents the new optional z2 argument for comoving_transverse_distance.
astropy/cosmology/_src/tests/funcs/test_funcs.py Switches round-trip tests to use the public 2-argument API.
astropy/cosmology/_src/tests/flrw/test_lambdacdm.py Updates transverse distance tests to call the public 2-argument API.
astropy/cosmology/_src/flrw/base.py Implements the optional-z2 signature and updates related call sites/docstrings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread astropy/cosmology/_src/flrw/base.py Resolved
Comment thread astropy/cosmology/_src/flrw/base.py Resolved
Comment thread astropy/cosmology/_src/flrw/base.py Resolved
Comment thread astropy/cosmology/_src/flrw/base.py Resolved
@nstarman

Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

@nstarman

Copy link
Copy Markdown
Member Author

@neutrinoceros, ready :)

@astrofrog astrofrog modified the milestones: v8.0.0, v8.1.0 May 5, 2026
@nstarman
nstarman force-pushed the cosmo/api/comoving_transverse_distance_z1_z2 branch from f023eb1 to 2b2170b Compare May 8, 2026 20:54
@nstarman

nstarman commented May 8, 2026 •

Copy link
Copy Markdown
Member Author

@neutrinoceros this PR simplifies the comoving_transverse_distance function stack while also enabling the 2-argument form.

Comment thread astropy/cosmology/_src/flrw/base.py Outdated
def comoving_transverse_distance(self, z: u.Quantity | ArrayLike, /) -> u.Quantity:
r"""Comoving transverse distance in Mpc at a given redshift.
def comoving_transverse_distance(
self, z: _InputT, z2: _InputT | None = None, /

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The annotations look either incorrect or at odds with how the arguments are actually handled. A type var implies that, as long as z2 != None, z2 and z1,always adhere to some common type (or interface); but then z1 is conditionally set to 0.0 (without any regard to z2's type).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think relaxing the type annotations to be _InputT | float should work. WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unioning a typevar seems like an antipattern to me: in most scenarios, it just kills the benefits from a typevar, and in the rare cases it might be correct, it still looks fishy enough that I'd rather avoid it to save mental bandwidth in readers.
What type checker (if any) are you using to check these ?

@nstarman nstarman May 22, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this case we always want to be able to accept floats. We also want to support higher types. What I think we want to discourage is a lot of type mixing.
I think that's a TypeVar|float.

I use mypy on Astropy and ty on pretty much everything else.

WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so TypeVar|float basically means "this can always be a float, but if it isn't then it needs to be consistent with other non-float variables that have this type" ? I think I get the intention but I'm not sure that type checkers understand this (or that it's supported by the spec). Do you have any source to back it up ? I'll play around with it and see what happens.

I use mypy on Astropy and ty on pretty much everything else.

Out of curiosity, I ran ty check astropy/cosmology and pyrefly check astropy/cosmology. ty seems to pick up many problems pyright does not, though I don't know wether they are real of false positives.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've fixed all errors to do with cosmoving_transverse_distance

ty check astropy/cosmology 2>&1 | grep -A 5 -B 5 "comoving_transverse_distance"

Comment thread astropy/cosmology/_src/flrw/base.py Resolved

@neutrinoceros neutrinoceros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorry for taking so long to reply. On paper this is perfectly fine to me. The only important thing to fix IMO are the type annotations.

@github-project-automation github-project-automation Bot moved this from In Progress to Review in progress in Cosmology, the Expansion May 21, 2026
@nstarman
nstarman force-pushed the cosmo/api/comoving_transverse_distance_z1_z2 branch from 2b2170b to ad9afdd Compare May 21, 2026 14:19
@nstarman
nstarman requested a review from neutrinoceros May 22, 2026 02:51
@nstarman

Copy link
Copy Markdown
Member Author

Ping @neutrinoceros for thoughts.

@nstarman

nstarman commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

@neutrinoceros all ty complaints about comoving_transverse_distance specifically are now fixed: ty check astropy/cosmology 2>&1 | grep -A 5 -B 5 "comoving_transverse_distance"

@nstarman
nstarman force-pushed the cosmo/api/comoving_transverse_distance_z1_z2 branch from e1b8e3c to 6689213 Compare July 6, 2026 19:36

@neutrinoceros neutrinoceros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only minor comments here. LGTM otherwise

Comment thread astropy/cosmology/_src/flrw/base.py Resolved

@pytest.mark.skipif(not HAS_SCIPY, reason="test requires scipy")
def test_comoving_transverse_distance_z1z2():
def test_comoving_transverse_distance():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I would actually keep the original test name here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I like the new name. Unified function w/ 2 args.

@github-project-automation github-project-automation Bot moved this from Review in progress to Reviewer approved in Cosmology, the Expansion Jul 8, 2026
@nstarman

Copy link
Copy Markdown
Member Author

Thanks @neutrinoceros for the reviews!

@nstarman

nstarman commented Jul 13, 2026 •

Copy link
Copy Markdown
Member Author

@neutrinoceros / @pllim can you confirm the CI failures are unrelated. Then I can bypass and merge. :) Thanks.

@neutrinoceros

Copy link
Copy Markdown
Contributor

I confirm. These are known failures unrelated to your PR.

@nstarman
nstarman merged commit 49f3dab into astropy:main Jul 13, 2026
36 of 39 checks passed
@nstarman
nstarman deleted the cosmo/api/comoving_transverse_distance_z1_z2 branch July 13, 2026 13:43
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in Cosmology, the Expansion Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants