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

Source from the content-addressed store, hash-verified

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