
    q-Phl6                       d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	 d dl
mZmZmZmZ d dlmZ d dlmZmZ d d	lmZmZ d d
lmZ d dlmZ d dlmZ  ej        e          5  d dlm Z m!Z! ddd           n# 1 swxY w Y   erd dlm"Z" d dl#m$Z$m%Z% d dl&m'Z' d dl(m)Z) ddedddddd dddddddd9d1Z* ed2d#d34           ed5d%d34          ddedddddd dddddddd:d8                        Z+dS );    )annotationsN)Sequence)BytesIOStringIO)Path)IOTYPE_CHECKINGAnyLiteral)deprecate_renamed_parameter)is_path_or_str_sequencenormalize_filepath)wrap_dfwrap_ldf)N_INFER_DEFAULT)parse_row_index_args)!_init_credential_provider_builder)PyDataFramePyLazyFrame)IOBase)	DataFrame	LazyFrame)SchemaDefinition)CredentialProviderFunctioni   Fauto   )schemaschema_overridesinfer_schema_length
batch_sizen_rows
low_memoryrechunkrow_index_namerow_index_offsetignore_errorsstorage_optionscredential_providerretriesfile_cache_ttlinclude_file_pathssource4str | Path | list[str] | list[Path] | IOBase | bytesr   SchemaDefinition | Noner   r   
int | Noner    r!   r"   boolr#   r$   
str | Noner%   intr&   r'   dict[str, Any] | Noner(   3CredentialProviderFunction | Literal['auto'] | Noner)   r*   r+   returnr   c               <   t          | t          t          f          st          | t                    r$| r"t          | d         t          t          f          st          | t                    r3t          |                                                                           } t          j	        | |
||          }t          |          }|r|                    |          }|S t          || |d          }~t          | f|||||||||	|
|||||d                                S )u~  
    Read into a DataFrame from a newline delimited JSON file.

    Parameters
    ----------
    source
        Path to a file or a file-like object (by "file-like object" we refer to objects
        that have a `read()` method, such as a file handler like the builtin `open`
        function, or a `BytesIO` instance). For file-like objects, the stream position
        may not be updated accordingly after reading.
    schema : Sequence of str, (str,DataType) pairs, or a {str:DataType,} dict
        The DataFrame schema may be declared in several ways:

        * As a dict of {name:type} pairs; if type is None, it will be auto-inferred.
        * As a list of column names; in this case types are automatically inferred.
        * As a list of (name,type) pairs; this is equivalent to the dictionary form.

        If you supply a list of column names that does not match the names in the
        underlying data, the names given here will overwrite them. The number
        of names given in the schema should match the underlying data dimensions.
    schema_overrides : dict, default None
        Support type specification or override of one or more columns; note that
        any dtypes inferred from the schema param will be overridden.
    infer_schema_length
        The maximum number of rows to scan for schema inference.
        If set to `None`, the full data may be scanned *(this is slow)*.
    batch_size
        Number of rows to read in each batch.
    n_rows
        Stop reading from JSON file after reading `n_rows`.
    low_memory
        Reduce memory pressure at the expense of performance.
    rechunk
        Reallocate to contiguous memory when all chunks/ files are parsed.
    row_index_name
        If not None, this will insert a row index column with give name into the
        DataFrame
    row_index_offset
        Offset to start the row index column (only use if the name is set)
    ignore_errors
        Return `Null` if parsing fails because of schema mismatches.
    storage_options
        Options that indicate how to connect to a cloud provider.

        The cloud providers currently supported are AWS, GCP, and Azure.
        See supported keys here:

        * `aws <https://docs.rs/object_store/latest/object_store/aws/enum.AmazonS3ConfigKey.html>`_
        * `gcp <https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html>`_
        * `azure <https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html>`_
        * Hugging Face (`hf://`): Accepts an API key under the `token` parameter: \
          `{'token': '...'}`, or by setting the `HF_TOKEN` environment variable.

        If `storage_options` is not provided, Polars will try to infer the information
        from environment variables.
    credential_provider
        Provide a function that can be called to provide cloud storage
        credentials. The function is expected to return a dictionary of
        credential keys along with an optional credential expiry time.

        .. warning::
            This functionality is considered **unstable**. It may be changed
            at any point without it being considered a breaking change.
    retries
        Number of retries if accessing a cloud instance fails.
    file_cache_ttl
        Amount of time to keep downloaded cloud files since their last access time,
        in seconds. Uses the `POLARS_FILE_CACHE_TTL` environment variable
        (which defaults to 1 hour) if not given.
    include_file_paths
        Include the path of the source file(s) as a column with this name.

    See Also
    --------
    scan_ndjson : Lazily read from an NDJSON file or multiple files via glob patterns.

    Warnings
    --------
    Calling `read_ndjson().lazy()` is an antipattern as this forces Polars to
    materialize a full ndjson file and therefore cannot push any optimizations into
    the reader. Therefore always prefer `scan_ndjson` if you want to work with
    `LazyFrame` s.

    Examples
    --------
    >>> from io import StringIO
    >>> json_str = '{"foo":1,"bar":6}\n{"foo":2,"bar":7}\n{"foo":3,"bar":8}\n'
    >>> pl.read_ndjson(StringIO(json_str))
    shape: (3, 2)
    ┌─────┬─────┐
    │ foo ┆ bar │
    │ --- ┆ --- │
    │ i64 ┆ i64 │
    ╞═════╪═════╡
    │ 1   ┆ 6   │
    │ 2   ┆ 7   │
    │ 3   ┆ 8   │
    └─────┴─────┘
    r   )r&   r   r   read_ndjson)r   r   r   r    r!   r"   r#   r$   r%   r&   r+   r)   r'   r(   r*   )
isinstancestrr   r   r   r   getvalueencoder   r7   r   headr   scan_ndjsoncollect)r,   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   pydfdfcredential_provider_builders                      P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/io/ndjson.pyr7   r7      sM   n 	6C;'' vx(( 	
 6!9sDk22 fh'' 	9V__..557788F&'-	
 
 
 T]] 	!B	"CV_m# # 	)/%)#-'7%!  " gii#    row_count_namez0.20.4)versionrow_count_offsetcstr | Path | IO[str] | IO[bytes] | bytes | list[str] | list[Path] | list[IO[str]] | list[IO[bytes]]r   c                  g }t          | t          t          f          rt          | d          } n5t          | t                    r t          |           rd | D             }n| }d} |dk    rd}t          |          t          || |d          }~|r"t	          |                                          }nd}t          j
        | ||||||||t          ||	          |
|||||          }t          |          S )	aM  
    Lazily read from a newline delimited JSON file or multiple files via glob patterns.

    This allows the query optimizer to push down predicates and projections to the scan
    level, thereby potentially reducing memory overhead.

    .. versionchanged:: 0.20.4
        * The `row_count_name` parameter was renamed `row_index_name`.
        * The `row_count_offset` parameter was renamed `row_index_offset`.

    Parameters
    ----------
    source
        Path to a file.
    schema : Sequence of str, (str,DataType) pairs, or a {str:DataType,} dict
        The DataFrame schema may be declared in several ways:

        * As a dict of {name:type} pairs; if type is None, it will be auto-inferred.
        * As a list of column names; in this case types are automatically inferred.
        * As a list of (name,type) pairs; this is equivalent to the dictionary form.

        If you supply a list of column names that does not match the names in the
        underlying data, the names given here will overwrite them. The number
        of names given in the schema should match the underlying data dimensions.
    schema_overrides : dict, default None
        Support type specification or override of one or more columns; note that
        any dtypes inferred from the schema param will be overridden.
    infer_schema_length
        The maximum number of rows to scan for schema inference.
        If set to `None`, the full data may be scanned *(this is slow)*.
    batch_size
        Number of rows to read in each batch.
    n_rows
        Stop reading from JSON file after reading `n_rows`.
    low_memory
        Reduce memory pressure at the expense of performance.
    rechunk
        Reallocate to contiguous memory when all chunks/ files are parsed.
    row_index_name
        If not None, this will insert a row index column with give name into the
        DataFrame
    row_index_offset
        Offset to start the row index column (only use if the name is set)
    ignore_errors
        Return `Null` if parsing fails because of schema mismatches.
    storage_options
        Options that indicate how to connect to a cloud provider.

        The cloud providers currently supported are AWS, GCP, and Azure.
        See supported keys here:

        * `aws <https://docs.rs/object_store/latest/object_store/aws/enum.AmazonS3ConfigKey.html>`_
        * `gcp <https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html>`_
        * `azure <https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html>`_
        * Hugging Face (`hf://`): Accepts an API key under the `token` parameter:           `{'token': '...'}`, or by setting the `HF_TOKEN` environment variable.

        If `storage_options` is not provided, Polars will try to infer the information
        from environment variables.
    credential_provider
        Provide a function that can be called to provide cloud storage
        credentials. The function is expected to return a dictionary of
        credential keys along with an optional credential expiry time.

        .. warning::
            This functionality is considered **unstable**. It may be changed
            at any point without it being considered a breaking change.
    retries
        Number of retries if accessing a cloud instance fails.
    file_cache_ttl
        Amount of time to keep downloaded cloud files since their last access time,
        in seconds. Uses the `POLARS_FILE_CACHE_TTL` environment variable
        (which defaults to 1 hour) if not given.
    include_file_paths
        Include the path of the source file(s) as a column with this name.
    Fcheck_not_directoryc                0    g | ]}t          |d           S )FrI   )r   ).0r,   s     rB   
<listcomp>zscan_ndjson.<locals>.<listcomp>7  s5        #6uEEE  rC   Nr   z('infer_schema_length' should be positiver=   )r   r   r   r    r!   r"   r#   	row_indexr&   r+   r)   cloud_optionsr(   r*   )r8   r9   r   r   listr   
ValueErrorr   itemsr   new_from_ndjsonr   r   )r,   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   sourcesmsgrA   pylfs                       rB   r=   r=      sH   V IKG&3+&& #FFFF	FD	!	! 	"6** 	 $  GG
 Ga8oo"CV_m# # 	 446677 &/)&~7GHH#-%7%!  D$ D>>rC   )"r,   r-   r   r.   r   r.   r   r/   r    r/   r!   r/   r"   r0   r#   r0   r$   r1   r%   r2   r&   r0   r'   r3   r(   r4   r)   r2   r*   r/   r+   r1   r5   r   )"r,   rG   r   r.   r   r.   r   r/   r    r/   r!   r/   r"   r0   r#   r0   r$   r1   r%   r2   r&   r0   r'   r3   r(   r4   r)   r2   r*   r/   r+   r1   r5   r   ),
__future__r   
contextlibcollections.abcr   ior   r   pathlibr   typingr   r	   r
   r   polars._utils.deprecationr   polars._utils.variousr   r   polars._utils.wrapr   r   polars.datatypesr   polars.io._utilsr   ,polars.io.cloud.credential_provider._builderr   suppressImportErrorpolars.polarsr   r   r   polarsr   r   polars._typingr   polars.io.cloudr   r7   r=    rC   rB   <module>rj      s   " " " " " "     $ $ $ $ $ $                       2 2 2 2 2 2 2 2 2 2 2 2 A A A A A A M M M M M M M M 0 0 0 0 0 0 0 0 , , , , , , 1 1 1 1 1 1      Z%% 7 7666666667 7 7 7 7 7 7 7 7 7 7 7 7 7 7  ;++++++++//////:::::: '+04&5!!%-1OU!%%)#g g g g g gT -/?RRR/1CXVVV '+04&5!!%-1OU!%%)7Y Y Y Y Y WV SRY Y Ys   #	A88A<?A<