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