| 693 | |
| 694 | |
| 695 | def test_binary_slice_compatibility(): |
| 696 | data = [b"", b"a", b"a\xff", b"ab\x00", b"abc\xfb", b"ab\xf2de"] |
| 697 | arr = pa.array(data) |
| 698 | for start, stop, step in itertools.product(range(-6, 6), |
| 699 | range(-6, 6), |
| 700 | range(-3, 4)): |
| 701 | if step == 0: |
| 702 | continue |
| 703 | expected = pa.array([k.as_py()[start:stop:step] |
| 704 | for k in arr]) |
| 705 | result = pc.binary_slice( |
| 706 | arr, start=start, stop=stop, step=step) |
| 707 | assert expected.equals(result) |
| 708 | # Positional options |
| 709 | assert pc.binary_slice(arr, start, stop, step) == result |
| 710 | # Fixed size binary input / output |
| 711 | for item in data: |
| 712 | fsb_scalar = pa.scalar(item, type=pa.binary(len(item))) |
| 713 | expected = item[start:stop:step] |
| 714 | actual = pc.binary_slice(fsb_scalar, start, stop, step) |
| 715 | assert actual.type == pa.binary(len(expected)) |
| 716 | assert actual.as_py() == expected |
| 717 | |
| 718 | |
| 719 | def test_split_pattern(): |