Skip to content

Commit

Permalink
Fix test failures for NumPy 2.0+ (#155)
Browse files Browse the repository at this point in the history
Migrate from np.NaN to np.nan. The former was removed in NumPy >2
  • Loading branch information
addisonElliott authored Oct 11, 2024
1 parent 52e9e37 commit 40f49c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions nrrd/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_format_optional_vector(self):
self.assertEqual(nrrd.format_optional_vector(np.array([1.2, 2., 3.2])), '(1.2,2,3.2000000000000002)')

self.assertEqual(nrrd.format_optional_vector(None), 'none')
self.assertEqual(nrrd.format_optional_vector(np.array([np.NaN, np.NaN, np.NaN])), 'none')
self.assertEqual(nrrd.format_optional_vector([np.NaN, np.NaN, np.NaN]), 'none')
self.assertEqual(nrrd.format_optional_vector(np.array([np.nan, np.nan, np.nan])), 'none')
self.assertEqual(nrrd.format_optional_vector([np.nan, np.nan, np.nan]), 'none')

def test_format_matrix(self):
self.assertEqual(nrrd.format_matrix(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])), '(1,2,3) (4,5,6) (7,8,9)')
Expand Down Expand Up @@ -77,10 +77,10 @@ def test_format_optional_matrix(self):
'(7.7000000000000002,8.8000000000000007,9.9000000000000004)')

self.assertEqual(nrrd.format_optional_matrix(np.array([
[np.NaN, np.NaN, np.NaN], [1, 2, 3], [4, 5, 6], [7, 8, 9]])),
[np.nan, np.nan, np.nan], [1, 2, 3], [4, 5, 6], [7, 8, 9]])),
'none (1,2,3) (4,5,6) (7,8,9)')
self.assertEqual(nrrd.format_optional_matrix(np.array([
[1, 2, 3], [np.NaN, np.NaN, np.NaN], [4, 5, 6], [7, 8, 9]])),
[1, 2, 3], [np.nan, np.nan, np.nan], [4, 5, 6], [7, 8, 9]])),
'(1,2,3) none (4,5,6) (7,8,9)')

def test_format_number_list(self):
Expand Down
4 changes: 2 additions & 2 deletions nrrd/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ def test_parse_optional_matrix(self):

self.assert_equal_with_datatype(nrrd.parse_optional_matrix(
'none (1.4726600000000003,-0,0) (-0,1.4726600000000003,-0) (0,-0,4.7619115092114601)'),
[[np.NaN, np.NaN, np.NaN], [1.4726600000000003, 0, 0], [0, 1.4726600000000003, 0],
[[np.nan, np.nan, np.nan], [1.4726600000000003, 0, 0], [0, 1.4726600000000003, 0],
[0, 0, 4.7619115092114601]])

self.assert_equal_with_datatype(nrrd.parse_optional_matrix(
'(1.4726600000000003,-0,0) none (-0,1.4726600000000003,-0) (0,-0,4.7619115092114601)'),
[[1.4726600000000003, 0, 0], [np.NaN, np.NaN, np.NaN], [0, 1.4726600000000003, 0],
[[1.4726600000000003, 0, 0], [np.nan, np.nan, np.nan], [0, 1.4726600000000003, 0],
[0, 0, 4.7619115092114601]])

with self.assertRaisesRegex(nrrd.NRRDError, 'Matrix should have same number of elements in each row'):
Expand Down
2 changes: 1 addition & 1 deletion nrrd/tests/test_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_read_simple_4d_nrrd(self):
'space directions': np.array([[1.5, 0., 0.],
[0., 1.5, 0.],
[0., 0., 1.],
[np.NaN, np.NaN, np.NaN]]),
[np.nan, np.nan, np.nan]]),
'endian': 'little',
'encoding': 'raw',
'measurement frame': np.array([[1.0001, 0., 0.],
Expand Down

0 comments on commit 40f49c3

Please sign in to comment.