(self)
| 911 | table = self.read_bytes(rows, read_options=opts) |
| 912 | |
| 913 | def test_include_columns(self): |
| 914 | rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n" |
| 915 | |
| 916 | convert_options = ConvertOptions() |
| 917 | convert_options.include_columns = ['ab'] |
| 918 | table = self.read_bytes(rows, convert_options=convert_options) |
| 919 | self.check_names(table, ["ab"]) |
| 920 | assert table.to_pydict() == { |
| 921 | "ab": ["ef", "ij", "mn"], |
| 922 | } |
| 923 | |
| 924 | # Order of include_columns is respected, regardless of CSV order |
| 925 | convert_options.include_columns = ['cd', 'ab'] |
| 926 | table = self.read_bytes(rows, convert_options=convert_options) |
| 927 | schema = pa.schema([('cd', pa.string()), |
| 928 | ('ab', pa.string())]) |
| 929 | assert table.schema == schema |
| 930 | assert table.to_pydict() == { |
| 931 | "cd": ["gh", "kl", "op"], |
| 932 | "ab": ["ef", "ij", "mn"], |
| 933 | } |
| 934 | |
| 935 | # Include a column not in the CSV file => raises by default |
| 936 | convert_options.include_columns = ['xx', 'ab', 'yy'] |
| 937 | with pytest.raises(KeyError, |
| 938 | match="Column 'xx' in include_columns " |
| 939 | "does not exist in CSV file"): |
| 940 | self.read_bytes(rows, convert_options=convert_options) |
| 941 | |
| 942 | def test_include_missing_columns(self): |
| 943 | rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n" |
nothing calls this directly
no test coverage detected