def test_singleton_axis_prep(): b = DataArray(np.random.randn(5, 6), "xz") slicing = (None,) shape, axes, key = _make_singleton_axes(b, slicing) key_should_be = (slice(None),) # should be trimmed shape_should_be = (1, 5, 6) ax_should_be = [Axis(l, i, b) for i, l in enumerate((None, "x", "z"))] nt.assert_true(key_should_be == key, "key translated poorly") nt.assert_true(shape_should_be == shape, "shape computed poorly") nt.assert_true(all([a1 == a2 for a1, a2 in zip(ax_should_be, axes)]), "axes computed poorly")
def test_singleton_axis_prep(): b = DataArray( np.random.randn(5,6), 'xz' ) slicing = ( None, ) shape, axes, key = _make_singleton_axes(b, slicing) key_should_be = (slice(None), ) # should be trimmed shape_should_be = (1,5,6) ax_should_be = [ Axis(l, i, b) for i, l in enumerate((None, 'x', 'z')) ] yield nt.assert_true, key_should_be==key, 'key translated poorly' yield nt.assert_true, shape_should_be==shape, 'shape computed poorly' yield nt.assert_true, all([a1==a2 for a1,a2 in zip(ax_should_be, axes)]), \ 'axes computed poorly'
def test_singleton_axis_prep(): b = DataArray(np.random.randn(5, 6), 'xz') slicing = (None, ) shape, axes, key = _make_singleton_axes(b, slicing) key_should_be = (slice(None), ) # should be trimmed shape_should_be = (1, 5, 6) ax_should_be = [Axis(l, i, b) for i, l in enumerate((None, 'x', 'z'))] yield nt.assert_true, key_should_be == key, 'key translated poorly' yield nt.assert_true, shape_should_be == shape, 'shape computed poorly' yield nt.assert_true, all([a1==a2 for a1,a2 in zip(ax_should_be, axes)]), \ 'axes computed poorly'
def test_singleton_axis_prep2(): # a little more complicated b = DataArray(np.random.randn(5, 6), 'xz') slicing = (0, None) shape, axes, key = _make_singleton_axes(b, slicing) key_should_be = (0, ) # should be trimmed shape_should_be = (5, 1, 6) ax_should_be = [Axis(l, i, b) for i, l in enumerate(('x', None, 'z'))] nt.assert_true(key_should_be == key, 'key translated poorly') nt.assert_true(shape_should_be == shape, 'shape computed poorly') nt.assert_true(all([a1 == a2 for a1, a2 in zip(ax_should_be, axes)]), 'axes computed poorly')