(case, *, safe=True, check_array_construction=True)
| 1587 | |
| 1588 | |
| 1589 | def _check_cast_case(case, *, safe=True, check_array_construction=True): |
| 1590 | in_data, in_type, out_data, out_type = case |
| 1591 | if isinstance(out_data, pa.Array): |
| 1592 | assert out_data.type == out_type |
| 1593 | expected = out_data |
| 1594 | else: |
| 1595 | expected = pa.array(out_data, type=out_type) |
| 1596 | |
| 1597 | # check casting an already created array |
| 1598 | if isinstance(in_data, pa.Array): |
| 1599 | assert in_data.type == in_type |
| 1600 | in_arr = in_data |
| 1601 | else: |
| 1602 | in_arr = pa.array(in_data, type=in_type) |
| 1603 | casted = in_arr.cast(out_type, safe=safe) |
| 1604 | casted.validate(full=True) |
| 1605 | assert casted.equals(expected) |
| 1606 | |
| 1607 | # constructing an array with out type which optionally involves casting |
| 1608 | # for more see ARROW-1949 |
| 1609 | if check_array_construction: |
| 1610 | in_arr = pa.array(in_data, type=out_type, safe=safe) |
| 1611 | assert in_arr.equals(expected) |
| 1612 | |
| 1613 | |
| 1614 | @pytest.mark.numpy |
no test coverage detected