(self)
| 619 | |
| 620 | @pytest.mark.numpy |
| 621 | def test_row_number_offset_in_errors(self): |
| 622 | # Row numbers are only correctly counted in serial reads |
| 623 | def format_msg(msg_format, row, *args): |
| 624 | if self.use_threads: |
| 625 | row_info = "" |
| 626 | else: |
| 627 | row_info = f"Row #{row}: " |
| 628 | return msg_format.format(row_info, *args) |
| 629 | |
| 630 | csv, _ = make_random_csv(4, 100, write_names=True) |
| 631 | |
| 632 | read_options = ReadOptions() |
| 633 | read_options.block_size = len(csv) / 3 |
| 634 | convert_options = ConvertOptions() |
| 635 | convert_options.column_types = {"a": pa.int32()} |
| 636 | |
| 637 | # Test without skip_rows and column names in the csv |
| 638 | csv_bad_columns = csv + b"1,2\r\n" |
| 639 | message_columns = format_msg("{}Expected 4 columns, got 2", 102) |
| 640 | with pytest.raises(pa.ArrowInvalid, match=message_columns): |
| 641 | self.read_bytes(csv_bad_columns, |
| 642 | read_options=read_options, |
| 643 | convert_options=convert_options) |
| 644 | |
| 645 | csv_bad_type = csv + b"a,b,c,d\r\n" |
| 646 | message_value = format_msg( |
| 647 | "In CSV column #0: {}" |
| 648 | "CSV conversion error to int32: invalid value 'a'", |
| 649 | 102, csv) |
| 650 | with pytest.raises(pa.ArrowInvalid, match=message_value): |
| 651 | self.read_bytes(csv_bad_type, |
| 652 | read_options=read_options, |
| 653 | convert_options=convert_options) |
| 654 | |
| 655 | long_row = (b"this is a long row" * 15) + b",3\r\n" |
| 656 | csv_bad_columns_long = csv + long_row |
| 657 | message_long = format_msg("{}Expected 4 columns, got 2: {} ...", 102, |
| 658 | long_row[0:96].decode("utf-8")) |
| 659 | with pytest.raises(pa.ArrowInvalid, match=message_long): |
| 660 | self.read_bytes(csv_bad_columns_long, |
| 661 | read_options=read_options, |
| 662 | convert_options=convert_options) |
| 663 | |
| 664 | # Test skipping rows after the names |
| 665 | read_options.skip_rows_after_names = 47 |
| 666 | |
| 667 | with pytest.raises(pa.ArrowInvalid, match=message_columns): |
| 668 | self.read_bytes(csv_bad_columns, |
| 669 | read_options=read_options, |
| 670 | convert_options=convert_options) |
| 671 | |
| 672 | with pytest.raises(pa.ArrowInvalid, match=message_value): |
| 673 | self.read_bytes(csv_bad_type, |
| 674 | read_options=read_options, |
| 675 | convert_options=convert_options) |
| 676 | |
| 677 | with pytest.raises(pa.ArrowInvalid, match=message_long): |
| 678 | self.read_bytes(csv_bad_columns_long, |
nothing calls this directly
no test coverage detected