Handles PyArrow Arrays and ChunkedArrays.
(
self, column: pa.Array | pa.ChunkedArray, allow_copy: bool = True
)
| 200 | """ |
| 201 | |
| 202 | def __init__( |
| 203 | self, column: pa.Array | pa.ChunkedArray, allow_copy: bool = True |
| 204 | ) -> None: |
| 205 | """ |
| 206 | Handles PyArrow Arrays and ChunkedArrays. |
| 207 | """ |
| 208 | # Store the column as a private attribute |
| 209 | if isinstance(column, pa.ChunkedArray): |
| 210 | if column.num_chunks == 1: |
| 211 | column = column.chunk(0) |
| 212 | else: |
| 213 | if not allow_copy: |
| 214 | raise RuntimeError( |
| 215 | "Chunks will be combined and a copy is required which " |
| 216 | "is forbidden by allow_copy=False" |
| 217 | ) |
| 218 | column = column.combine_chunks() |
| 219 | |
| 220 | self._allow_copy = allow_copy |
| 221 | |
| 222 | if pa.types.is_boolean(column.type): |
| 223 | if not allow_copy: |
| 224 | raise RuntimeError( |
| 225 | "Boolean column will be casted to uint8 and a copy " |
| 226 | "is required which is forbidden by allow_copy=False" |
| 227 | ) |
| 228 | self._dtype = self._dtype_from_arrowdtype(column.type, 8) |
| 229 | self._col = pc.cast(column, pa.uint8()) |
| 230 | else: |
| 231 | self._col = column |
| 232 | dtype = self._col.type |
| 233 | try: |
| 234 | bit_width = dtype.bit_width |
| 235 | except ValueError: |
| 236 | # in case of a variable-length strings, considered as array |
| 237 | # of bytes (8 bits) |
| 238 | bit_width = 8 |
| 239 | self._dtype = self._dtype_from_arrowdtype(dtype, bit_width) |
| 240 | |
| 241 | def size(self) -> int: |
| 242 | """ |
nothing calls this directly
no test coverage detected