| 2232 | ] |
| 2233 | ) |
| 2234 | def test_table_cast_to_incompatible_schema(cls): |
| 2235 | data = [ |
| 2236 | pa.array(range(5)), |
| 2237 | pa.array([-10, -5, 0, 5, 10]), |
| 2238 | ] |
| 2239 | table = cls.from_arrays(data, names=tuple('ab')) |
| 2240 | |
| 2241 | target_schema1 = pa.schema([ |
| 2242 | pa.field('A', pa.int32()), |
| 2243 | pa.field('b', pa.int16()), |
| 2244 | ]) |
| 2245 | target_schema2 = pa.schema([ |
| 2246 | pa.field('a', pa.int32()), |
| 2247 | ]) |
| 2248 | |
| 2249 | if cls is pa.Table: |
| 2250 | cls_name = 'table' |
| 2251 | else: |
| 2252 | cls_name = 'record batch' |
| 2253 | message = ("Target schema's field names are not matching the " |
| 2254 | f"{cls_name}'s field names:.*") |
| 2255 | |
| 2256 | with pytest.raises(ValueError, match=message): |
| 2257 | table.cast(target_schema1) |
| 2258 | with pytest.raises(ValueError, match=message): |
| 2259 | table.cast(target_schema2) |
| 2260 | |
| 2261 | |
| 2262 | @pytest.mark.parametrize( |