MCPcopy Create free account
hub / github.com/apache/arrow / bool_column_to_array

Function bool_column_to_array

python/pyarrow/interchange/from_dataframe.py:197–233  ·  view source on GitHub ↗

Convert a column holding boolean dtype to a PyArrow array. Parameters ---------- col : ColumnObject allow_copy : bool, default: True Whether to allow copying the memory to perform the conversion (if false then zero-copy approach is requested). Returns -

(
    col: ColumnObject,
    allow_copy: bool = True,
)

Source from the content-addressed store, hash-verified

195
196
197def bool_column_to_array(
198 col: ColumnObject,
199 allow_copy: bool = True,
200) -> pa.Array:
201 """
202 Convert a column holding boolean dtype to a PyArrow array.
203
204 Parameters
205 ----------
206 col : ColumnObject
207 allow_copy : bool, default: True
208 Whether to allow copying the memory to perform the conversion
209 (if false then zero-copy approach is requested).
210
211 Returns
212 -------
213 pa.Array
214 """
215 buffers = col.get_buffers()
216 size = buffers["data"][1][1]
217
218 # If booleans are byte-packed a copy to bit-packed will be made
219 if size == 8 and not allow_copy:
220 raise RuntimeError(
221 "Boolean column will be casted from uint8 and a copy "
222 "is required which is forbidden by allow_copy=False"
223 )
224
225 data_type = col.dtype
226 data = buffers_to_array(buffers, data_type,
227 col.size(),
228 col.describe_null,
229 col.offset)
230 if size == 8:
231 data = pc.cast(data, pa.bool_())
232
233 return data
234
235
236def categorical_column_to_dictionary(

Callers 1

Calls 4

buffers_to_arrayFunction · 0.85
get_buffersMethod · 0.80
sizeMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected