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

Function test_array_from_numpy_str_utf8

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

Source from the content-addressed store, hash-verified

3651
3652@pytest.mark.numpy
3653def test_array_from_numpy_str_utf8():
3654 # ARROW-3890 -- in Python 3, NPY_UNICODE arrays are produced, but in Python
3655 # 2 they are NPY_STRING (binary), so we must do UTF-8 validation
3656 vec = np.array(["toto", "tata"])
3657 vec2 = np.array(["toto", "tata"], dtype=object)
3658
3659 arr = pa.array(vec, pa.string())
3660 arr2 = pa.array(vec2, pa.string())
3661 expected = pa.array(["toto", "tata"])
3662 assert arr.equals(expected)
3663 assert arr2.equals(expected)
3664
3665 # with mask, separate code path
3666 mask = np.array([False, False], dtype=bool)
3667 arr = pa.array(vec, pa.string(), mask=mask)
3668 assert arr.equals(expected)
3669
3670 # UTF8 validation failures
3671 vec = np.array([('mañana').encode('utf-16-le')])
3672 with pytest.raises(ValueError):
3673 pa.array(vec, pa.string())
3674
3675 with pytest.raises(ValueError):
3676 pa.array(vec, pa.string(), mask=np.array([False]))
3677
3678
3679@pytest.mark.numpy

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected