Skip to content
Open
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
34 changes: 24 additions & 10 deletions python/pyarrow/parquet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ class ParquetFile:
page_checksum_verification : bool, default False
If True, verify the checksum for each page read from the file.
arrow_extensions_enabled : bool, default True
If True, read Parquet logical types as Arrow extension types where possible,
(e.g., read JSON as the canonical `arrow.json` extension type or UUID as
the canonical `arrow.uuid` extension type).
If True, read Parquet logical types as Arrow extension types where
possible (e.g., read JSON as the canonical `arrow.json` extension type
or UUID as the canonical `arrow.uuid` extension type).

Examples
--------
Expand Down Expand Up @@ -2372,7 +2372,7 @@ def write_metadata(schema, where, metadata_collector=None, filesystem=None,


def read_metadata(where, memory_map=False, decryption_properties=None,
filesystem=None):
filesystem=None, arrow_extensions_enabled=True):
"""
Read FileMetaData from footer of a single Parquet file.

Expand All @@ -2387,6 +2387,10 @@ def read_metadata(where, memory_map=False, decryption_properties=None,
If nothing passed, will be inferred based on path.
Path will try to be found in the local on-disk filesystem otherwise
it will be parsed as an URI to determine the filesystem.
arrow_extensions_enabled : bool, default True
Comment thread
Kuinox marked this conversation as resolved.
If True, read Parquet logical types as Arrow extension types where
possible (e.g. UUID as the canonical `arrow.uuid` extension type).
If False, use the underlying storage types instead.

Returns
-------
Expand Down Expand Up @@ -2416,13 +2420,17 @@ def read_metadata(where, memory_map=False, decryption_properties=None,
file_ctx = where = filesystem.open_input_file(where)

with file_ctx:
file = ParquetFile(where, memory_map=memory_map,
decryption_properties=decryption_properties)
file = ParquetFile(
where,
memory_map=memory_map,
decryption_properties=decryption_properties,
arrow_extensions_enabled=arrow_extensions_enabled,
)
return file.metadata


def read_schema(where, memory_map=False, decryption_properties=None,
filesystem=None):
filesystem=None, arrow_extensions_enabled=True):
"""
Read effective Arrow schema from Parquet file metadata.

Expand All @@ -2437,6 +2445,9 @@ def read_schema(where, memory_map=False, decryption_properties=None,
If nothing passed, will be inferred based on path.
Path will try to be found in the local on-disk filesystem otherwise
it will be parsed as an URI to determine the filesystem.
arrow_extensions_enabled : bool, default True
If True, read Parquet logical types as Arrow extension types where
possible (e.g., UUID as the canonical `arrow.uuid` extension type).

Returns
-------
Expand All @@ -2462,9 +2473,12 @@ def read_schema(where, memory_map=False, decryption_properties=None,

with file_ctx:
file = ParquetFile(
where, memory_map=memory_map,
decryption_properties=decryption_properties)
return file.schema.to_arrow_schema()
where,
memory_map=memory_map,
decryption_properties=decryption_properties,
arrow_extensions_enabled=arrow_extensions_enabled,
)
return file.schema_arrow


__all__ = (
Expand Down
19 changes: 19 additions & 0 deletions python/pyarrow/tests/parquet/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,22 @@ def msg(c):

with pytest.raises(TypeError, match=msg("FileMetaData")):
pq.FileMetaData()


def test_read_schema_uuid_extension_type(tmp_path):
data = [
b'\xe4`\xf9p\x83QGN\xac\x7f\xa4g>K\xa8\xcb',
b'\x1et\x14\x95\xee\xd5C\xea\x9b\xd7s\xdc\x91BK\xaf',
Comment on lines +820 to +822
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we add a comment on what is this / how was it generated?
If we ever want to change that or fix a bug in the future it could be useful.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoses are two uuid, i'll add comments

None,
]
table = pa.table([pa.array(data, type=pa.uuid())], names=["ext"])

file_path = tmp_path / "uuid.parquet"
file_path_str = str(file_path)
pq.write_table(table, file_path_str, store_schema=False)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, is store_schema=False relevant?

Copy link
Copy Markdown
Author

@Kuinox Kuinox May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was 6 months ago so I'm only guessing now:
I remember that there was differents behavior depending if arrow loaded it's stored schema or not.
I don't remember if it was needed here, but store_schema=False would allow to be sure that an uuid logical type is detected as is without arrow getting the information from it's own schema.

I can confirm it if you want


schema_default = pq.read_schema(file_path_str)
assert schema_default.field("ext").type == pa.uuid()

schema_disabled = pq.read_schema(file_path_str, arrow_extensions_enabled=False)
assert schema_disabled.field("ext").type == pa.binary(16)
Loading