(case, *, safe=True, check_array_construction=True)
| 1702 | |
| 1703 | |
| 1704 | def _check_cast_case(case, *, safe=True, check_array_construction=True): |
| 1705 | in_data, in_type, out_data, out_type = case |
| 1706 | if isinstance(out_data, pa.Array): |
| 1707 | assert out_data.type == out_type |
| 1708 | expected = out_data |
| 1709 | else: |
| 1710 | expected = pa.array(out_data, type=out_type) |
| 1711 | |
| 1712 | # check casting an already created array |
| 1713 | if isinstance(in_data, pa.Array): |
| 1714 | assert in_data.type == in_type |
| 1715 | in_arr = in_data |
| 1716 | else: |
| 1717 | in_arr = pa.array(in_data, type=in_type) |
| 1718 | casted = in_arr.cast(out_type, safe=safe) |
| 1719 | casted.validate(full=True) |
| 1720 | assert casted.equals(expected) |
| 1721 | |
| 1722 | # constructing an array with out type which optionally involves casting |
| 1723 | # for more see ARROW-1949 |
| 1724 | if check_array_construction: |
| 1725 | in_arr = pa.array(in_data, type=out_type, safe=safe) |
| 1726 | assert in_arr.equals(expected) |
| 1727 | |
| 1728 | |
| 1729 | @pytest.mark.numpy |
no test coverage detected