MCPcopy Create free account
hub / github.com/apache/arrow / test_skip_rows_after_names

Method test_skip_rows_after_names

python/pyarrow/tests/test_csv.py:500–603  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

498 }
499
500 def test_skip_rows_after_names(self):
501 rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n"
502
503 opts = ReadOptions()
504 opts.skip_rows_after_names = 1
505 table = self.read_bytes(rows, read_options=opts)
506 self.check_names(table, ["ab", "cd"])
507 assert table.to_pydict() == {
508 "ab": ["ij", "mn"],
509 "cd": ["kl", "op"],
510 }
511
512 # Can skip exact number of rows
513 opts.skip_rows_after_names = 3
514 table = self.read_bytes(rows, read_options=opts)
515 self.check_names(table, ["ab", "cd"])
516 assert table.to_pydict() == {
517 "ab": [],
518 "cd": [],
519 }
520
521 # Can skip beyond all rows
522 opts.skip_rows_after_names = 4
523 table = self.read_bytes(rows, read_options=opts)
524 self.check_names(table, ["ab", "cd"])
525 assert table.to_pydict() == {
526 "ab": [],
527 "cd": [],
528 }
529
530 # Can skip rows with a different number of columns
531 rows = b"abcd\n,,,,,\nij,kl\nmn,op\n"
532 opts.skip_rows_after_names = 2
533 opts.column_names = ["f0", "f1"]
534 table = self.read_bytes(rows, read_options=opts)
535 self.check_names(table, ["f0", "f1"])
536 assert table.to_pydict() == {
537 "f0": ["ij", "mn"],
538 "f1": ["kl", "op"],
539 }
540 opts = ReadOptions()
541
542 # Can skip rows with new lines in the value
543 rows = b'ab,cd\n"e\nf","g\n\nh"\n"ij","k\nl"\nmn,op'
544 opts.skip_rows_after_names = 2
545 parse_opts = ParseOptions()
546 parse_opts.newlines_in_values = True
547 table = self.read_bytes(rows, read_options=opts,
548 parse_options=parse_opts)
549 self.check_names(table, ["ab", "cd"])
550 assert table.to_pydict() == {
551 "ab": ["mn"],
552 "cd": ["op"],
553 }
554
555 # Can skip rows when block ends in middle of quoted value
556 opts.skip_rows_after_names = 2
557 opts.block_size = 26

Callers 1

Calls 6

read_bytesMethod · 0.95
check_namesMethod · 0.95
ReadOptionsClass · 0.90
ParseOptionsClass · 0.90
make_random_csvFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected