
    DUfw                     &    d dl Z	 	 	 	 ddZd	dZdS )
    NsnappyT       @c                    	 ddl }ddl}n# t          $ r t          d          w xY wt          | t          j                  r| f} 	 t          |           D ][\  }	}
|j                            |
d          }|	dk    r |j	        j
        ||j        f|||d|}|                    ||           \	 |                                 dS # |                                 w xY w)a0  
    Save an iterable of dataframe chunks to a single Apache Parquet file. For
    more info about Parquet, see https://arrow.apache.org/docs/python/parquet.html.

    Parameters
    ----------
    pieces : DataFrame or iterable of DataFrame
        Chunks to write
    outpath : str
        Path to output file
    row_group_size : int
        Number of rows per row group
    compression : {'snappy', 'gzip', 'brotli', 'none'}, optional
        Compression algorithm. Can be set on a per-column basis with a
        dictionary of column names to compression lib.
    use_dictionary : bool, optional
        Use dictionary encoding. Can be set on a per-column basis with a list
        of column names.

    See also
    --------
    pyarrow.parquet.write_table
    pyarrow.parquet.ParquetFile
    fastparquet

    r   Nz0Saving to parquet requires the `pyarrow` packageF)preserve_index)compressionuse_dictionaryversion)row_group_size)pyarrowpyarrow.parquetImportError
isinstancepd	DataFrame	enumerateTablefrom_pandasparquetParquetWriterschemawrite_tableclose)piecesoutpathr
   r   r   r	   kwargspar   ipiecetablewriters                X/var/www/html/software/conda/lib/python3.11/site-packages/bioframe/sandbox/parquet_io.py
to_parquetr"      s:   FN N N NLMMMN &",'' !&)) 	E 	EHAuH((u(EEEAvv11L !,#1#    u^DDDD	E 	s    %A+C CFc                     |                     dd          |st          j        | fd|S 	 ddlm} n# t
          $ r t          d          w xY w G fdd|          } || fi |S )	a  
    Load DataFrames from Parquet files, optionally in pieces.

    Parameters
    ----------
    filepath : str, pathlib.Path, pyarrow.NativeFile, or file-like object
        Readable source. For passing bytes or buffer-like file containing a
        Parquet file, use pyarorw.BufferReader
    columns: list
        If not None, only these columns will be read from the row groups. A
        column name may be a prefix of a nested field, e.g. 'a' will select
        'a.b', 'a.c', and 'a.d.e'
    iterator : boolean, default False
        Return an iterator object that yields row group DataFrames and
        provides the ParquetFile interface.
    use_threads : boolean, default True
        Perform multi-threaded column reads
    memory_map : boolean, default True
        If the source is a file path, use a memory map to read file, which can
        improve performance in some environments

    Returns
    -------
    DataFrame or ParquetFileIterator

    use_threadsTcolumnsr$   r   )ParquetFilez;Iterating over Parquet data requires the `pyarrow` package.c                   "    e Zd Zd Z fdZdS ))read_parquet.<locals>.ParquetFileIteratorc                     | S )N )selfs    r!   __iter__z2read_parquet.<locals>.ParquetFileIterator.__iter__k   s        c                     t          | d          sd| _        | j        | j        k     r/|                     | j        d          }| xj        dz  c_        nt          |                                S )N_rgidr   T)r&   r$   use_pandas_metadata   )hasattrr0   num_row_groupsread_row_groupStopIteration	to_pandas)r,   rgr&   r$   s     r!   __next__z2read_parquet.<locals>.ParquetFileIterator.__next__n   s{    tW-- #!"DJ: 333,,
 '$/,0	 -  B JJ!OJJJ''||~~%r.   N)__name__
__module____qualname__r-   r9   r%   s   r!   ParquetFileIteratorr)   j   sB          & & & & & & & &r.   r=   )popr   read_parquetr   r'   r   )filepathr&   iteratorr   r'   r=   r$   s    `    @r!   r?   r?   A   s    6 **]D11K 7
%;
 
BH
 
 	
	3333333 	 	 	M  	
	& 	& 	& 	& 	& 	& 	& 	&+ 	& 	& 	&& #"866v666s	   8 A)Nr   Tr   )NF)pandasr   r"   r?   r+   r.   r!   <module>rC      sR        : : : :z<7 <7 <7 <7 <7 <7r.   