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:516–619  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

514 }
515
516 def test_skip_rows_after_names(self):
517 rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n"
518
519 opts = ReadOptions()
520 opts.skip_rows_after_names = 1
521 table = self.read_bytes(rows, read_options=opts)
522 self.check_names(table, ["ab", "cd"])
523 assert table.to_pydict() == {
524 "ab": ["ij", "mn"],
525 "cd": ["kl", "op"],
526 }
527
528 # Can skip exact number of rows
529 opts.skip_rows_after_names = 3
530 table = self.read_bytes(rows, read_options=opts)
531 self.check_names(table, ["ab", "cd"])
532 assert table.to_pydict() == {
533 "ab": [],
534 "cd": [],
535 }
536
537 # Can skip beyond all rows
538 opts.skip_rows_after_names = 4
539 table = self.read_bytes(rows, read_options=opts)
540 self.check_names(table, ["ab", "cd"])
541 assert table.to_pydict() == {
542 "ab": [],
543 "cd": [],
544 }
545
546 # Can skip rows with a different number of columns
547 rows = b"abcd\n,,,,,\nij,kl\nmn,op\n"
548 opts.skip_rows_after_names = 2
549 opts.column_names = ["f0", "f1"]
550 table = self.read_bytes(rows, read_options=opts)
551 self.check_names(table, ["f0", "f1"])
552 assert table.to_pydict() == {
553 "f0": ["ij", "mn"],
554 "f1": ["kl", "op"],
555 }
556 opts = ReadOptions()
557
558 # Can skip rows with new lines in the value
559 rows = b'ab,cd\n"e\nf","g\n\nh"\n"ij","k\nl"\nmn,op'
560 opts.skip_rows_after_names = 2
561 parse_opts = ParseOptions()
562 parse_opts.newlines_in_values = True
563 table = self.read_bytes(rows, read_options=opts,
564 parse_options=parse_opts)
565 self.check_names(table, ["ab", "cd"])
566 assert table.to_pydict() == {
567 "ab": ["mn"],
568 "cd": ["op"],
569 }
570
571 # Can skip rows when block ends in middle of quoted value
572 opts.skip_rows_after_names = 2
573 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