zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
U
¬ý°d¢Hã @s´dZddlmZddlZddlZddlmZmZddlZddlm    Z    ddl
m Z ddl m Z mZmZmZmZddlmZdd    lmZdd
lmZdd lmZdd lmZddlZdd lmZmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)dddœdd„Z*d8dddddddœdd„Z+Gd d„dƒZ,Gd!d"„d"e,ƒZ-Gd#d$„d$e,ƒZ.ee!d%d&d9d)d*dd+d,dd-d.d/œd0d1„ƒZ/ee!d%d&d'dde j0e j0fd2dd-dd3d4d)d5œd6d7„ƒZ1dS):z parquet compat é)Ú annotationsN)ÚAnyÚLiteral)Úcatch_warnings)Úlib)Ú DtypeBackendÚFilePathÚ
ReadBufferÚStorageOptionsÚ WriteBuffer)Úimport_optional_dependency©ÚAbstractMethodError)Údoc)Úfind_stack_level)Úcheck_dtype_backend)Ú    DataFrameÚ
get_option)Ú _shared_docs)ÚVersion)Ú    IOHandlesÚ
get_handleÚ is_fsspec_urlÚis_urlÚstringify_pathÚstrÚBaseImpl)ÚengineÚreturnc Cs¤|dkrtdƒ}|dkr|ttg}d}|D]D}z |ƒWStk
rj}z|dt|ƒ7}W5d}~XYq(Xq(td|›ƒ‚|dkrŠtƒS|dkr˜tƒStd    ƒ‚dS)
zreturn our implementationÚautozio.parquet.engineÚz
 - NzÉUnable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
A suitable version of pyarrow or fastparquet is required for parquet support.
Trying to import the above resulted in these errors:ÚpyarrowÚ fastparquetz.engine must be one of 'pyarrow', 'fastparquet')rÚ PyArrowImplÚFastParquetImplÚ ImportErrorrÚ
ValueError)rZengine_classesZ
error_msgsZ engine_classÚerr©r(úHd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/io/parquet.pyÚ
get_engine,s$ $ÿ
r*ÚrbFz1FilePath | ReadBuffer[bytes] | WriteBuffer[bytes]rr
ÚboolzVtuple[FilePath | ReadBuffer[bytes] | WriteBuffer[bytes], IOHandles[bytes] | None, Any])ÚpathÚfsÚstorage_optionsÚmodeÚis_dirrcCsœt|ƒ}t|ƒr:|dkr:tdƒ}|jj|f|p0iŽ\}}n|rVt|ƒrN|dkrVtdƒ‚d}|s’|s’t|tƒr’t    j
  |¡s’t ||d|d}d}|j }|||fS)zFile handling for PyArrow.NÚfsspecr+z8storage_options passed with buffer, or non-supported URLF©Zis_textr/)rrr ÚcoreZ    url_to_fsrr&Ú
isinstancerÚosr-ÚisdirrÚhandle)r-r.r/r0r1Úpath_or_handler2Úhandlesr(r(r)Ú_get_path_or_handleNs8
ÿÿ
ÿþý
ü    ÿr;c@s>eZdZedddœdd„ƒZddœdd„Zd dd
œd d „Zd    S)rrÚNone)ÚdfrcCst|tƒstdƒ‚dS)Nz+to_parquet only supports IO with DataFrames)r5rr&©r=r(r(r)Úvalidate_dataframews
zBaseImpl.validate_dataframer>cKs t|ƒ‚dS©Nr )Úselfr=r-Ú compressionÚkwargsr(r(r)Úwrite|szBaseImpl.writeN©rcKs t|ƒ‚dSr@r )rAr-ÚcolumnsrCr(r(r)Úreadsz BaseImpl.read)N)Ú__name__Ú
__module__Ú __qualname__Ú staticmethodr?rDrGr(r(r(r)rvsc    @sVeZdZddœdd„Zdddd    d
d d dd œdd„Zddejdfddd ddœdd„ZdS)r#r<rEcCs&tdddddl}ddl}||_dS)Nr!z(pyarrow is required for parquet support.©Úextrar)r Zpyarrow.parquetZ(pandas.core.arrays.arrow.extension_typesÚapi)rAr!Úpandasr(r(r)Ú__init__„sÿzPyArrowImpl.__init__ÚsnappyNrzFilePath | WriteBuffer[bytes]ú
str | Noneú bool | Noner
úlist[str] | None)r=r-rBÚindexr/Úpartition_colsrc Ks| |¡d| dd¡i}|dk    r*||d<|jjj|f|Ž}    t|| dd¡|d|dk    d\}
} |d<t|
tjƒr¢t    |
dƒr¢t|
j
t t fƒr¢|
j
}
t|
t ƒr¢|
  ¡}
zH|dk    rÌ|jjj|    |
f||dœ|—Žn|jjj|    |
fd|i|—ŽW5| dk    rü|  ¡XdS)    NZschemaZpreserve_indexÚ
filesystemÚwb)r/r0r1Úname)rBrVrB)r?ÚpoprNZTableZ from_pandasr;r5ÚioÚBufferedWriterÚhasattrrYrÚbytesÚdecodeÚcloseÚparquetZwrite_to_datasetZ write_table) rAr=r-rBrUr/rVrCZfrom_pandas_kwargsÚtabler9r:r(r(r)rDsT
 
 
û
ÿþý
þüû    ÿÿÿ
zPyArrowImpl.writeFr,úDtypeBackend | lib.NoDefault)Úuse_nullable_dtypesÚ dtype_backendr/rcKsÚd|d<i}|dkr2ddlm}|ƒ}    |    j|d<n|dkrDtj|d<tdƒ}
|
d    kr\d|d
<t|| d d¡|d d \} } |d <zD|j    j
j | fd|i|—Ž} | j f|Ž}|
d    kr¼|j d    dd}|W¢S| dk    rÔ|  ¡XdS)NTZuse_pandas_metadataZnumpy_nullabler)Ú_arrow_dtype_mappingZ types_mapperr!zmode.data_managerÚarrayZ split_blocksrWr+)r/r0rFF)Úcopy)Zpandas.io._utilrfÚgetÚpdZ
ArrowDtyperr;rZr`rNraZ
read_tableÚ    to_pandasZ _as_manager)rAr-rFrdrer/rCZto_pandas_kwargsrfÚmappingÚmanagerr9r:Zpa_tableÚresultr(r(r)rGÄs>      
 
üÿÿÿ zPyArrowImpl.read)rQNNN)rHrIrJrPrDrÚ
no_defaultrGr(r(r(r)r#ƒsù8úr#c@sBeZdZddœdd„Zdddd    dd
œd d „Zdd    dd œdd„ZdS)r$r<rEcCstddd}||_dS)Nr"z,fastparquet is required for parquet support.rL)r rN)rAr"r(r(r)rPñs
ÿzFastParquetImpl.__init__rQNrz,Literal[('snappy', 'gzip', 'brotli')] | Noner
)r=rBr/rc     s´| |¡d|kr"|dk    r"tdƒ‚d|kr4| d¡}|dk    rDd|d<t|ƒ}t|ƒrptdƒ‰‡‡fdd„|d<n ˆr|td    ƒ‚td
d $|jj||f|||d œ|—ŽW5QRXdS) NÚ partition_onzYCannot use both partition_on and partition_cols. Use partition_cols for partitioning dataZhiveZ file_schemer2csˆj|dfˆpiŽ ¡S)NrX©Úopen©r-Ú_©r2r/r(r)Ú<lambda>s
ÿÿz'FastParquetImpl.write.<locals>.<lambda>Ú    open_withz?storage_options passed with file object or non-fsspec file pathT)Úrecord)rBZ write_indexrp)    r?r&rZrrr rrNrD)rAr=r-rBrUrVr/rCr(rur)rDùs8
 
ÿ
ÿ þûúzFastParquetImpl.write)r/rc
 s&i}| dd¡}| dtj¡}t|jjƒtdƒkr:d|d<|rFtdƒ‚|tjk    rXtdƒ‚t|ƒ}d}t|ƒr¸t    dƒ‰t|jjƒtd    ƒkr¤ˆj
|d
fˆp˜iŽj |d <q䇇fd d „|d<n,t |t ƒrätj |¡sät|d
dˆd}|j}z(|jj|f|Ž}    |    jfd|i|—ŽW¢S|dk    r | ¡XdS)NrdFrez0.7.1Z pandas_nullszNThe 'use_nullable_dtypes' argument is not supported for the fastparquet enginezHThe 'dtype_backend' argument is not supported for the fastparquet enginer2z0.6.1r+r.csˆj|dfˆpiŽ ¡S)Nr+rqrsrur(r)rvEs
ÿÿz&FastParquetImpl.read.<locals>.<lambda>rwr3rF)rZrrorrNÚ __version__r&rrr rrr.r5rr6r-r7rr8r`Z ParquetFilerk)
rAr-rFr/rCZparquet_kwargsrdrer:Z parquet_filer(rur)rG(sL ÿ
ÿÿÿ ÿ
zFastParquetImpl.read)rQNNN)NN)rHrIrJrPrDrGr(r(r(r)r$ðs ù0ÿr$r/)r/rrQrz$FilePath | WriteBuffer[bytes] | NonerRrSrTz bytes | None)r=r-rrBrUr/rVrc
Ksrt|tƒr|g}t|ƒ}|dkr(t ¡n|}    |j||    f||||dœ|—Ž|dkrjt|    tjƒsbt‚|     ¡SdSdS)a}
    Write a DataFrame to the parquet format.
 
    Parameters
    ----------
    df : DataFrame
    path : str, path object, file-like object, or None, default None
        String, path object (implementing ``os.PathLike[str]``), or file-like
        object implementing a binary ``write()`` function. If None, the result is
        returned as bytes. If a string, it will be used as Root Directory path
        when writing a partitioned dataset. The engine fastparquet does not
        accept file-like objects.
 
        .. versionchanged:: 1.2.0
 
    engine : {{'auto', 'pyarrow', 'fastparquet'}}, default 'auto'
        Parquet library to use. If 'auto', then the option
        ``io.parquet.engine`` is used. The default ``io.parquet.engine``
        behavior is to try 'pyarrow', falling back to 'fastparquet' if
        'pyarrow' is unavailable.
    compression : {{'snappy', 'gzip', 'brotli', 'lz4', 'zstd', None}},
        default 'snappy'. Name of the compression to use. Use ``None``
        for no compression. The supported compression methods actually
        depend on which engine is used. For 'pyarrow', 'snappy', 'gzip',
        'brotli', 'lz4', 'zstd' are all supported. For 'fastparquet',
        only 'gzip' and 'snappy' are supported.
    index : bool, default None
        If ``True``, include the dataframe's index(es) in the file output. If
        ``False``, they will not be written to the file.
        If ``None``, similar to ``True`` the dataframe's index(es)
        will be saved. However, instead of being saved as values,
        the RangeIndex will be stored as a range in the metadata so it
        doesn't require much space and is faster. Other indexes will
        be included as columns in the file output.
    partition_cols : str or list, optional, default None
        Column names by which to partition the dataset.
        Columns are partitioned in the order they are given.
        Must be None if path is not a string.
    {storage_options}
 
        .. versionadded:: 1.2.0
 
    kwargs
        Additional keyword arguments passed to the engine
 
    Returns
    -------
    bytes if no path argument is provided else None
    N)rBrUrVr/)r5rr*r[ÚBytesIOrDÚAssertionErrorÚgetvalue)
r=r-rrBrUr/rVrCÚimplZ path_or_bufr(r(r)Ú
to_parquetYs&<
þúù
r~zFilePath | ReadBuffer[bytes]zbool | lib.NoDefaultrc)r-rrFr/rdrerc    Ksbt|ƒ}|tjk    r:d}|dkr&|d7}tj|ttƒdnd}t|ƒ|j|f||||dœ|—ŽS)a    
    Load a parquet object from the file path, returning a DataFrame.
 
    Parameters
    ----------
    path : str, path object or file-like object
        String, path object (implementing ``os.PathLike[str]``), or file-like
        object implementing a binary ``read()`` function.
        The string could be a URL. Valid URL schemes include http, ftp, s3,
        gs, and file. For file URLs, a host is expected. A local file could be:
        ``file://localhost/path/to/table.parquet``.
        A file URL can also be a path to a directory that contains multiple
        partitioned parquet files. Both pyarrow and fastparquet support
        paths to directories as well as file URLs. A directory path could be:
        ``file://localhost/path/to/tables`` or ``s3://bucket/partition_dir``.
    engine : {{'auto', 'pyarrow', 'fastparquet'}}, default 'auto'
        Parquet library to use. If 'auto', then the option
        ``io.parquet.engine`` is used. The default ``io.parquet.engine``
        behavior is to try 'pyarrow', falling back to 'fastparquet' if
        'pyarrow' is unavailable.
    columns : list, default=None
        If not None, only these columns will be read from the file.
 
    {storage_options}
 
        .. versionadded:: 1.3.0
 
    use_nullable_dtypes : bool, default False
        If True, use dtypes that use ``pd.NA`` as missing value indicator
        for the resulting DataFrame. (only applicable for the ``pyarrow``
        engine)
        As new dtypes are added that support ``pd.NA`` in the future, the
        output with this option will change to use those dtypes.
        Note: this is an experimental option, and behaviour (e.g. additional
        support dtypes) may change without notice.
 
        .. deprecated:: 2.0
 
    dtype_backend : {{"numpy_nullable", "pyarrow"}}, defaults to NumPy backed DataFrames
        Which dtype_backend to use, e.g. whether a DataFrame should have NumPy
        arrays, nullable dtypes are used for all dtypes that have a nullable
        implementation when "numpy_nullable" is set, pyarrow is used for all
        dtypes if "pyarrow" is set.
 
        The dtype_backends are still experimential.
 
        .. versionadded:: 2.0
 
    **kwargs
        Any additional kwargs are passed to the engine.
 
    Returns
    -------
    DataFrame
    zYThe argument 'use_nullable_dtypes' is deprecated and will be removed in a future version.TzFUse dtype_backend='numpy_nullable' instead of use_nullable_dtype=True.)Ú
stacklevelF)rFr/rdre)    r*rroÚwarningsÚwarnÚ FutureWarningrrrG)    r-rrFr/rdrerCr}Úmsgr(r(r)Ú read_parquet¬s*A
ÿÿÿûúr„)Nr+F)NrrQNNN)2Ú__doc__Ú
__future__rr[r6Útypingrrr€rZ pandas._libsrZpandas._typingrrr    r
r Zpandas.compat._optionalr Z pandas.errorsrZpandas.util._decoratorsrZpandas.util._exceptionsrZpandas.util._validatorsrrOrjrrZpandas.core.shared_docsrZpandas.util.versionrZpandas.io.commonrrrrrr*r;rr#r$r~ror„r(r(r(r)Ú<module>sR              %û( mi ù R ú