MCPcopy Create free account
hub / github.com/apache/arrow / test_cast_binary_to_utf8

Function test_cast_binary_to_utf8

python/pyarrow/tests/test_array.py:2327–2344  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2325
2326@pytest.mark.numpy
2327def test_cast_binary_to_utf8():
2328 binary_arr = pa.array([b'foo', b'bar', b'baz'], type=pa.binary())
2329 utf8_arr = binary_arr.cast(pa.utf8())
2330 expected = pa.array(['foo', 'bar', 'baz'], type=pa.utf8())
2331
2332 assert utf8_arr.equals(expected)
2333
2334 non_utf8_values = [('mañana').encode('utf-16-le')]
2335 non_utf8_binary = pa.array(non_utf8_values)
2336 assert non_utf8_binary.type == pa.binary()
2337 with pytest.raises(ValueError):
2338 non_utf8_binary.cast(pa.string())
2339
2340 non_utf8_all_null = pa.array(non_utf8_values, mask=np.array([True]),
2341 type=pa.binary())
2342 # No error
2343 casted = non_utf8_all_null.cast(pa.string())
2344 assert casted.null_count == 1
2345
2346
2347@pytest.mark.numpy

Callers

nothing calls this directly

Calls 5

equalsMethod · 0.80
arrayMethod · 0.45
castMethod · 0.45
encodeMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected