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)
| 2430 | |
| 2431 | |
| 2432 | def 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__ = ( |
no test coverage detected