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

Function from_dataframe

python/pyarrow/interchange/from_dataframe.py:63–89  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

61
62
63def 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
92def _from_dataframe(df: DataFrameObject, allow_copy=True):

Callers 2

test_recordbatch_non_cpuFunction · 0.90
test_table_non_cpuFunction · 0.90

Calls 2

_from_dataframeFunction · 0.85
__dataframe__Method · 0.80

Tested by 2

test_recordbatch_non_cpuFunction · 0.72
test_table_non_cpuFunction · 0.72