Repository navigation
Stops using astropy's sanitize_slices - #995
Conversation
d1efe66 to
681b8b2
Compare
681b8b2 to
b2b76ab
Compare
alasdairwilson
left a comment
There was a problem hiding this comment.
Why adopt the code rather than calling the replacement with a version check on astropy?
|
|
yeah meant swap between sanitise slices and simplifiy_basic_index for pre and post 8.0.2 |
|
Oh, I didn't put two and two together. I will do that instead. |
b2b76ab to
4308e94
Compare
|
I made it worse. |
alasdairwilson
left a comment
There was a problem hiding this comment.
Since regular cube slicing rejects non‑unit steps, we should add that same guard to index_as_cube. Using that, slice.indices() returns (start, stop, step), and we only take the start and end (with [:2]) and drop the step before the per‑cube slices reach the cube‑level check. That means index_as_cube[::2] or even ::-1 will silently return every row.
Could you apply the same check step with item[common_axis].step != 1 before before calling slice.indices (and add tests for non unitary steps on index_as_cube)
I guess in #979 rather than here? Whatever you want. |
|
Well I want to make your life easier. Not mine. |
do it in 979 then and rebase this ontop |
7e63481 to
50a5ed2
Compare
|
Should be done now. |
|
@astrofrog , should we roll back deprecating sanitize_slices upstream? 🤔 |
|
|
||
|
|
||
| if minversion("astropy", "8.0.2"): | ||
| def sanitize_slices(slices, ndim): |
There was a problem hiding this comment.
Maybe keep the compat layer private so you don't have to deprecate it later? 🤣
|
We could also do what we did to |
|
@nabobalis would it be helpful if we hold back from introducing the deprecation until 9.0? |
|
Nah, I don't see the point. Ndcube has to handle it regardless as it does all this crazy slicing. I wouldn't block any astropy changes based on this. |
50a5ed2 to
2b90d37
Compare
2b90d37 to
5f8d58b
Compare
alasdairwilson
left a comment
There was a problem hiding this comment.
name it _sanitize_slices, and leave it out of all
5f8d58b to
8180030
Compare
8180030 to
7f38920
Compare
Vendors in the new simplify_basic_index for old versions of astropy
7f38920 to
5226695
Compare
|
I have largely re-written this to be a lot more sane. |
| import scipy.interpolate | ||
| except ImportError: | ||
| pass | ||
| from ndcube.utils.misc import simplify_basic_index |
There was a problem hiding this comment.
I still think this should be private?
| item = tuple(slice(*i.indices(n)[:2]) if isinstance(i, slice) else range(n)[i] | ||
| for i, n in zip(item, self.shape)) | ||
| # Drop the step: nested WCS slicing rejects an explicit step before astropy 7.2.3/8.0.2. | ||
| item = tuple(slice(i.start, i.stop) if isinstance(i, slice) else i for i in item) |
There was a problem hiding this comment.
If you want to avoid having removable code in multiple places, you could patch the vendored version of simplify_basic_index to change steps to None if they are 1, then you don't need this here since any step that is present is definitely not None or 1.
|
|
||
| # Slice cube. | ||
| item = tuple(sanitize_slices(item, len(self.shape))) | ||
| # TODO: Remove when astropy>7.2.3 |
There was a problem hiding this comment.
What does this refer to now the surrounding code has changed?
There was a problem hiding this comment.
The drop the step part below isn't needed once we have patched-astropy
| # Error early if a step is passed | ||
| if any(isinstance(i, slice) and i.step not in (None, 1) for i in item): | ||
| raise IndexError("Slicing WCS with a step is not supported.") |
PR Description
Closes #994.
astropy 8.0.2 reimplemented
sanitize_sliceswithsimplify_basic_index, which rejects a negative index when the shape is unknown, socube[:, -3:-1]raises (#994); astropy 8.1 deprecatessanitize_slices.AI Assistance Disclosure
AI tools were used for:
https://claude.ai/code/session_01TutVtk4wvj3M6PHKJLBbKe