(tempdir)
| 634 | |
| 635 | @pytest.mark.pandas |
| 636 | def test_read_multiple_files(tempdir): |
| 637 | nfiles = 10 |
| 638 | size = 5 |
| 639 | |
| 640 | dirpath = tempdir / guid() |
| 641 | dirpath.mkdir() |
| 642 | |
| 643 | test_data = [] |
| 644 | paths = [] |
| 645 | for i in range(nfiles): |
| 646 | df = _test_dataframe(size, seed=i) |
| 647 | |
| 648 | # Hack so that we don't have a dtype cast in v1 files |
| 649 | df['uint32'] = df['uint32'].astype(np.int64) |
| 650 | |
| 651 | path = dirpath / f'{i}.parquet' |
| 652 | |
| 653 | table = pa.Table.from_pandas(df) |
| 654 | _write_table(table, path) |
| 655 | |
| 656 | test_data.append(table) |
| 657 | paths.append(path) |
| 658 | |
| 659 | # Write a _SUCCESS.crc file |
| 660 | (dirpath / '_SUCCESS.crc').touch() |
| 661 | |
| 662 | def read_multiple_files(paths, columns=None, use_threads=True, **kwargs): |
| 663 | dataset = pq.ParquetDataset(paths, **kwargs) |
| 664 | return dataset.read(columns=columns, use_threads=use_threads) |
| 665 | |
| 666 | result = read_multiple_files(paths) |
| 667 | expected = pa.concat_tables(test_data) |
| 668 | |
| 669 | assert result.equals(expected) |
| 670 | |
| 671 | # Read column subset |
| 672 | to_read = [0, 2, 6, result.num_columns - 1] |
| 673 | |
| 674 | col_names = [result.field(i).name for i in to_read] |
| 675 | out = pq.read_table(dirpath, columns=col_names) |
| 676 | expected = pa.Table.from_arrays([result.column(i) for i in to_read], |
| 677 | names=col_names, |
| 678 | metadata=result.schema.metadata) |
| 679 | assert out.equals(expected) |
| 680 | |
| 681 | # Read with multiple threads |
| 682 | pq.read_table(dirpath, use_threads=True) |
| 683 | |
| 684 | # Test failure modes with non-uniform metadata |
| 685 | bad_apple = _test_dataframe(size, seed=i).iloc[:, :4] |
| 686 | bad_apple_path = tempdir / f'{guid()}.parquet' |
| 687 | |
| 688 | t = pa.Table.from_pandas(bad_apple) |
| 689 | _write_table(t, bad_apple_path) |
| 690 | |
| 691 | # TODO(dataset) Dataset API skips bad files |
| 692 | |
| 693 | # bad_meta = pq.read_metadata(bad_apple_path) |
nothing calls this directly
no test coverage detected