| 2159 | ] |
| 2160 | ) |
| 2161 | def test_table_safe_casting(cls): |
| 2162 | data = [ |
| 2163 | pa.array(range(5), type=pa.int64()), |
| 2164 | pa.array([-10, -5, 0, 5, 10], type=pa.int32()), |
| 2165 | pa.array([1.0, 2.0, 3.0, 4.0, 5.0], type=pa.float64()), |
| 2166 | pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string()) |
| 2167 | ] |
| 2168 | table = cls.from_arrays(data, names=tuple('abcd')) |
| 2169 | |
| 2170 | expected_data = [ |
| 2171 | pa.array(range(5), type=pa.int32()), |
| 2172 | pa.array([-10, -5, 0, 5, 10], type=pa.int16()), |
| 2173 | pa.array([1, 2, 3, 4, 5], type=pa.int64()), |
| 2174 | pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string()) |
| 2175 | ] |
| 2176 | expected_table = cls.from_arrays(expected_data, names=tuple('abcd')) |
| 2177 | |
| 2178 | target_schema = pa.schema([ |
| 2179 | pa.field('a', pa.int32()), |
| 2180 | pa.field('b', pa.int16()), |
| 2181 | pa.field('c', pa.int64()), |
| 2182 | pa.field('d', pa.string()) |
| 2183 | ]) |
| 2184 | casted_table = table.cast(target_schema) |
| 2185 | |
| 2186 | assert casted_table.equals(expected_table) |
| 2187 | |
| 2188 | |
| 2189 | @pytest.mark.parametrize( |