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

Function test_cast_integers_safe

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

Source from the content-addressed store, hash-verified

1728
1729@pytest.mark.numpy
1730def test_cast_integers_safe():
1731 safe_cases = [
1732 (np.array([0, 1, 2, 3], dtype='i1'), 'int8',
1733 np.array([0, 1, 2, 3], dtype='i4'), pa.int32()),
1734 (np.array([0, 1, 2, 3], dtype='i1'), 'int8',
1735 np.array([0, 1, 2, 3], dtype='u4'), pa.uint16()),
1736 (np.array([0, 1, 2, 3], dtype='i1'), 'int8',
1737 np.array([0, 1, 2, 3], dtype='u1'), pa.uint8()),
1738 (np.array([0, 1, 2, 3], dtype='i1'), 'int8',
1739 np.array([0, 1, 2, 3], dtype='f8'), pa.float64())
1740 ]
1741
1742 for case in safe_cases:
1743 _check_cast_case(case)
1744
1745 unsafe_cases = [
1746 (np.array([50000], dtype='i4'), 'int32', 'int16'),
1747 (np.array([70000], dtype='i4'), 'int32', 'uint16'),
1748 (np.array([-1], dtype='i4'), 'int32', 'uint16'),
1749 (np.array([50000], dtype='u2'), 'uint16', 'int16')
1750 ]
1751 for in_data, in_type, out_type in unsafe_cases:
1752 in_arr = pa.array(in_data, type=in_type)
1753
1754 with pytest.raises(pa.ArrowInvalid):
1755 in_arr.cast(out_type)
1756
1757
1758def test_cast_none():

Callers

nothing calls this directly

Calls 3

_check_cast_caseFunction · 0.85
arrayMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected