(self)
| 453 | assert table.column_names == names |
| 454 | |
| 455 | def test_header_skip_rows(self): |
| 456 | rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n" |
| 457 | |
| 458 | opts = ReadOptions() |
| 459 | opts.skip_rows = 1 |
| 460 | table = self.read_bytes(rows, read_options=opts) |
| 461 | self.check_names(table, ["ef", "gh"]) |
| 462 | assert table.to_pydict() == { |
| 463 | "ef": ["ij", "mn"], |
| 464 | "gh": ["kl", "op"], |
| 465 | } |
| 466 | |
| 467 | opts.skip_rows = 3 |
| 468 | table = self.read_bytes(rows, read_options=opts) |
| 469 | self.check_names(table, ["mn", "op"]) |
| 470 | assert table.to_pydict() == { |
| 471 | "mn": [], |
| 472 | "op": [], |
| 473 | } |
| 474 | |
| 475 | opts.skip_rows = 4 |
| 476 | with pytest.raises(pa.ArrowInvalid): |
| 477 | # Not enough rows |
| 478 | table = self.read_bytes(rows, read_options=opts) |
| 479 | |
| 480 | # Can skip rows with a different number of columns |
| 481 | rows = b"abcd\n,,,,,\nij,kl\nmn,op\n" |
| 482 | opts.skip_rows = 2 |
| 483 | table = self.read_bytes(rows, read_options=opts) |
| 484 | self.check_names(table, ["ij", "kl"]) |
| 485 | assert table.to_pydict() == { |
| 486 | "ij": ["mn"], |
| 487 | "kl": ["op"], |
| 488 | } |
| 489 | |
| 490 | # Can skip all rows exactly when columns are given |
| 491 | opts.skip_rows = 4 |
| 492 | opts.column_names = ['ij', 'kl'] |
| 493 | table = self.read_bytes(rows, read_options=opts) |
| 494 | self.check_names(table, ["ij", "kl"]) |
| 495 | assert table.to_pydict() == { |
| 496 | "ij": [], |
| 497 | "kl": [], |
| 498 | } |
| 499 | |
| 500 | def test_skip_rows_after_names(self): |
| 501 | rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n" |
no test coverage detected