def test_vectorized_indexing(self): array = np.array([[b'a', b'b', b'c'], [b'd', b'e', b'f']], dtype='S') stacked = conventions.StackedBytesArray(array) expected = np.array([[b'abc', b'def'], [b'def', b'abc']]) indexer = V[np.array([[0, 1], [1, 0]])] actual = stacked[indexer] self.assertArrayEqual(actual, expected)
def test_wrapper_class(self): array = np.array([[b'a', b'b', b'c'], [b'd', b'e', b'f']], dtype='S') actual = conventions.StackedBytesArray(array) expected = np.array([b'abc', b'def'], dtype='S') self.assertEqual(actual.dtype, expected.dtype) self.assertEqual(actual.shape, expected.shape) self.assertEqual(actual.size, expected.size) self.assertEqual(actual.ndim, expected.ndim) self.assertEqual(len(actual), len(expected)) self.assertArrayEqual(expected, actual) self.assertArrayEqual(expected[:1], actual[B[:1]]) with pytest.raises(IndexError): actual[B[:, :2]]
def test_wrapper_class(self): array = np.array([[b'a', b'b', b'c'], [b'd', b'e', b'f']], dtype='S') actual = conventions.StackedBytesArray(array) expected = np.array([b'abc', b'def'], dtype='S') assert actual.dtype == expected.dtype assert actual.shape == expected.shape assert actual.size == expected.size assert actual.ndim == expected.ndim assert len(actual) == len(expected) assert_array_equal(expected, actual) assert_array_equal(expected[:1], actual[B[:1]]) with pytest.raises(IndexError): actual[B[:, :2]]
def test_scalar(self): array = np.array([b'a', b'b', b'c'], dtype='S') actual = conventions.StackedBytesArray(array) expected = np.array(b'abc') assert actual.dtype == expected.dtype assert actual.shape == expected.shape assert actual.size == expected.size assert actual.ndim == expected.ndim with pytest.raises(TypeError): len(actual) np.testing.assert_array_equal(expected, actual) with pytest.raises(IndexError): actual[B[:2]] assert str(actual) == str(expected)