Skip to content

Commit 2a3e753

Browse files
author
Carwyn Pelley
committed
BUG: Fixed bounds checking
closes #14
1 parent 569a92f commit 2a3e753

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

stratify/_vinterp.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ cdef class _Interpolation(object):
548548
# Compute the axis in absolute terms.
549549
fp_axis = (axis + fz_src.ndim) % fz_src.ndim
550550
zp_axis = fp_axis - (fz_src.ndim - z_src.ndim)
551-
if not 0 <= zp_axis < z_src.ndim or axis > z_src.ndim:
551+
if (not 0 <= zp_axis < z_src.ndim or axis > fz_src.ndim):
552552
raise ValueError('Axis {} out of range.'.format(axis))
553553

554554
# Ensure that fz_src's shape is a superset of z_src's.

stratify/tests/test_vinterp.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,24 @@ def test_inconsistent_shape(self):
339339
with self.assertRaisesRegexp(ValueError, emsg):
340340
vinterp._Interpolation([1, 3], data, zdata, axis=2)
341341

342-
def test_axis_out_of_bounds(self):
342+
def test_axis_out_of_bounds_fz_src_relative(self):
343+
# axis is out of bounds as identified by the absolute axis with z_src.
343344
data = np.empty([5, 4])
344345
zdata = np.empty([5, 4])
345346
axis = 4
346347
emsg = 'Axis {} out of range'
347348
with self.assertRaisesRegexp(ValueError, emsg.format(axis)):
348349
vinterp._Interpolation([1, 3], data, zdata, axis=axis)
349350

351+
def test_axis_out_of_bounds_z_src_absolute(self):
352+
# axis is out of bounds as identified by the relative axis with fz_src.
353+
data = np.empty([5, 4])
354+
zdata = np.empty([3, 5, 4])
355+
axis = 0
356+
emsg = 'Axis {} out of range'
357+
with self.assertRaisesRegexp(ValueError, emsg.format(axis)):
358+
vinterp._Interpolation([1, 3], data, zdata, axis=axis)
359+
350360
def test_nd_inconsistent_ndims(self):
351361
z_target = np.empty((2, 3, 4))
352362
z_src = np.empty((3, 4))

0 commit comments

Comments
 (0)