| 383 | |
| 384 | |
| 385 | def test_schema_duplicate_fields(): |
| 386 | fields = [ |
| 387 | pa.field('foo', pa.int32()), |
| 388 | pa.field('bar', pa.string()), |
| 389 | pa.field('foo', pa.list_(pa.int8())), |
| 390 | ] |
| 391 | sch = pa.schema(fields) |
| 392 | assert sch.names == ['foo', 'bar', 'foo'] |
| 393 | assert sch.types == [pa.int32(), pa.string(), pa.list_(pa.int8())] |
| 394 | assert len(sch) == 3 |
| 395 | assert repr(sch) == """\ |
| 396 | foo: int32 |
| 397 | bar: string |
| 398 | foo: list<item: int8> |
| 399 | child 0, item: int8""" |
| 400 | |
| 401 | assert sch[0].name == 'foo' |
| 402 | assert sch[0].type == fields[0].type |
| 403 | with pytest.warns(FutureWarning): |
| 404 | assert sch.field_by_name('bar') == fields[1] |
| 405 | with pytest.warns(FutureWarning): |
| 406 | assert sch.field_by_name('xxx') is None |
| 407 | with pytest.warns((UserWarning, FutureWarning)): |
| 408 | assert sch.field_by_name('foo') is None |
| 409 | |
| 410 | # Schema::GetFieldIndex |
| 411 | assert sch.get_field_index('foo') == -1 |
| 412 | |
| 413 | # Schema::GetAllFieldIndices |
| 414 | assert sch.get_all_field_indices('foo') == [0, 2] |
| 415 | |
| 416 | |
| 417 | def test_field_flatten(): |