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

Function test_parquet_metadata_api

python/pyarrow/tests/parquet/test_metadata.py:56–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54
55@pytest.mark.pandas
56def test_parquet_metadata_api():
57 df = alltypes_sample(size=10000)
58 df = df.reindex(columns=sorted(df.columns))
59 df.index = np.random.randint(0, 1000000, size=len(df))
60
61 fileh = make_sample_file(df)
62 ncols = len(df.columns)
63
64 # Series of sniff tests
65 meta = fileh.metadata
66 repr(meta)
67 assert meta.num_rows == len(df)
68 assert meta.num_columns == ncols + 1 # +1 for index
69 assert meta.num_row_groups == 1
70 assert meta.format_version == '2.6'
71 assert 'parquet-cpp' in meta.created_by
72 assert isinstance(meta.serialized_size, int)
73 assert isinstance(meta.metadata, dict)
74
75 # Schema
76 schema = fileh.schema
77 assert meta.schema is schema
78 assert len(schema) == ncols + 1 # +1 for index
79 repr(schema)
80
81 col = schema[0]
82 repr(col)
83 assert col.name == df.columns[0]
84 assert col.max_definition_level == 1
85 assert col.max_repetition_level == 0
86 assert col.max_repetition_level == 0
87 assert col.physical_type == 'BOOLEAN'
88 assert col.converted_type == 'NONE'
89
90 col_float16 = schema[5]
91 assert col_float16.logical_type.type == 'FLOAT16'
92
93 with pytest.raises(IndexError):
94 schema[ncols + 1] # +1 for index
95
96 with pytest.raises(IndexError):
97 schema[-1]
98
99 # Row group
100 for rg in range(meta.num_row_groups):
101 rg_meta = meta.row_group(rg)
102 assert isinstance(rg_meta, pq.RowGroupMetaData)
103 repr(rg_meta)
104
105 for col in range(rg_meta.num_columns):
106 col_meta = rg_meta.column(col)
107 assert isinstance(col_meta, pq.ColumnChunkMetaData)
108 repr(col_meta)
109
110 with pytest.raises(IndexError):
111 meta.row_group(-1)
112
113 with pytest.raises(IndexError):

Callers

nothing calls this directly

Calls 4

alltypes_sampleFunction · 0.90
make_sample_fileFunction · 0.90
lenFunction · 0.85
columnMethod · 0.45

Tested by

no test coverage detected