Skip to content

Commit 4459cef

Browse files
grlee77larsoner
authored andcommitted
FIX: raise TypeError on complex input prior to figure creation
1 parent 416f784 commit 4459cef

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

nibabel/tests/test_viewers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def test_viewer():
6666
v = OrthoSlicer3D(data[:, :, :, 0])
6767
v._on_scroll(nt('event', 'button inaxes key')('up', v._axes[0], 'shift'))
6868
v._on_keypress(nt('event', 'key')('escape'))
69+
v.close()
70+
71+
# complex input should raise a TypeError prior to figure creation
72+
assert_raises(TypeError, OrthoSlicer3D,
73+
data[:, :, :, 0].astype(np.complex64))
6974

7075
# other cases
7176
fig, axes = plt.subplots(1, 4)

nibabel/viewers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def __init__(self, data, affine=None, axes=None, cmap='gray',
7272
data = np.asanyarray(data)
7373
if data.ndim < 3:
7474
raise ValueError('data must have at least 3 dimensions')
75+
if np.iscomplexobj(data):
76+
raise TypeError("Complex data not supported")
7577
affine = np.array(affine, float) if affine is not None else np.eye(4)
7678
if affine.ndim != 2 or affine.shape != (4, 4):
7779
raise ValueError('affine must be a 4x4 matrix')

0 commit comments

Comments
 (0)