Skip to content

BUG: allow step=1 in combine_slices for nested SlicedLowLevelWCS - #20488

Open
wahajahmed010 wants to merge 1 commit into
astropy:mainfrom
wahajahmed010:fix/20487-sliced-wcs-step-1
Open

wahajahmed010 wants to merge 1 commit into
astropy:mainfrom
wahajahmed010:fix/20487-sliced-wcs-step-1

Conversation

@wahajahmed010

Copy link
Copy Markdown

Fixes #20487

Description

SlicedLowLevelWCS accepts an explicit step=1 on the first slice because sanitize_slices already treats step=1 like step=None (see sanitize_slices in astropy/wcs/wcsapi/wrappers/sliced_wcs.py). However, the chained-slice code path calls combine_slices again, which rejects any non-None step — including the case where the first slice stored step=1 or the new slice uses step=1.

The result is a confusing ValueError("Only slices with steps of 1 are supported") for code like:

SlicedLowLevelWCS(
    SlicedLowLevelWCS(wcs, [slice(0, 2, 1)]),
    [slice(1, None)]
)

This PR makes combine_slices accept step=1 in either argument, matching the contract already enforced by sanitize_slices. Any other step (e.g. 2) is still rejected.

Changes

  • astropy/wcs/wcsapi/wrappers/sliced_wcs.py: relax the early step guard in combine_slices to also allow step == 1, normalize slice(..., step=1) to slice(..., step=None) up front, and document the behavior in the docstring.
  • astropy/wcs/wcsapi/wrappers/tests/test_sliced_wcs.py: append 8 new parametrized regression cases to the existing test_combine_slices table covering the pairs from the issue reproduction.
  • docs/changes/wcs/20487.bugfix.rst: changelog entry following the repository's fragment convention.

AI Disclosure

This PR was prepared with AI assistance. The code change was drafted by an LLM (ollama/minimax-m3, acting as the implementation subagent) and verified offline against the existing parametrized cases in test_combine_slices plus 8 new regression cases (28/28 pass, rejection of non-1 steps is preserved). The final patch was reviewed and applied by the human contributor.

sanitize_slices already accepts an explicit step of 1 on the first slice,
but combine_slices raises "Only slices with steps of 1 are supported" for
ANY non-None step, including 1. As a result, slicing a SlicedLowLevelWCS a
second time with step=1 (or storing step=1 in the first slice and slicing
again) raises, even though semantically step=1 is identical to the default
step=None.

Normalize step=1 to step=None at the top of combine_slices and accept it in
the existing step checks. Errors for non-1, non-None steps are preserved.

Closes astropy#20487
@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.

@pllim pllim added this to the v8.1.0 milestone Sep 28, 2026

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

Minor comment below, but looks good to me otherwise, will approve once this is implemented.

if isinstance(slice1, slice) and slice1.step == 1:
slice1 = slice(slice1.start, slice1.stop)
if isinstance(slice2, slice) and slice2.step == 1:
slice2 = slice(slice2.start, slice2.stop)

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.

I think this block could actually be moved up to just after the docstring and then the other code changes (adding and sliceN.step != 1) might not be needed

This branch has not been deployed

No deployments
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.

SlicedLowLevelWCS rejects an explicit step of 1 when slicing a sliced WCS

3 participants