ITADN

test_resample fails with scipy 1.16

#1428Opendrew-parsons 创建于 2025-08-16
D
drew-parsonscommented
nibabel is failing tests using scipy 1.16 on debian CI infrastructure, https://ci.debian.net/packages/n/nibabel/ (tests with scipy 1.16 are reported under the `unstable` links). The bug was reported to Debian at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1109953 The failing tests are ``` 176s FAILED nibabel/tests/test_processing.py::test_resample_from_to - Failed: DID ... 176s FAILED nibabel/tests/test_processing.py::test_resample_to_output - Failed: DI... 176s = 2 failed, 5362 passed, 108 skipped, 11 xfailed, 1 xpassed, 26950 warnings in 137.68s (0:02:17) = ``` It looks like it might be a problem with API changes. The error is ``` 176s ___________________________ test_resample_to_output ____________________________ 176s 176s caplog = <_pytest.logging.LogCaptureFixture object at 0x7fb89afd3110> 176s 176s @needs_scipy 176s def test_resample_to_output(caplog): 176s # Test routine to sample images to output space 176s # Image aligned to output axes - no-op 176s data = np.arange(24, dtype='int32').reshape((2, 3, 4)) 176s img = Nifti1Image(data, np.eye(4)) 176s # Check default resampling 176s img2 = resample_to_output(img) 176s assert_array_equal(img2.shape, (2, 3, 4)) 176s assert_array_equal(img2.affine, np.eye(4)) 176s assert_array_equal(img2.dataobj, data) 176s # Check resampling with different voxel size specifications 176s for vox_sizes in (None, 1, [1, 1, 1]): 176s img2 = resample_to_output(img, vox_sizes) 176s assert_array_equal(img2.shape, (2, 3, 4)) 176s assert_array_equal(img2.affine, np.eye(4)) 176s assert_array_equal(img2.dataobj, data) 176s img2 = resample_to_output(img, vox_sizes) 176s # Check 2D works 176s img_2d = Nifti1Image(data[0], np.eye(4)) 176s for vox_sizes in (None, 1, (1, 1), (1, 1, 1)): 176s img3 = resample_to_output(img_2d, vox_sizes) 176s assert_array_equal(img3.shape, (3, 4, 1)) 176s assert_array_equal(img3.affine, np.eye(4)) 176s assert_array_equal(img3.dataobj, data[0][..., None]) 176s # Even 1D 176s img_1d = Nifti1Image(data[0, 0], np.eye(4)) 176s img3 = resample_to_output(img_1d) 176s assert_array_equal(img3.shape, (4, 1, 1)) 176s assert_array_equal(img3.affine, np.eye(4)) 176s assert_array_equal(img3.dataobj, data[0, 0][..., None, None]) 176s # But 4D does not 176s img_4d = Nifti1Image(data.reshape(2, 3, 2, 2), np.eye(4)) 176s with pytest.raises(ValueError): 176s resample_to_output(img_4d) 176s # Run vox2vox_out tests, checking output shape, coordinate transform 176s for in_shape, in_aff, vox, out_shape, out_aff in get_outspace_params(): 176s # Allow for expansion of image shape from < 3D 176s in_n_dim = len(in_shape) 176s if in_n_dim < 3: 176s in_shape = in_shape + (1,) * (3 - in_n_dim) 176s if not vox is None: 176s vox = vox + (1,) * (3 - in_n_dim) 176s assert len(out_shape) == in_n_dim 176s out_shape = out_shape + (1,) * (3 - in_n_dim) 176s img = Nifti1Image(np.ones(in_shape), in_aff) 176s out_img = resample_to_output(img, vox) 176s assert_all_in(in_shape, in_aff, out_img.shape, out_img.affine) 176s assert out_img.shape == out_shape 176s assert_almost_equal(out_img.affine, out_aff) 176s # Check data is as expected with some transforms 176s # Flip first axis 176s out_img = resample_to_output(Nifti1Image(data, np.diag([-1, 1, 1, 1]))) 176s assert_array_equal(out_img.dataobj, np.flipud(data)) 176s # Subsample voxels 176s out_img = resample_to_output(Nifti1Image(data, np.diag([4, 5, 6, 1]))) 176s > with pytest.warns(UserWarning): # Suppress scipy warning 176s E Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. 176s E Emitted warnings: []. 176s 176s nibabel/tests/test_processing.py:278: Failed ``` Full test log at https://ci.debian.net/data/autopkgtest/unstable/amd64/n/nibabel/63127756/log.gz These tests were run with scipy 1.16.0, not the more recent 1.16.1.
0 条评论