Skip to content

Commit dc7a210

Browse files
authored
Merge pull request astropy#16559 from meeseeksmachine/auto-backport-of-pr-16544-on-v6.1.x
Backport PR astropy#16544 on branch v6.1.x (Fix bug in overlap_slices)
2 parents 6e9699c + da17f0e commit dc7a210

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

astropy/nddata/tests/test_utils.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
subsampling = 5
4646

47-
test_pos_bad = [(-1, -4), (-2, 0), (6, 2), (6, 6)]
4847
test_nonfinite_positions = [
4948
(np.nan, np.nan),
5049
(np.inf, np.inf),
@@ -67,11 +66,23 @@ def test_slices_pos_different_dim():
6766
overlap_slices((4, 5), (1, 2), (0, 0, 3))
6867

6968

70-
@pytest.mark.parametrize("pos", test_pos_bad)
71-
def test_slices_no_overlap(pos):
69+
@pytest.mark.parametrize(
70+
"inputs",
71+
[
72+
((5, 5), (2, 2), (-1, -4)),
73+
((5, 5), (2, 2), (-2, -0)),
74+
((5, 5), (2, 2), (6, 2)),
75+
((5, 5), (2, 2), (6, 6)),
76+
((7, 7), (0, 0), (-2, -2)),
77+
((7, 7), (3, 3), (-2, -2)),
78+
((7, 7), (3, 3), (-2, 2)),
79+
((7, 7), (3, 3), (2, -2)),
80+
],
81+
)
82+
def test_slices_no_overlap(inputs):
7283
"""If there is no overlap between arrays, an error should be raised."""
7384
with pytest.raises(NoOverlapError):
74-
overlap_slices((5, 5), (2, 2), pos)
85+
overlap_slices(*inputs)
7586

7687

7788
def test_slices_partial_overlap():

astropy/nddata/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def overlap_slices(large_array_shape, small_array_shape, position, mode="partial
115115
]
116116

117117
for e_max in indices_max:
118-
if e_max < 0:
118+
if e_max < 0 or (e_max == 0 and small_array_shape != (0, 0)):
119119
raise NoOverlapError("Arrays do not overlap.")
120120
for e_min, large_shape in zip(indices_min, large_array_shape):
121121
if e_min >= large_shape:

docs/changes/utils/16544.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed an edge-case bug in ``overlap_slices`` where the function could
2+
return an empty slice for non-overlapping slices.

0 commit comments

Comments
 (0)