(
cls,
df,
fs,
path,
append=False,
partition_on=None,
ignore_divisions=False,
division_info=None,
schema="infer",
index_cols=None,
**kwargs,
)
| 638 | |
| 639 | @classmethod |
| 640 | def initialize_write( |
| 641 | cls, |
| 642 | df, |
| 643 | fs, |
| 644 | path, |
| 645 | append=False, |
| 646 | partition_on=None, |
| 647 | ignore_divisions=False, |
| 648 | division_info=None, |
| 649 | schema="infer", |
| 650 | index_cols=None, |
| 651 | **kwargs, |
| 652 | ): |
| 653 | if schema == "infer" or isinstance(schema, dict): |
| 654 | # Start with schema from _meta_nonempty |
| 655 | inferred_schema = pyarrow_schema_dispatch( |
| 656 | df._meta_nonempty.set_index(index_cols) |
| 657 | if index_cols |
| 658 | else df._meta_nonempty |
| 659 | ).remove_metadata() |
| 660 | |
| 661 | # Use dict to update our inferred schema |
| 662 | if isinstance(schema, dict): |
| 663 | schema = pa.schema(schema) |
| 664 | for name in schema.names: |
| 665 | i = inferred_schema.get_field_index(name) |
| 666 | j = schema.get_field_index(name) |
| 667 | inferred_schema = inferred_schema.set(i, schema.field(j)) |
| 668 | schema = inferred_schema |
| 669 | |
| 670 | # Check that target directory exists |
| 671 | fs.mkdirs(path, exist_ok=True) |
| 672 | if append and division_info is None: |
| 673 | ignore_divisions = True |
| 674 | |
| 675 | full_metadata = None # metadata for the full dataset, from _metadata |
| 676 | tail_metadata = None # metadata for at least the last file in the dataset |
| 677 | i_offset = 0 |
| 678 | metadata_file_exists = False |
| 679 | if append: |
| 680 | # Extract metadata and get file offset if appending |
| 681 | ds = pa_ds.dataset(path, filesystem=_wrapped_fs(fs), format="parquet") |
| 682 | i_offset = len(ds.files) |
| 683 | if i_offset > 0: |
| 684 | try: |
| 685 | with fs.open(fs.sep.join([path, "_metadata"]), mode="rb") as fil: |
| 686 | full_metadata = pq.read_metadata(fil) |
| 687 | tail_metadata = full_metadata |
| 688 | metadata_file_exists = True |
| 689 | except OSError: |
| 690 | try: |
| 691 | with fs.open( |
| 692 | sorted(ds.files, key=natural_sort_key)[-1], mode="rb" |
| 693 | ) as fil: |
| 694 | tail_metadata = pq.read_metadata(fil) |
| 695 | except OSError: |
| 696 | pass |
| 697 | else: |
nothing calls this directly
no test coverage detected