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

Function test_pandas_roundtrip

python/pyarrow/tests/interchange/test_conversion.py:124–150  ·  view source on GitHub ↗
(uint, int, float, np_float_str)

Source from the content-addressed store, hash-verified

122 ]
123)
124def test_pandas_roundtrip(uint, int, float, np_float_str):
125 if Version(pd.__version__) < Version("1.5.0"):
126 pytest.skip("__dataframe__ added to pandas in 1.5.0")
127
128 arr = [1, 2, 3]
129 table = pa.table(
130 {
131 "a": pa.array(arr, type=uint),
132 "b": pa.array(arr, type=int),
133 "c": pa.array(np.array(arr, dtype=np.dtype(np_float_str)), type=float),
134 "d": [True, False, True],
135 }
136 )
137 from pandas.api.interchange import (
138 from_dataframe as pandas_from_dataframe
139 )
140 pandas_df = pandas_from_dataframe(table)
141 result = pi.from_dataframe(pandas_df)
142 assert table.equals(result)
143
144 table_protocol = table.__dataframe__()
145 result_protocol = result.__dataframe__()
146
147 assert table_protocol.num_columns() == result_protocol.num_columns()
148 assert table_protocol.num_rows() == result_protocol.num_rows()
149 assert table_protocol.num_chunks() == result_protocol.num_chunks()
150 assert table_protocol.column_names() == result_protocol.column_names()
151
152
153@pytest.mark.pandas

Callers

nothing calls this directly

Calls 9

VersionClass · 0.90
dtypeMethod · 0.80
equalsMethod · 0.80
__dataframe__Method · 0.80
arrayMethod · 0.45
num_columnsMethod · 0.45
num_rowsMethod · 0.45
num_chunksMethod · 0.45
column_namesMethod · 0.45

Tested by

no test coverage detected