def test_encoding(self): encoding = 'utf-8' raw_array = np.array([b'abc', u'ß∂µ∆'.encode(encoding)]) actual = conventions.BytesToStringArray(raw_array, encoding=encoding) expected = np.array([u'abc', u'ß∂µ∆'], dtype=object) 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.assertArrayEqual(expected, actual) self.assertArrayEqual(expected[0], actual[B[0]])
def test_encoding(self): encoding = 'utf-8' raw_array = np.array([b'abc', u'ß∂µ∆'.encode(encoding)]) actual = conventions.BytesToStringArray(raw_array, encoding=encoding) expected = np.array([u'abc', u'ß∂µ∆'], dtype=object) assert actual.dtype == expected.dtype assert actual.shape == expected.shape assert actual.size == expected.size assert actual.ndim == expected.ndim assert_array_equal(expected, actual) assert_array_equal(expected[0], actual[B[0]])
def test_scalar(self): expected = np.array(u'abc', dtype=object) actual = conventions.BytesToStringArray(np.array(b'abc'), encoding='utf-8') 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)