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

Function read_schema

python/pyarrow/parquet/core.py:2455–2504  ·  view source on GitHub ↗

Read effective Arrow schema from Parquet file metadata. Parameters ---------- where : str (file path) or file-like object memory_map : bool, default False Create memory map when the source is a file path. decryption_properties : FileDecryptionProperties, default Non

(where, memory_map=False, decryption_properties=None,
                filesystem=None, arrow_extensions_enabled=True)

Source from the content-addressed store, hash-verified

2453
2454
2455def read_schema(where, memory_map=False, decryption_properties=None,
2456 filesystem=None, arrow_extensions_enabled=True):
2457 """
2458 Read effective Arrow schema from Parquet file metadata.
2459
2460 Parameters
2461 ----------
2462 where : str (file path) or file-like object
2463 memory_map : bool, default False
2464 Create memory map when the source is a file path.
2465 decryption_properties : FileDecryptionProperties, default None
2466 Decryption properties for reading encrypted Parquet files.
2467 filesystem : FileSystem, default None
2468 If nothing passed, will be inferred based on path.
2469 Path will try to be found in the local on-disk filesystem otherwise
2470 it will be parsed as an URI to determine the filesystem.
2471 arrow_extensions_enabled : bool, default True
2472 If True, read Parquet logical types as Arrow extension types where
2473 possible (e.g., UUID as the canonical `arrow.uuid` extension type).
2474
2475 Returns
2476 -------
2477 schema : pyarrow.Schema
2478 The schema of the Parquet file
2479
2480 Examples
2481 --------
2482 >>> import pyarrow as pa
2483 >>> import pyarrow.parquet as pq
2484 >>> table = pa.table({'n_legs': [4, 5, 100],
2485 ... 'animal': ["Dog", "Brittle stars", "Centipede"]})
2486 >>> pq.write_table(table, 'example.parquet')
2487
2488 >>> pq.read_schema('example.parquet')
2489 n_legs: int64
2490 animal: string
2491 """
2492 filesystem, where = _resolve_filesystem_and_path(where, filesystem)
2493 file_ctx = nullcontext()
2494 if filesystem is not None:
2495 file_ctx = where = filesystem.open_input_file(where)
2496
2497 with file_ctx:
2498 file = ParquetFile(
2499 where,
2500 memory_map=memory_map,
2501 decryption_properties=decryption_properties,
2502 arrow_extensions_enabled=arrow_extensions_enabled,
2503 )
2504 return file.schema_arrow
2505
2506
2507__all__ = (

Callers 2

initializeMethod · 0.85

Calls 3

ParquetFileClass · 0.85
open_input_fileMethod · 0.45

Tested by

no test coverage detected