Skip to content

Correction to frame standardization - #704

Merged
larrybradley merged 7 commits into
astropy:mainfrom
sedonaprice:bugfix-range-frame-standardization
Sep 23, 2026
Merged

larrybradley merged 7 commits into
astropy:mainfrom
sedonaprice:bugfix-range-frame-standardization

Conversation

@sedonaprice

Copy link
Copy Markdown
Contributor

Fixes #703.

Changes the method SphericalSkyRegion._standardize_frame(), to return an instance, not a frame, and to first check if the frame is already an instance of BaseCoordinateFrame.

Test case for that issue now works as expected:

from astropy import units as u
from regions import RangeSphericalSkyRegion

reg1 = RangeSphericalSkyRegion(
    frame="icrs",
    latitude_range=[0 * u.deg, 1 * u.deg],
)
reg2 = RangeSphericalSkyRegion(
    frame="icrs",
    latitude_range=[0.5 * u.deg, 1.5 * u.deg],
)
reg1 & reg2

returns

<CompoundSphericalSkyRegion(region1=Region: RangeSphericalSkyRegion
frame: icrs
longitude_range: None
latitude_range: [<Quantity 0. deg>, <Quantity 1. deg>], region2=Region: RangeSphericalSkyRegion
frame: icrs
longitude_range: None
latitude_range: [<Quantity 0.5 deg>, <Quantity 1.5 deg>], operator=<built-in function and_>)>

sedonaprice and others added 3 commits September 4, 2026 16:31
Change to return an instance, not a frame, and to check if the frame is already an instance of BaseCoordinateFrame.

@larrybradley larrybradley 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.

Thanks, @sedonaprice. The fix looks good. However, this PR needs a regression test for the bug being fixed.

(I also pushed a small fix to your branch).

Comment thread CHANGES.rst Outdated
@larrybradley larrybradley added this to the 0.13 milestone Sep 9, 2026
sedonaprice and others added 4 commits September 9, 2026 13:39
Co-authored-by: Larry Bradley <larry.bradley@gmail.com>
Move from function test_compound_spherical_sky to class TestCompoundSphericalSky, to make addition of regression tests more clear.
- Test of compound range region successful creation and has frame expected.
- Add test of all region types to confirm behavior for range and other spherical shapes (so long as the frame is defined; eg, not for WholeSphericalSkyRegion).
- Ad hoc correction to access `reg1.frame`, not `reg1._frame` in range test, preferring public attribute
@sedonaprice

Copy link
Copy Markdown
Contributor Author

@larrybradley Regression tests added (after a compound spherical sky test refactor as an independent commit, enabling more clear demarcation of the regression test).

The regression test I added for confirming the frame is standardized as expected for all shapes needed a carveout for WholeSphericalSkyRegion. Another option would be to do a minor refactor to introduce a "frame" for a WholeSphericalSkyRegion class. This would have a couple of benefits: (a) consistent behavior with the other region "shapes" (for tests), (b) opportunity for sanity checks (can the whole sky be transformed to X frame?). Something to consider for a different PR.

@larrybradley larrybradley 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! Thanks, @sedonaprice.

@larrybradley
larrybradley merged commit 440dc9c into astropy:main Sep 23, 2026
26 checks passed
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.

BUG: RangeSphericalSkyRegion frame isn't correct, so compound regions with range fail

2 participants