Build a ``pa.Table`` from any DataFrame supporting the interchange protocol. Parameters ---------- df : DataFrameObject Object supporting the interchange protocol, i.e. `__dataframe__` method. allow_copy : bool, default: True Whether to allow copying the
(df: DataFrameObject, allow_copy=True)
| 61 | |
| 62 | |
| 63 | def from_dataframe(df: DataFrameObject, allow_copy=True) -> pa.Table: |
| 64 | """ |
| 65 | Build a ``pa.Table`` from any DataFrame supporting the interchange protocol. |
| 66 | |
| 67 | Parameters |
| 68 | ---------- |
| 69 | df : DataFrameObject |
| 70 | Object supporting the interchange protocol, i.e. `__dataframe__` |
| 71 | method. |
| 72 | allow_copy : bool, default: True |
| 73 | Whether to allow copying the memory to perform the conversion |
| 74 | (if false then zero-copy approach is requested). |
| 75 | |
| 76 | Returns |
| 77 | ------- |
| 78 | pa.Table |
| 79 | """ |
| 80 | if isinstance(df, pa.Table): |
| 81 | return df |
| 82 | elif isinstance(df, pa.RecordBatch): |
| 83 | return pa.Table.from_batches([df]) |
| 84 | |
| 85 | if not hasattr(df, "__dataframe__"): |
| 86 | raise ValueError("`df` does not support __dataframe__") |
| 87 | |
| 88 | return _from_dataframe(df.__dataframe__(allow_copy=allow_copy), |
| 89 | allow_copy=allow_copy) |
| 90 | |
| 91 | |
| 92 | def _from_dataframe(df: DataFrameObject, allow_copy=True): |