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

Function test_cast_integers_safe

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

Source from the content-addressed store, hash-verified

1613
1614@pytest.mark.numpy
1615def test_cast_integers_safe():
1616 safe_cases = [
1617 (np.array([0, 1, 2, 3], dtype='i1'), 'int8',
1618 np.array([0, 1, 2, 3], dtype='i4'), pa.int32()),
1619 (np.array([0, 1, 2, 3], dtype='i1'), 'int8',
1620 np.array([0, 1, 2, 3], dtype='u4'), pa.uint16()),
1621 (np.array([0, 1, 2, 3], dtype='i1'), 'int8',
1622 np.array([0, 1, 2, 3], dtype='u1'), pa.uint8()),
1623 (np.array([0, 1, 2, 3], dtype='i1'), 'int8',
1624 np.array([0, 1, 2, 3], dtype='f8'), pa.float64())
1625 ]
1626
1627 for case in safe_cases:
1628 _check_cast_case(case)
1629
1630 unsafe_cases = [
1631 (np.array([50000], dtype='i4'), 'int32', 'int16'),
1632 (np.array([70000], dtype='i4'), 'int32', 'uint16'),
1633 (np.array([-1], dtype='i4'), 'int32', 'uint16'),
1634 (np.array([50000], dtype='u2'), 'uint16', 'int16')
1635 ]
1636 for in_data, in_type, out_type in unsafe_cases:
1637 in_arr = pa.array(in_data, type=in_type)
1638
1639 with pytest.raises(pa.ArrowInvalid):
1640 in_arr.cast(out_type)
1641
1642
1643def 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