Serialize a pandas DataFrame into a buffer protocol compatible object. Parameters ---------- df : pandas.DataFrame nthreads : int, default None Number of threads to use for conversion to Arrow, default all CPUs. preserve_index : bool, default None The defaul
(df, *, nthreads=None, preserve_index=None)
| 232 | |
| 233 | |
| 234 | def serialize_pandas(df, *, nthreads=None, preserve_index=None): |
| 235 | """ |
| 236 | Serialize a pandas DataFrame into a buffer protocol compatible object. |
| 237 | |
| 238 | Parameters |
| 239 | ---------- |
| 240 | df : pandas.DataFrame |
| 241 | nthreads : int, default None |
| 242 | Number of threads to use for conversion to Arrow, default all CPUs. |
| 243 | preserve_index : bool, default None |
| 244 | The default of None will store the index as a column, except for |
| 245 | RangeIndex which is stored as metadata only. If True, always |
| 246 | preserve the pandas index data as a column. If False, no index |
| 247 | information is saved and the result will have a default RangeIndex. |
| 248 | |
| 249 | Returns |
| 250 | ------- |
| 251 | buf : buffer |
| 252 | An object compatible with the buffer protocol. |
| 253 | """ |
| 254 | batch = pa.RecordBatch.from_pandas(df, nthreads=nthreads, |
| 255 | preserve_index=preserve_index) |
| 256 | sink = pa.BufferOutputStream() |
| 257 | with pa.RecordBatchStreamWriter(sink, batch.schema) as writer: |
| 258 | writer.write_batch(batch) |
| 259 | return sink.getvalue() |
| 260 | |
| 261 | |
| 262 | def deserialize_pandas(buf, *, use_threads=True): |
nothing calls this directly
no test coverage detected