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

Function read_schema

python/pyarrow/parquet/core.py:2432–2481  ·  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

2430
2431
2432def read_schema(where, memory_map=False, decryption_properties=None,
2433 filesystem=None, arrow_extensions_enabled=True):
2434 """
2435 Read effective Arrow schema from Parquet file metadata.
2436
2437 Parameters
2438 ----------
2439 where : str (file path) or file-like object
2440 memory_map : bool, default False
2441 Create memory map when the source is a file path.
2442 decryption_properties : FileDecryptionProperties, default None
2443 Decryption properties for reading encrypted Parquet files.
2444 filesystem : FileSystem, default None
2445 If nothing passed, will be inferred based on path.
2446 Path will try to be found in the local on-disk filesystem otherwise
2447 it will be parsed as an URI to determine the filesystem.
2448 arrow_extensions_enabled : bool, default True
2449 If True, read Parquet logical types as Arrow extension types where
2450 possible (e.g., UUID as the canonical `arrow.uuid` extension type).
2451
2452 Returns
2453 -------
2454 schema : pyarrow.Schema
2455 The schema of the Parquet file
2456
2457 Examples
2458 --------
2459 >>> import pyarrow as pa
2460 >>> import pyarrow.parquet as pq
2461 >>> table = pa.table({'n_legs': [4, 5, 100],
2462 ... 'animal': ["Dog", "Brittle stars", "Centipede"]})
2463 >>> pq.write_table(table, 'example.parquet')
2464
2465 >>> pq.read_schema('example.parquet')
2466 n_legs: int64
2467 animal: string
2468 """
2469 filesystem, where = _resolve_filesystem_and_path(where, filesystem)
2470 file_ctx = nullcontext()
2471 if filesystem is not None:
2472 file_ctx = where = filesystem.open_input_file(where)
2473
2474 with file_ctx:
2475 file = ParquetFile(
2476 where,
2477 memory_map=memory_map,
2478 decryption_properties=decryption_properties,
2479 arrow_extensions_enabled=arrow_extensions_enabled,
2480 )
2481 return file.schema_arrow
2482
2483
2484__all__ = (

Callers 2

initializeMethod · 0.85

Calls 3

ParquetFileClass · 0.85
open_input_fileMethod · 0.45

Tested by

no test coverage detected