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

Method test_include_columns

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

Source from the content-addressed store, hash-verified

926 table = self.read_bytes(rows, read_options=opts)
927
928 def test_include_columns(self):
929 rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n"
930
931 convert_options = ConvertOptions()
932 convert_options.include_columns = ['ab']
933 table = self.read_bytes(rows, convert_options=convert_options)
934 self.check_names(table, ["ab"])
935 assert table.to_pydict() == {
936 "ab": ["ef", "ij", "mn"],
937 }
938
939 # Order of include_columns is respected, regardless of CSV order
940 convert_options.include_columns = ['cd', 'ab']
941 table = self.read_bytes(rows, convert_options=convert_options)
942 schema = pa.schema([('cd', pa.string()),
943 ('ab', pa.string())])
944 assert table.schema == schema
945 assert table.to_pydict() == {
946 "cd": ["gh", "kl", "op"],
947 "ab": ["ef", "ij", "mn"],
948 }
949
950 # Include a column not in the CSV file => raises by default
951 convert_options.include_columns = ['xx', 'ab', 'yy']
952 with pytest.raises(KeyError,
953 match="Column 'xx' in include_columns "
954 "does not exist in CSV file"):
955 self.read_bytes(rows, convert_options=convert_options)
956
957 def test_include_missing_columns(self):
958 rows = b"ab,cd\nef,gh\nij,kl\nmn,op\n"

Callers

nothing calls this directly

Calls 5

read_bytesMethod · 0.95
ConvertOptionsClass · 0.90
check_namesMethod · 0.45
schemaMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected