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

Class _PyArrowDataFrame

python/pyarrow/interchange/dataframe.py:31–217  ·  view source on GitHub ↗

A data frame class, with only the methods required by the interchange protocol defined. A "data frame" represents an ordered collection of named columns. A column's "name" must be a unique string. Columns may be accessed by name or by position. This could be a public data

Source from the content-addressed store, hash-verified

29
30
31class _PyArrowDataFrame:
32 """
33 A data frame class, with only the methods required by the interchange
34 protocol defined.
35
36 A "data frame" represents an ordered collection of named columns.
37 A column's "name" must be a unique string.
38 Columns may be accessed by name or by position.
39
40 This could be a public data frame class, or an object with the methods and
41 attributes defined on this DataFrame class could be returned from the
42 ``__dataframe__`` method of a public data frame class in a library adhering
43 to the dataframe interchange protocol specification.
44 """
45
46 def __init__(
47 self, df: pa.Table | pa.RecordBatch,
48 nan_as_null: bool = False,
49 allow_copy: bool = True
50 ) -> None:
51 """
52 Constructor - an instance of this (private) class is returned from
53 `pa.Table.__dataframe__` or `pa.RecordBatch.__dataframe__`.
54 """
55 self._df = df
56 # ``nan_as_null`` is a keyword intended for the consumer to tell the
57 # producer to overwrite null values in the data with ``NaN`` (or
58 # ``NaT``).
59 if nan_as_null is True:
60 raise RuntimeError(
61 "nan_as_null=True currently has no effect, "
62 "use the default nan_as_null=False"
63 )
64 self._nan_as_null = nan_as_null
65 self._allow_copy = allow_copy
66
67 def __dataframe__(
68 self, nan_as_null: bool = False, allow_copy: bool = True
69 ) -> _PyArrowDataFrame:
70 """
71 Construct a new exchange object, potentially changing the parameters.
72 ``nan_as_null`` is a keyword intended for the consumer to tell the
73 producer to overwrite null values in the data with ``NaN``.
74 It is intended for cases where the consumer does not support the bit
75 mask or byte mask that is the producer's native representation.
76 ``allow_copy`` is a keyword that defines whether or not the library is
77 allowed to make a copy of the data. For example, copying data would be
78 necessary if a library supports strided buffers, given that this
79 protocol specifies contiguous buffers.
80 """
81 return _PyArrowDataFrame(self._df, nan_as_null, allow_copy)
82
83 @property
84 def metadata(self) -> dict[str, Any]:
85 """
86 The metadata for the data frame, as a dictionary with string keys. The
87 contents of `metadata` may be anything, they are meant for a library
88 to store information that it needs to, e.g., roundtrip losslessly or

Callers 4

__dataframe__Method · 0.85
select_columnsMethod · 0.85
get_chunksMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected