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)
| 2417 | |
| 2418 | |
| 2419 | def read_schema(where, memory_map=False, decryption_properties=None, |
| 2420 | filesystem=None): |
| 2421 | """ |
| 2422 | Read effective Arrow schema from Parquet file metadata. |
| 2423 | |
| 2424 | Parameters |
| 2425 | ---------- |
| 2426 | where : str (file path) or file-like object |
| 2427 | memory_map : bool, default False |
| 2428 | Create memory map when the source is a file path. |
| 2429 | decryption_properties : FileDecryptionProperties, default None |
| 2430 | Decryption properties for reading encrypted Parquet files. |
| 2431 | filesystem : FileSystem, default None |
| 2432 | If nothing passed, will be inferred based on path. |
| 2433 | Path will try to be found in the local on-disk filesystem otherwise |
| 2434 | it will be parsed as an URI to determine the filesystem. |
| 2435 | |
| 2436 | Returns |
| 2437 | ------- |
| 2438 | schema : pyarrow.Schema |
| 2439 | The schema of the Parquet file |
| 2440 | |
| 2441 | Examples |
| 2442 | -------- |
| 2443 | >>> import pyarrow as pa |
| 2444 | >>> import pyarrow.parquet as pq |
| 2445 | >>> table = pa.table({'n_legs': [4, 5, 100], |
| 2446 | ... 'animal': ["Dog", "Brittle stars", "Centipede"]}) |
| 2447 | >>> pq.write_table(table, 'example.parquet') |
| 2448 | |
| 2449 | >>> pq.read_schema('example.parquet') |
| 2450 | n_legs: int64 |
| 2451 | animal: string |
| 2452 | """ |
| 2453 | filesystem, where = _resolve_filesystem_and_path(where, filesystem) |
| 2454 | file_ctx = nullcontext() |
| 2455 | if filesystem is not None: |
| 2456 | file_ctx = where = filesystem.open_input_file(where) |
| 2457 | |
| 2458 | with file_ctx: |
| 2459 | file = ParquetFile( |
| 2460 | where, memory_map=memory_map, |
| 2461 | decryption_properties=decryption_properties) |
| 2462 | return file.schema.to_arrow_schema() |
| 2463 | |
| 2464 | |
| 2465 | __all__ = ( |
no test coverage detected