U
    bڕ                     @  sr  d dl mZ d dlmZmZ d dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZmZmZ d dlZd dlm  mZ d dlmZ d d	lmZmZmZmZmZ d d
lmZ d dlmZm Z m!Z! d dl"m#Z#m$Z$ d dl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d dl;m<Z< d dl=m>Z>m?Z? d dl@mAZA ejBZBejCZCdGddddd dd!d d"d dd#d$d%d&ZDG d'd( d(eZEG d)d* d*eEZFG d+d, d,eEZGG d-d. d.eGZHe!e3d/ e3d0 d1 d2ed3dd4e d5d1gd6d7dHd:d d d dd d;d"d;d#d<
d=d>ZIG d?d@ d@ejJZKG dAdB dBZLG dCdD dDeLZMG dEdF dFeLZNdS )I    )annotations)ABCabstractmethod)abcN)StringIO)islice)AnyCallableMapping)iNaT)CompressionOptionsDtypeArg
IndexLabelJSONSerializableStorageOptionsAbstractMethodError)deprecate_kwargdeprecate_nonkeyword_argumentsdoc)
ensure_stris_period_dtype)	DataFrame
MultiIndexSeriesisnanotnato_datetime)!create_series_with_explicit_dtype)NDFrame)concat)_shared_docs)	IOHandlesfile_exists
get_handleis_fsspec_urlis_urlstringify_path)convert_to_line_delimits)build_table_schemaparse_table_schema)validate_integerepoch
   TmsFinferr   
str | Nonestrintbool(Callable[[Any], JSONSerializable] | Noner   r   )objorientdate_formatdouble_precisionforce_ascii	date_unitdefault_handlerlinescompressionindexindentstorage_optionsc                 C  s   |
s|dkrt d|r(|dkr(t d|dkrLt|trL|j|jpFdd}|dkrdt|trdt}n(t|trtt}nt|trt}nt	d|||||||||
|d		
 }|rt|}| d k	rt| d
|	|d}|j
| W 5 Q R X n|S d S )N)splittablez?'index=False' is only valid when 'orient' is 'split' or 'table'recordsz3'lines' keyword only valid when 'orient' is recordsrB   values)namez''obj' should be a Series or a DataFrame)r6   r7   r8   ensure_asciir:   r;   r>   r?   w)r=   r@   )
ValueError
isinstancer   Zto_framerE   r   JSONTableWriterSeriesWriterFrameWriterNotImplementedErrorwriter(   r$   handle)path_or_bufr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   writershandles rT   8/tmp/pip-unpacked-wheel-ck39h295/pandas/io/json/_json.pyto_jsonI   sL    


   rV   c                
   @  sZ   e Zd ZU ded< dddddddddd	d
dZdd Zdd ZeeddddZ	dS )Writerr1   _default_orientNr   r0   r2   r3   r4   r6   r7   r8   rF   r:   r>   r;   r?   c
           
      C  sV   || _ |d kr| j}|| _|| _|| _|| _|| _|| _|| _|	| _	d | _
|   d S N)r5   rX   r6   r7   r8   rF   r:   r;   r>   r?   Zis_copy_format_axes)
selfr5   r6   r7   r8   rF   r:   r>   r;   r?   rT   rT   rU   __init__   s    zWriter.__init__c                 C  s   t | d S rZ   r   r\   rT   rT   rU   r[      s    zWriter._format_axesc              
   C  s0   | j dk}t| j| j| j| j| j|| j| jdS )Niso)r6   r8   rF   r:   	iso_datesr;   r?   )	r7   dumpsobj_to_writer6   r8   rF   r:   r;   r?   )r\   r`   rT   rT   rU   rN      s    
zWriter.write"NDFrame | Mapping[IndexLabel, Any]returnc                 C  s   dS )zObject to write in JSON format.NrT   r^   rT   rT   rU   rb      s    zWriter.obj_to_write)Nr   )
__name__
__module____qualname____annotations__r]   r[   rN   propertyr   rb   rT   rT   rT   rU   rW      s   
  rW   c                   @  s*   e Zd ZdZeddddZdd ZdS )	rK   r>   rc   rd   c                 C  s,   | j s"| jdkr"| jj| jjdS | jS d S )NrA   )rE   data)r>   r6   r5   rE   rD   r^   rT   rT   rU   rb      s    zSeriesWriter.obj_to_writec                 C  s*   | j jjs&| jdkr&td| j dd S )Nr>   z(Series index must be unique for orient='')r5   r>   	is_uniquer6   rH   r^   rT   rT   rU   r[      s    zSeriesWriter._format_axesNrf   rg   rh   rX   rj   rb   r[   rT   rT   rT   rU   rK      s   rK   c                   @  s*   e Zd ZdZeddddZdd ZdS )	rL   columnsrc   rd   c                 C  s0   | j s&| jdkr&| jjdd}|d= n| j}|S )NrA   )r6   r>   )r>   r6   r5   Zto_dict)r\   rb   rT   rT   rU   rb      s
    zFrameWriter.obj_to_writec                 C  sP   | j jjs&| jdkr&td| j d| j jjsL| jdkrLtd| j ddS )z:
        Try to format axes if they are datelike.
        )r>   ro   z+DataFrame index must be unique for orient='z'.)r>   ro   rC   z-DataFrame columns must be unique for orient='N)r5   r>   rm   r6   rH   ro   r^   rT   rT   rU   r[      s    zFrameWriter._format_axesNrn   rT   rT   rT   rU   rL      s   rL   c                
      sH   e Zd ZdZdddddddddd	 fd
dZeddddZ  ZS )rJ   rC   Nr   r0   r1   r2   r3   r4   rY   c
                   s.  t  j|||||||||	d	 |dkr:d| d}
t|
t|| jd| _|jdkrht|jt	rht
d|jdkr|jt|jjkst|j|jjrd	}
t|
| }|jd
gdj}t|r|| dd ||< t|jjr|j |_| js
|jdd| _n|jdd| _d| _d| _|| _dS )z
        Adds a `schema` attribute with the Table Schema, resets
        the index (can't do in caller, because the schema inference needs
        to know what the index is, forces orient to records, and forces
        date_format to 'iso'.
        )r;   r?   r_   z8Trying to write with `orient='table'` and `date_format='zH'`. Table Schema requires dates to be formatted with `date_format='iso'`r>      z6orient='table' is not supported for MultiIndex columns   z/Overlapping names between the index and columns	timedelta)includec                 S  s   |   S rZ   )	isoformat)xrT   rT   rU   <lambda>(      z*JSONTableWriter.__init__.<locals>.<lambda>T)ZdropFrC   N)superr]   rH   r)   r>   schemandimrI   ro   r   rM   rE   setnameslenintersectioncopyZselect_dtypesZapplymapr   dtypeZto_timestampZreset_indexr5   r7   r6   )r\   r5   r6   r7   r8   rF   r:   r>   r;   r?   msgZ
timedeltas	__class__rT   rU   r]      sP    
zJSONTableWriter.__init__rc   rd   c                 C  s   | j | jdS )N)rz   rk   )rz   r5   r^   rT   rT   rU   rb   6  s    zJSONTableWriter.obj_to_write)Nr   )rf   rg   rh   rX   r]   rj   rb   __classcell__rT   rT   r   rU   rJ      s     "HrJ   r@   decompression_optionsrP   )r@   r   numpy)Zold_arg_nameZnew_arg_namez2.0   )versionZallowed_args
stacklevelframestrictDtypeArg | None
int | None)
r   keep_default_datesr   precise_floatencoding_errorsr<   	chunksizer=   nrowsr@   c                 C  s   |dkr|rt d|dkr(|r(t d|dkr<|dkr<d}|dkrP|dkrPd}t| |||||||||	|
||||||d}|r|S | | W  5 Q R  S Q R X dS )a  
    Convert a JSON string to pandas object.

    Parameters
    ----------
    path_or_buf : a valid JSON str, path object or file-like object
        Any valid string path is acceptable. The string could be a URL. Valid
        URL schemes include http, ftp, s3, and file. For file URLs, a host is
        expected. A local file could be:
        ``file://localhost/path/to/table.json``.

        If you want to pass in a path object, pandas accepts any
        ``os.PathLike``.

        By file-like object, we refer to objects with a ``read()`` method,
        such as a file handle (e.g. via builtin ``open`` function)
        or ``StringIO``.
    orient : str
        Indication of expected JSON string format.
        Compatible JSON strings can be produced by ``to_json()`` with a
        corresponding orient value.
        The set of possible orients is:

        - ``'split'`` : dict like
          ``{{index -> [index], columns -> [columns], data -> [values]}}``
        - ``'records'`` : list like
          ``[{{column -> value}}, ... , {{column -> value}}]``
        - ``'index'`` : dict like ``{{index -> {{column -> value}}}}``
        - ``'columns'`` : dict like ``{{column -> {{index -> value}}}}``
        - ``'values'`` : just the values array

        The allowed and default values depend on the value
        of the `typ` parameter.

        * when ``typ == 'series'``,

          - allowed orients are ``{{'split','records','index'}}``
          - default is ``'index'``
          - The Series index must be unique for orient ``'index'``.

        * when ``typ == 'frame'``,

          - allowed orients are ``{{'split','records','index',
            'columns','values', 'table'}}``
          - default is ``'columns'``
          - The DataFrame index must be unique for orients ``'index'`` and
            ``'columns'``.
          - The DataFrame columns must be unique for orients ``'index'``,
            ``'columns'``, and ``'records'``.

    typ : {{'frame', 'series'}}, default 'frame'
        The type of object to recover.

    dtype : bool or dict, default None
        If True, infer dtypes; if a dict of column to dtype, then use those;
        if False, then don't infer dtypes at all, applies only to the data.

        For all ``orient`` values except ``'table'``, default is True.

        .. versionchanged:: 0.25.0

           Not applicable for ``orient='table'``.

    convert_axes : bool, default None
        Try to convert the axes to the proper dtypes.

        For all ``orient`` values except ``'table'``, default is True.

        .. versionchanged:: 0.25.0

           Not applicable for ``orient='table'``.

    convert_dates : bool or list of str, default True
        If True then default datelike columns may be converted (depending on
        keep_default_dates).
        If False, no dates will be converted.
        If a list of column names, then those columns will be converted and
        default datelike columns may also be converted (depending on
        keep_default_dates).

    keep_default_dates : bool, default True
        If parsing dates (convert_dates is not False), then try to parse the
        default datelike columns.
        A column label is datelike if

        * it ends with ``'_at'``,

        * it ends with ``'_time'``,

        * it begins with ``'timestamp'``,

        * it is ``'modified'``, or

        * it is ``'date'``.

    numpy : bool, default False
        Direct decoding to numpy arrays. Supports numeric data only, but
        non-numeric column and index labels are supported. Note also that the
        JSON ordering MUST be the same for each term if numpy=True.

        .. deprecated:: 1.0.0

    precise_float : bool, default False
        Set to enable usage of higher precision (strtod) function when
        decoding string to double values. Default (False) is to use fast but
        less precise builtin functionality.

    date_unit : str, default None
        The timestamp unit to detect if converting dates. The default behaviour
        is to try and detect the correct precision, but if this is not desired
        then pass one of 's', 'ms', 'us' or 'ns' to force parsing only seconds,
        milliseconds, microseconds or nanoseconds respectively.

    encoding : str, default is 'utf-8'
        The encoding to use to decode py3 bytes.

    encoding_errors : str, optional, default "strict"
        How encoding errors are treated. `List of possible values
        <https://docs.python.org/3/library/codecs.html#error-handlers>`_ .

        .. versionadded:: 1.3.0

    lines : bool, default False
        Read the file as a json object per line.

    chunksize : int, optional
        Return JsonReader object for iteration.
        See the `line-delimited json docs
        <https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#line-delimited-json>`_
        for more information on ``chunksize``.
        This can only be passed if `lines=True`.
        If this is None, the file will be read into memory all at once.

        .. versionchanged:: 1.2

           ``JsonReader`` is a context manager.

    {decompression_options}

        .. versionchanged:: 1.4.0 Zstandard support.

    nrows : int, optional
        The number of lines from the line-delimited jsonfile that has to be read.
        This can only be passed if `lines=True`.
        If this is None, all the rows will be returned.

        .. versionadded:: 1.1

    {storage_options}

        .. versionadded:: 1.2.0

    Returns
    -------
    Series or DataFrame
        The type returned depends on the value of `typ`.

    See Also
    --------
    DataFrame.to_json : Convert a DataFrame to a JSON string.
    Series.to_json : Convert a Series to a JSON string.
    json_normalize : Normalize semi-structured JSON data into a flat table.

    Notes
    -----
    Specific to ``orient='table'``, if a :class:`DataFrame` with a literal
    :class:`Index` name of `index` gets written with :func:`to_json`, the
    subsequent read operation will incorrectly set the :class:`Index` name to
    ``None``. This is because `index` is also used by :func:`DataFrame.to_json`
    to denote a missing :class:`Index` name, and the subsequent
    :func:`read_json` operation cannot distinguish between the two. The same
    limitation is encountered with a :class:`MultiIndex` and any names
    beginning with ``'level_'``.

    Examples
    --------
    >>> df = pd.DataFrame([['a', 'b'], ['c', 'd']],
    ...                   index=['row 1', 'row 2'],
    ...                   columns=['col 1', 'col 2'])

    Encoding/decoding a Dataframe using ``'split'`` formatted JSON:

    >>> df.to_json(orient='split')
        '{{"columns":["col 1","col 2"],"index":["row 1","row 2"],"data":[["a","b"],["c","d"]]}}'
    >>> pd.read_json(_, orient='split')
          col 1 col 2
    row 1     a     b
    row 2     c     d

    Encoding/decoding a Dataframe using ``'index'`` formatted JSON:

    >>> df.to_json(orient='index')
    '{{"row 1":{{"col 1":"a","col 2":"b"}},"row 2":{{"col 1":"c","col 2":"d"}}}}'

    >>> pd.read_json(_, orient='index')
          col 1 col 2
    row 1     a     b
    row 2     c     d

    Encoding/decoding a Dataframe using ``'records'`` formatted JSON.
    Note that index labels are not preserved with this encoding.

    >>> df.to_json(orient='records')
    '[{{"col 1":"a","col 2":"b"}},{{"col 1":"c","col 2":"d"}}]'
    >>> pd.read_json(_, orient='records')
      col 1 col 2
    0     a     b
    1     c     d

    Encoding with Table Schema

    >>> df.to_json(orient='table')
        '{{"schema":{{"fields":[{{"name":"index","type":"string"}},{{"name":"col 1","type":"string"}},{{"name":"col 2","type":"string"}}],"primaryKey":["index"],"pandas_version":"1.4.0"}},"data":[{{"index":"row 1","col 1":"a","col 2":"b"}},{{"index":"row 2","col 1":"c","col 2":"d"}}]}}'
    rB   z)cannot pass both dtype and orient='table'z0cannot pass both convert_axes and orient='table'NT)r6   typr   convert_axesconvert_datesr   r   r   r:   encodingr<   r   r=   r   r@   r   )rH   
JsonReaderread)rP   r6   r   r   r   r   r   r   r   r:   r   r   r<   r   r=   r   r@   Zjson_readerrT   rT   rU   	read_json;  sB      r   c                   @  s~   e Zd ZdZd dddddddddd		d
dZdd Zdd ZddddZdd Zdd Z	dd Z
dd Zdd Zdd ZdS )!r   z
    JsonReader provides an interface for reading in a JSON file.

    If initialized with ``lines=True`` and ``chunksize``, can be iterated over
    ``chunksize`` lines at a time. Otherwise, calling ``read`` reads in the
    whole document.
    Nr   r3   r   r   r   r0   )	r   r   r   r<   r   r=   r   r@   r   c                 C  s   || _ || _|| _|| _|| _|| _|| _|	| _|
| _|| _	|| _
|| _|| _|| _d| _|| _|| _d | _| jd k	rtd| jd| _| jstd| jd k	rtd| jd| _| jstd| |}| || _d S )Nr   r   rr   z*chunksize can only be passed if lines=Truer   z&nrows can only be passed if lines=True)r6   r   r   r   r   r   r   r   r:   r   r=   r@   r<   r   
nrows_seenr   r   rS   r+   rH   _get_data_from_filepath_preprocess_datark   )r\   filepath_or_bufferr6   r   r   r   r   r   r   r   r:   r   r<   r   r=   r   r@   r   rk   rT   rT   rU   r]   p  s8    


zJsonReader.__init__c              	   C  sP   t |dr.| js.| js.|  | }W 5 Q R X t |dsL| jsD| jrLt|}|S )a&  
        At this point, the data either has a `read` attribute (e.g. a file
        object or a StringIO) or is a string that is a JSON document.

        If self.chunksize, we prepare the data for the `__next__` method.
        Otherwise, we read it into memory for the `read` method.
        r   )hasattrr   r   r   r   )r\   rk   rT   rT   rU   r     s    zJsonReader._preprocess_datac                 C  sT   t |}t|tr*t|s*t|s*t|rPt|d| j| j| j	| j
d| _| jj}|S )aL  
        The function read_json accepts three input types:
            1. filepath (string-like)
            2. file-like object (e.g. open file object, StringIO)
            3. JSON string

        This method turns (1) into (2) to simplify the rest of the processing.
        It returns input types (2) and (3) unchanged.
        r)r   r=   r@   errors)r'   rI   r1   r&   r%   r#   r$   r   r=   r@   r   rS   rO   )r\   r   rT   rT   rU   r     s&    z"JsonReader._get_data_from_filepathr1   rd   c                 C  s&   dd dd dd |D D  dS )zG
        Combines a list of JSON objects into one JSON object.
        [,c                 S  s   g | ]}|r|qS rT   rT   .0linerT   rT   rU   
<listcomp>  s      z-JsonReader._combine_lines.<locals>.<listcomp>c                 s  s   | ]}|  V  qd S rZ   )stripr   rT   rT   rU   	<genexpr>  s     z,JsonReader._combine_lines.<locals>.<genexpr>])join)r\   r<   rT   rT   rU   _combine_lines  s    $zJsonReader._combine_linesc                 C  s   | j rj| jrt| }qv| jrDtt| j| j}| |}| |}qvt	| j}|
d}| | |}n| | j}|   |S )zA
        Read the whole JSON input into a pandas object.
        
)r<   r   r    r   listr   rk   r   _get_object_parserr   rA   close)r\   r5   r<   
lines_jsonrk   Z
data_linesrT   rT   rU   r     s    



zJsonReader.readc              	   C  s   | j }| j}| j| j| j| j| j| j| j| jd}d}|dkrNt	|f|
 }|dks^|dkrt|tsp||d< t|f|
 }|S )z>
        Parses a json document into a pandas object.
        )r6   r   r   r   r   r   r   r:   Nr   Zseriesr   )r   r   r6   r   r   r   r   r   r:   FrameParserparserI   r3   SeriesParser)r\   jsonr   r   kwargsr5   rT   rT   rU   r     s&    

zJsonReader._get_object_parserc                 C  s   | j dk	r| j   dS )z
        If we opened a stream earlier, in _get_data_from_filepath, we should
        close it.

        If an open stream or file was passed, we leave it open.
        N)rS   r   r^   rT   rT   rU   r   	  s    
zJsonReader.closec                 C  s   | j r| j| j kr|   ttt| j| j}|rv| |}| 	|}t
| j| jt| |_|  jt|7  _|S |   td S rZ   )r   r   r   StopIterationr   r   rk   r   r   r   ranger~   r>   )r\   r<   r   r5   rT   rT   rU   __next__  s    

zJsonReader.__next__c                 C  s   | S rZ   rT   r^   rT   rT   rU   	__enter__'  s    zJsonReader.__enter__c                 C  s   |    d S rZ   )r   )r\   exc_type	exc_value	tracebackrT   rT   rU   __exit__*  s    zJsonReader.__exit__)Nr   )rf   rg   rh   __doc__r]   r   r   r   r   r   r   r   r   r   rT   rT   rT   rU   r   g  s      4
r   c                   @  s   e Zd ZU ded< ded< dZdddd	dZd%ddddZdd Zdd Zdd Z	dd Z
dd Zdd Zd&ddddd Zd!d" Zd#d$ Zd
S )'Parserztuple[str, ...]_split_keysr1   rX   )rR   r.   usnsi3l    ,b/ l    `'rl     F[L'NTFr   r   c
           
      C  s   || _ |d kr| j}|| _|| _|dkr,d}|	d k	rd|	 }	|	| jkrVtd| j | j|	 | _n| jd | _|| _	|| _
|| _|| _|	| _|| _d | _d S )NrA   Fzdate_unit must be one of rR   )r   rX   r6   r   lower_STAMP_UNITSrH   _MIN_STAMPS	min_stampr   r   r   r   r:   r   r5   )
r\   r   r6   r   r   r   r   r   r   r:   rT   rT   rU   r]   :  s(    
zParser.__init__c                 C  s8   t | t | j}|r4d|}td| dS )zT
        Checks that dict has only the appropriate keys for orient='split'.
        z, z!JSON data had unexpected key(s): N)r|   keys
differencer   r   rH   )r\   decodedZbad_keysZbad_keys_joinedrT   rT   rU   check_keys_splitb  s    
zParser.check_keys_splitc                 C  sB   | j r|   n|   | jd kr&d S | jr4|   |   | jS rZ   )r   _parse_numpy_parse_no_numpyr5   r   _convert_axes_try_convert_typesr^   rT   rT   rU   r   k  s    

zParser.parsec                 C  s   t | d S rZ   r   r^   rT   rT   rU   r   y  s    zParser._parse_numpyc                 C  s   t | d S rZ   r   r^   rT   rT   rU   r   |  s    zParser._parse_no_numpyc                 C  sP   | j }|dk	st|jD ]2}| j|||ddd\}}|rt| j || qdS )z&
        Try to convert axes.
        NFT)rE   rk   
use_dtypesr   )r5   AssertionErrorZ_AXIS_ORDERS_try_convert_dataZ	_get_axissetattr)r\   r5   Z	axis_nameZnew_axisresultrT   rT   rU   r     s    

zParser._convert_axesc                 C  s   t | d S rZ   r   r^   rT   rT   rU   r     s    zParser._try_convert_typesr3   )r   r   c              
   C  s  |r| j s.tt|r|dfS |tjdfS | j dkr:nXt| j trR| j |n| j }|dk	rz|	|dfW S  t
tfk
r   |df Y S X |r| |\}}|r|dfS |j dkrz|	d}W n t
tfk
r   Y nX |j jdkr&|j dkr&z|	d}W n t
tfk
r$   Y nX t|r|j dksH|j dkrz |	d}||k rf|}W n t
ttfk
r   Y nX |j d	krz|	d}W n t
tfk
r   Y nX |d
krt|r| jdkr|dfS |dfS )zO
        Try to parse a ndarray like into a column by inferring dtype.
        FTNobjectZfloat64ffloatint64r2   r>   rA   )r   allr   ZfillnanpnanrI   dictgetastype	TypeErrorrH   _try_convert_to_datekindr~   OverflowErrorr6   )r\   rE   rk   r   r   r   new_datar   rT   rT   rU   r     sZ    

"
zParser._try_convert_datac                 C  s   t |s|dfS |}|jdkrHz|d}W n tttfk
rF   Y nX t|jjtj	rt
|j|| jkB |jtkB }| s|dfS | jr| jfn| j}|D ]@}zt|d|d}W n tttfk
r   Y qY nX |df  S |dfS )z
        Try to parse a ndarray like into a date column.

        Try to coerce object in epoch/iso formats and integer/float in epoch
        formats. Return a boolean if parsing was successful.
        Fr   r   raise)r   unitT)r~   r   r   r   rH   r   
issubclasstyper   numberr   Z_valuesr   r   r   r:   r   r   )r\   rk   r   Zin_rangeZ
date_unitsr:   rT   rT   rU   r     s2    

zParser._try_convert_to_datec                 C  s   t | d S rZ   r   r^   rT   rT   rU   _try_convert_dates  s    zParser._try_convert_dates)NTTFFFN)TT)rf   rg   rh   ri   r   r   r]   r   r   r   r   r   r   r   r   r   rT   rT   rT   rU   r   .  s6   
       (	   Q%r   c                   @  s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
r   r>   )rE   r>   rk   c                 C  sV   t | j| jd}| jdkrDdd | D }| | tf || _nt|td| _d S )Nr   rA   c                 S  s   i | ]\}}t ||qS rT   r1   r   kvrT   rT   rU   
<dictcomp>  s      z0SeriesParser._parse_no_numpy.<locals>.<dictcomp>dtype_if_empty)	loadsr   r   r6   itemsr   r   r5   r   )r\   rk   r   rT   rT   rU   r     s    

zSeriesParser._parse_no_numpyc                 C  s   d d| j d}| jdkr d|d< tjtf|}|| j}| jdkrldd | D }| | tf || _	n*| jdkrt|dt
i| _	nt|t
d	| _	d S )
NTr   r   r   )ro   r>   labelledrA   c                 S  s   i | ]\}}t ||qS rT   r   r   rT   rT   rU   r   &  s      z-SeriesParser._parse_numpy.<locals>.<dictcomp>r   r   )r   r6   	functoolspartialr   r   r   r   r   r5   r   )r\   Zload_kwargsZloads_rk   r   rT   rT   rU   r     s&    





zSeriesParser._parse_numpyc                 C  s4   | j d krd S | jd| j | jd\}}|r0|| _ d S )Nrk   r   )r5   r   r   )r\   r5   r   rT   rT   rU   r   2  s    
  
zSeriesParser._try_convert_typesN)rf   rg   rh   rX   r   r   r   r   rT   rT   rT   rU   r     s
   
r   c                   @  s>   e Zd ZdZdZdd Zdd Zddd	Zd
d Zdd Z	dS )r   ro   )ro   r>   rk   c                 C  s   | j }| j}|dkrTt|d dd| jd}t|rH|d j|d |d f}t| | _n|dkrt|d d| jd}d	d
 | D }| 	| tf || _n<|dkrtt|d d| jd| _ntt|d dd| jd | _d S )Nro   T)r   r   r   r   r   rq   rr   rA   r   c                 S  s   i | ]\}}t ||qS rT   r   r   rT   rT   rU   r   T  s      z,FrameParser._parse_numpy.<locals>.<dictcomp>rD   )
r   r6   r   r   r~   Tr   r5   r   r   )r\   r   r6   argsr   rT   rT   rU   r   @  sH       
zFrameParser._parse_numpyc                 C  s   | j }| j}|dkr.tt|| jdd d| _n|dkrrdd t|| jd D }| | tf dd i|| _nX|dkrtjt|| jdd dd	| _n2|d
krt	|| jd| _ntt|| jdd d| _d S )Nro   r   r   rA   c                 S  s   i | ]\}}t ||qS rT   r   r   rT   rT   rU   r   p  s    z/FrameParser._parse_no_numpy.<locals>.<dictcomp>r   r>   )r   r6   rB   )
r   r6   r   r   r   r5   r   r   	from_dictr*   )r\   r   r6   r   rT   rT   rU   r   f  s2     


 zFrameParser._parse_no_numpyNc                 C  s   |dkrdd }| j }|dk	s"td}i }t| D ]8\}\}}|||rf|||\}	}
|
rf|	}d}|||< q6|rt||jd}|j|_|| _ dS )zM
        Take a conversion function and possibly recreate the frame.
        Nc                 S  s   dS )NTrT   colcrT   rT   rU   rw     rx   z0FrameParser._process_converter.<locals>.<lambda>FTrp   )r5   r   	enumerater   r   r>   ro   )r\   r   Zfiltr5   Zneeds_new_objZnew_objir   r   r   r   Z	new_framerT   rT   rU   _process_converter  s"    

zFrameParser._process_converterc                   s2    j d krd S  jr     fdd d S )Nc                   s    j | |ddS )NFr   )r   r   r^   rT   rU   rw     rx   z0FrameParser._try_convert_types.<locals>.<lambda>)r5   r   r   r  r^   rT   r^   rU   r     s    

zFrameParser._try_convert_typesc                   sZ   j d krd S j  dkr g  t  ddddfdd fdd d S )	NTr3   rd   c                 S  sT   t | tsdS |  }|dsL|dsL|dksL|dksL|dksL|drPdS dS )	zK
            Return if this col is ok to try for a date parse.
            FZ_at_timemodifieddatedatetime	timestampT)rI   r1   r   endswith
startswith)r   Z	col_lowerrT   rT   rU   is_ok  s"    
z-FrameParser._try_convert_dates.<locals>.is_okc                   s
     |S rZ   )r   r   r^   rT   rU   rw     rx   z0FrameParser._try_convert_dates.<locals>.<lambda>c                   s   j r| p|  kS rZ   )r   r   r   r
  r\   rT   rU   rw     s    )r5   r   r|   r  r^   rT   r  rU   r     s    

zFrameParser._try_convert_dates)N)
rf   rg   rh   rX   r   r   r   r  r   r   rT   rT   rT   rU   r   <  s   &

r   )Nr,   r-   Tr.   NFr/   Tr   N)NNr   NNTTFFNNr   FNr/   NN)O
__future__r   r   r   r   collectionsr   ior   	itertoolsr   typingr   r	   r
   r   r   Zpandas._libs.jsonZ_libsr   Zpandas._libs.tslibsr   Zpandas._typingr   r   r   r   r   Zpandas.errorsr   Zpandas.util._decoratorsr   r   r   Zpandas.core.dtypes.commonr   r   Zpandasr   r   r   r   r   r   Zpandas.core.constructionr   Zpandas.core.genericr   Zpandas.core.reshape.concatr    Zpandas.core.shared_docsr!   Zpandas.io.commonr"   r#   r$   r%   r&   r'   Zpandas.io.json._normalizer(   Zpandas.io.json._table_schemar)   r*   Zpandas.io.parsers.readersr+   r   ra   rV   rW   rK   rL   rJ   r   Iteratorr   r   r   r   rT   rT   rT   rU   <module>   s                &>7P

                   (  & H _0