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

Method test_include_columns

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

Source from the content-addressed store, hash-verified

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