Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/pyarrow/_parquet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ cdef class RowGroupMetaData:
return True

def column(self, int i):
if i < 0 or i >= self.num_columns:
raise IndexError('{0} out of bounds'.format(i))
chunk = ColumnChunkMetaData()
chunk.init(deref(self.metadata), i)
return chunk
Expand Down
12 changes: 12 additions & 0 deletions python/pyarrow/tests/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,23 @@ def test_parquet_metadata_api():
assert isinstance(col_meta, pq.ColumnChunkMetaData)
repr(col_meta)

with pytest.raises(IndexError):
meta.row_group(-1)

with pytest.raises(IndexError):
meta.row_group(meta.num_row_groups + 1)

rg_meta = meta.row_group(0)
assert rg_meta.num_rows == len(df)
assert rg_meta.num_columns == ncols + 1 # +1 for index
assert rg_meta.total_byte_size > 0

with pytest.raises(IndexError):
col_meta = rg_meta.column(-1)

with pytest.raises(IndexError):
col_meta = rg_meta.column(ncols + 2)

col_meta = rg_meta.column(0)
assert col_meta.file_offset > 0
assert col_meta.file_path == '' # created from BytesIO
Expand Down