Build a PyArrow buffer from the passed mask buffer. Parameters ---------- validity_buff : BufferObject Tuple of underlying validity buffer and associated dtype. validity_dtype : Dtype Dtype description as a tuple ``(kind, bit-width, format string, endian
(
validity_buff: BufferObject,
validity_dtype: Dtype,
describe_null: ColumnNullType,
length: int,
offset: int = 0,
allow_copy: bool = True,
)
| 423 | |
| 424 | |
| 425 | def validity_buffer_from_mask( |
| 426 | validity_buff: BufferObject, |
| 427 | validity_dtype: Dtype, |
| 428 | describe_null: ColumnNullType, |
| 429 | length: int, |
| 430 | offset: int = 0, |
| 431 | allow_copy: bool = True, |
| 432 | ) -> pa.Buffer: |
| 433 | """ |
| 434 | Build a PyArrow buffer from the passed mask buffer. |
| 435 | |
| 436 | Parameters |
| 437 | ---------- |
| 438 | validity_buff : BufferObject |
| 439 | Tuple of underlying validity buffer and associated dtype. |
| 440 | validity_dtype : Dtype |
| 441 | Dtype description as a tuple ``(kind, bit-width, format string, |
| 442 | endianness)``. |
| 443 | describe_null : ColumnNullType |
| 444 | Null representation the column dtype uses, |
| 445 | as a tuple ``(kind, value)`` |
| 446 | length : int |
| 447 | The number of values in the array. |
| 448 | offset : int, default: 0 |
| 449 | Number of elements to offset from the start of the buffer. |
| 450 | allow_copy : bool, default: True |
| 451 | Whether to allow copying the memory to perform the conversion |
| 452 | (if false then zero-copy approach is requested). |
| 453 | |
| 454 | Returns |
| 455 | ------- |
| 456 | pa.Buffer |
| 457 | """ |
| 458 | null_kind, sentinel_val = describe_null |
| 459 | validity_kind, _, _, _ = validity_dtype |
| 460 | assert validity_kind == DtypeKind.BOOL |
| 461 | |
| 462 | if null_kind == ColumnNullType.NON_NULLABLE: |
| 463 | # Sliced array can have a NON_NULLABLE ColumnNullType due |
| 464 | # to no missing values in that slice of an array though the bitmask |
| 465 | # exists and validity_buff must be set to None in this case |
| 466 | return None |
| 467 | |
| 468 | elif null_kind == ColumnNullType.USE_BYTEMASK or ( |
| 469 | null_kind == ColumnNullType.USE_BITMASK and sentinel_val == 1 |
| 470 | ): |
| 471 | buff = pa.foreign_buffer(validity_buff.ptr, |
| 472 | validity_buff.bufsize, |
| 473 | base=validity_buff) |
| 474 | |
| 475 | if null_kind == ColumnNullType.USE_BYTEMASK: |
| 476 | if not allow_copy: |
| 477 | raise RuntimeError( |
| 478 | "To create a bitmask a copy of the data is " |
| 479 | "required which is forbidden by allow_copy=False" |
| 480 | ) |
| 481 | mask = pa.Array.from_buffers(pa.int8(), length, |
| 482 | [None, buff], |
no test coverage detected