Esempio n. 1
0
def _text_strip(data: pa.Array, to_strip) -> pa.Array:
    """
    Strip the characters of ``to_strip`` from start and end of each element in the data.
    """
    if len(data) == 0:
        return data

    offsets, data_buffer = _extract_string_buffers(data)

    valid_buffer = data.buffers()[0]
    valid_offset = data.offset
    builder = StringArrayBuilder(max(len(data_buffer), len(data)))

    _do_strip(
        valid_buffer,
        valid_offset,
        offsets,
        data_buffer,
        len(data),
        to_strip,
        inout_builder=builder,
    )

    result_array = finalize_string_array(builder, pa.string())
    return result_array
Esempio n. 2
0
def _slice_handle_chunk(pa_arr, start, end, step):
    """Slice each string according to the (start, end, step) inputs."""
    offsets, data = _extract_string_buffers(pa_arr)
    valid = _buffer_to_view(pa_arr.buffers()[0])
    if step == 0:
        raise ValueError("step cannot be zero.")

    if start >= 0 and (end is None or end >= 0) and step >= 1:
        if step == 1:
            res = _slice_pos_inputs_nostep(offsets, data, valid, pa_arr.offset,
                                           start, end)
        else:
            res = _slice_pos_inputs_step(offsets, data, valid, pa_arr.offset,
                                         start, end, step)
    else:
        res = _slice_generic(offsets, data, valid, pa_arr.offset, start, end,
                             step)

    return finalize_string_array(res, pa.string())