| 2206 | ] |
| 2207 | ) |
| 2208 | def test_table_safe_casting(cls): |
| 2209 | data = [ |
| 2210 | pa.array(range(5), type=pa.int64()), |
| 2211 | pa.array([-10, -5, 0, 5, 10], type=pa.int32()), |
| 2212 | pa.array([1.0, 2.0, 3.0, 4.0, 5.0], type=pa.float64()), |
| 2213 | pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string()) |
| 2214 | ] |
| 2215 | table = cls.from_arrays(data, names=tuple('abcd')) |
| 2216 | |
| 2217 | expected_data = [ |
| 2218 | pa.array(range(5), type=pa.int32()), |
| 2219 | pa.array([-10, -5, 0, 5, 10], type=pa.int16()), |
| 2220 | pa.array([1, 2, 3, 4, 5], type=pa.int64()), |
| 2221 | pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string()) |
| 2222 | ] |
| 2223 | expected_table = cls.from_arrays(expected_data, names=tuple('abcd')) |
| 2224 | |
| 2225 | target_schema = pa.schema([ |
| 2226 | pa.field('a', pa.int32()), |
| 2227 | pa.field('b', pa.int16()), |
| 2228 | pa.field('c', pa.int64()), |
| 2229 | pa.field('d', pa.string()) |
| 2230 | ]) |
| 2231 | casted_table = table.cast(target_schema) |
| 2232 | |
| 2233 | assert casted_table.equals(expected_table) |
| 2234 | |
| 2235 | |
| 2236 | @pytest.mark.parametrize( |