(uint, int, float, np_float_str)
| 122 | ] |
| 123 | ) |
| 124 | def 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 |
nothing calls this directly
no test coverage detected