| 2267 | ] |
| 2268 | ) |
| 2269 | def test_table_safe_casting(cls): |
| 2270 | data = [ |
| 2271 | pa.array(range(5), type=pa.int64()), |
| 2272 | pa.array([-10, -5, 0, 5, 10], type=pa.int32()), |
| 2273 | pa.array([1.0, 2.0, 3.0, 4.0, 5.0], type=pa.float64()), |
| 2274 | pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string()) |
| 2275 | ] |
| 2276 | table = cls.from_arrays(data, names=tuple('abcd')) |
| 2277 | |
| 2278 | expected_data = [ |
| 2279 | pa.array(range(5), type=pa.int32()), |
| 2280 | pa.array([-10, -5, 0, 5, 10], type=pa.int16()), |
| 2281 | pa.array([1, 2, 3, 4, 5], type=pa.int64()), |
| 2282 | pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string()) |
| 2283 | ] |
| 2284 | expected_table = cls.from_arrays(expected_data, names=tuple('abcd')) |
| 2285 | |
| 2286 | target_schema = pa.schema([ |
| 2287 | pa.field('a', pa.int32()), |
| 2288 | pa.field('b', pa.int16()), |
| 2289 | pa.field('c', pa.int64()), |
| 2290 | pa.field('d', pa.string()) |
| 2291 | ]) |
| 2292 | casted_table = table.cast(target_schema) |
| 2293 | |
| 2294 | assert casted_table.equals(expected_table) |
| 2295 | |
| 2296 | |
| 2297 | @pytest.mark.parametrize( |