(self)
| 835 | } |
| 836 | |
| 837 | def test_header_column_names(self): |
| 838 | rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n" |
| 839 | |
| 840 | opts = ReadOptions() |
| 841 | opts.column_names = ["x", "y"] |
| 842 | table = self.read_bytes(rows, read_options=opts) |
| 843 | self.check_names(table, ["x", "y"]) |
| 844 | assert table.to_pydict() == { |
| 845 | "x": ["ab", "ef", "ij", "mn"], |
| 846 | "y": ["cd", "gh", "kl", "op"], |
| 847 | } |
| 848 | |
| 849 | opts.skip_rows = 3 |
| 850 | table = self.read_bytes(rows, read_options=opts) |
| 851 | self.check_names(table, ["x", "y"]) |
| 852 | assert table.to_pydict() == { |
| 853 | "x": ["mn"], |
| 854 | "y": ["op"], |
| 855 | } |
| 856 | |
| 857 | opts.skip_rows = 4 |
| 858 | table = self.read_bytes(rows, read_options=opts) |
| 859 | self.check_names(table, ["x", "y"]) |
| 860 | assert table.to_pydict() == { |
| 861 | "x": [], |
| 862 | "y": [], |
| 863 | } |
| 864 | |
| 865 | opts.skip_rows = 5 |
| 866 | with pytest.raises(pa.ArrowInvalid): |
| 867 | # Not enough rows |
| 868 | table = self.read_bytes(rows, read_options=opts) |
| 869 | |
| 870 | # Unexpected number of columns |
| 871 | opts.skip_rows = 0 |
| 872 | opts.column_names = ["x", "y", "z"] |
| 873 | with pytest.raises(pa.ArrowInvalid, |
| 874 | match="Expected 3 columns, got 2"): |
| 875 | table = self.read_bytes(rows, read_options=opts) |
| 876 | |
| 877 | # Can skip rows with a different number of columns |
| 878 | rows = b"abcd\n,,,,,\nij,kl\nmn,op\n" |
| 879 | opts.skip_rows = 2 |
| 880 | opts.column_names = ["x", "y"] |
| 881 | table = self.read_bytes(rows, read_options=opts) |
| 882 | self.check_names(table, ["x", "y"]) |
| 883 | assert table.to_pydict() == { |
| 884 | "x": ["ij", "mn"], |
| 885 | "y": ["kl", "op"], |
| 886 | } |
| 887 | |
| 888 | def test_header_autogenerate_column_names(self): |
| 889 | rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n" |
nothing calls this directly
no test coverage detected