Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pandas/io/json/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pandas/io/json/__pycache__/_normalize.cpython-312.pyc

�

Mٜg<C�� �ddlmZddlmZmZddlZddlmZmZm	Z	ddl
Zddlm
Z
ddlZddlmZerddlmZddlmZmZdd	�Z				d							dd
�Z										dd�Zdd�Z	d					dd
�Z							d																	dd�Zy)�)�annotations)�abc�defaultdictN)�
TYPE_CHECKING�Any�DefaultDict��convert_json_to_lines)�	DataFrame)�Iterable)�IgnoreRaise�Scalarc�F�|ddk(s
|ddk(r|S|dd}t|�S)zJ
    Helper function that converts JSON lists to line delimited JSON.
    r�[����]�r	)�ss �D/usr/local/lib/python3.12/site-packages/pandas/io/json/_normalize.py�convert_to_line_delimitsr s4��
�Q�4�3�;�1�R�5�C�<���	�!�B��A� ��#�#�c���d}t|t�r|g}d}g}|D]�}tj|�}|j	�D]�\}	}
t|	t
�st|	�}	|dk(r|	}n||z|	z}t|
t�r|�!||k\r|dk7r|j
|	�}
|
||<�d|j
|	�}
|jt|
|||dz|����|j|���|r|dS|S)a�
    A simplified json_normalize

    Converts a nested dict into a flat dict ("record"), unlike json_normalize,
    it does not attempt to extract a subset of the data.

    Parameters
    ----------
    ds : dict or list of dicts
    prefix: the prefix, optional, default: ""
    sep : str, default '.'
        Nested records will generate names separated by sep,
        e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar
    level: int, optional, default: 0
        The number of levels in the json string.

    max_level: int, optional, default: None
        The max depth to normalize.

    Returns
    -------
    d - dict or list of dicts, matching `ds`

    Examples
    --------
    >>> nested_to_record(
    ...     dict(flat1=1, dict1=dict(c=1, d=2), nested=dict(e=dict(c=1, d=2), d=2))
    ... )
    {'flat1': 1, 'dict1.c': 1, 'dict1.d': 2, 'nested.e.c': 1, 'nested.e.d': 2, 'nested.d': 2}
    FTrr)
�
isinstance�dict�copy�deepcopy�items�str�pop�update�nested_to_record�append)�ds�prefix�sep�level�	max_level�	singleton�new_ds�d�new_d�k�v�newkeys            rr!r!-s��X�I��"�d���T���	�
�F�
���
�
�a� ���G�G�I�D�A�q��a��%���F����z����#���)���a��&��%�%�9�*<��A�:��	�	�!��A�$%�E�&�M���	�	�!��A��L�L�)�!�V�S�%�!�)�Y�O�P�-�.	�
�
�e��3�6��a�y���Mrc��t|t�rD|j�D]/\}}|�|�|��}|s|j|�}t	||||���1|S|||<|S)a3
    Main recursive function
    Designed for the most basic use case of pd.json_normalize(data)
    intended as a performance improvement, see #15621

    Parameters
    ----------
    data : Any
        Type dependent on types contained within nested Json
    key_string : str
        New key (with separator(s) in) for data
    normalized_dict : dict
        The new normalized/flattened Json dict
    separator : str, default '.'
        Nested records will generate names separated by sep,
        e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar
    ��data�
key_string�normalized_dict�	separator)rrr�removeprefix�_normalise_json)r1r2r3r4�key�value�new_keys       rr6r6~su��.�$����*�*�,�J�C��#��Y�K��u�5�G��!�.�.�y�9����"� /�#�	
�
'���'+��
�#��rc
��|j�D��cic]\}}t|t�r�||��}}}t|j�D��cic]\}}t|t�s�||��c}}di|��}i|�|�Scc}}wcc}}w)aw
    Order the top level keys and then recursively go to depth

    Parameters
    ----------
    data : dict or list of dicts
    separator : str, default '.'
        Nested records will generate names separated by sep,
        e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar

    Returns
    -------
    dict or list of dicts, matching `normalised_json_object`
    �r0)rrrr6)r1r4r,r-�	top_dict_�nested_dict_s      r�_normalise_json_orderedr>�s���#'�*�*�,�J�,�$�!�Q�j��D�6I��A��,�I�J�"�#�z�z�|�
C�|�t�q�!�z�!�T�/B�a��d�|�
C����	�L�)�i�(�<�(�(��K��
Cs�A=�A=�
B
�&B
c��i}t|t�rt||��}|St|t�r|D�cgc]}t	||����}}|S|Scc}w)a�
    A optimized basic json_normalize

    Converts a nested dict into a flat dict ("record"), unlike
    json_normalize and nested_to_record it doesn't do anything clever.
    But for the most basic use cases it enhances performance.
    E.g. pd.json_normalize(data)

    Parameters
    ----------
    ds : dict or list of dicts
    sep : str, default '.'
        Nested records will generate names separated by sep,
        e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar

    Returns
    -------
    frame : DataFrame
    d - dict or list of dicts, matching `normalised_json_object`

    Examples
    --------
    >>> _simple_json_normalize(
    ...     {
    ...         "flat1": 1,
    ...         "dict1": {"c": 1, "d": 2},
    ...         "nested": {"e": {"c": 1, "d": 2}, "d": 2},
    ...     }
    ... )
    {'flat1': 1, 'dict1.c': 1, 'dict1.d': 2, 'nested.e.c': 1, 'nested.e.d': 2, 'nested.d': 2}

    )r1r4�r%)rrr>�list�_simple_json_normalize)r#r%�normalised_json_object�row�normalised_json_lists     rrBrB�sg��V ���"�d��!8�b�C�!P��"�!�
�B��	�PR�S�PR�� 6�s�� D�PR��S�#�#�!�!�� Ts�Ac��������������	d							d�fd�
�d�fd��t|t�r|s
t�St|t�r|g}n<t|tj
�rt|t�st|�}nt�|�|�|�����tt|����S|�+td�|D��rt|����}t|�St|t�s|g}|�g}nt|t�s|g}|D�cgc]}t|t�r|n|g��c}�g�g�tt���D�	cgc]}	�j|	���c}	�dd����������f
d�
��||id��t��}
��|
j�fd	��
�}
�j�D]�\}}|�||z}||
vrtd|�d���t!j"|t$�
�}
|
j&dkDr=t!j(t+|�ft$�
�}
t-|�D]
\}}||
|<�|
j/��|
|<��|
Scc}wcc}	w)a�
    Normalize semi-structured JSON data into a flat table.

    Parameters
    ----------
    data : dict or list of dicts
        Unserialized JSON objects.
    record_path : str or list of str, default None
        Path in each object to list of records. If not passed, data will be
        assumed to be an array of records.
    meta : list of paths (str or list of str), default None
        Fields to use as metadata for each record in resulting table.
    meta_prefix : str, default None
        If True, prefix records with dotted (?) path, e.g. foo.bar.field if
        meta is ['foo', 'bar'].
    record_prefix : str, default None
        If True, prefix records with dotted (?) path, e.g. foo.bar.field if
        path to records is ['foo', 'bar'].
    errors : {'raise', 'ignore'}, default 'raise'
        Configures error handling.

        * 'ignore' : will ignore KeyError if keys listed in meta are not
          always present.
        * 'raise' : will raise KeyError if keys listed in meta are not
          always present.
    sep : str, default '.'
        Nested records will generate names separated by sep.
        e.g., for sep='.', {'foo': {'bar': 0}} -> foo.bar.
    max_level : int, default None
        Max number of levels(depth of dict) to normalize.
        if None, normalizes all levels.

    Returns
    -------
    frame : DataFrame
    Normalize semi-structured JSON data into a flat table.

    Examples
    --------
    >>> data = [
    ...     {"id": 1, "name": {"first": "Coleen", "last": "Volk"}},
    ...     {"name": {"given": "Mark", "family": "Regner"}},
    ...     {"id": 2, "name": "Faye Raker"},
    ... ]
    >>> pd.json_normalize(data)
        id name.first name.last name.given name.family        name
    0  1.0     Coleen      Volk        NaN         NaN         NaN
    1  NaN        NaN       NaN       Mark      Regner         NaN
    2  2.0        NaN       NaN        NaN         NaN  Faye Raker

    >>> data = [
    ...     {
    ...         "id": 1,
    ...         "name": "Cole Volk",
    ...         "fitness": {"height": 130, "weight": 60},
    ...     },
    ...     {"name": "Mark Reg", "fitness": {"height": 130, "weight": 60}},
    ...     {
    ...         "id": 2,
    ...         "name": "Faye Raker",
    ...         "fitness": {"height": 130, "weight": 60},
    ...     },
    ... ]
    >>> pd.json_normalize(data, max_level=0)
        id        name                        fitness
    0  1.0   Cole Volk  {'height': 130, 'weight': 60}
    1  NaN    Mark Reg  {'height': 130, 'weight': 60}
    2  2.0  Faye Raker  {'height': 130, 'weight': 60}

    Normalizes nested data up to level 1.

    >>> data = [
    ...     {
    ...         "id": 1,
    ...         "name": "Cole Volk",
    ...         "fitness": {"height": 130, "weight": 60},
    ...     },
    ...     {"name": "Mark Reg", "fitness": {"height": 130, "weight": 60}},
    ...     {
    ...         "id": 2,
    ...         "name": "Faye Raker",
    ...         "fitness": {"height": 130, "weight": 60},
    ...     },
    ... ]
    >>> pd.json_normalize(data, max_level=1)
        id        name  fitness.height  fitness.weight
    0  1.0   Cole Volk             130              60
    1  NaN    Mark Reg             130              60
    2  2.0  Faye Raker             130              60

    >>> data = [
    ...     {
    ...         "state": "Florida",
    ...         "shortname": "FL",
    ...         "info": {"governor": "Rick Scott"},
    ...         "counties": [
    ...             {"name": "Dade", "population": 12345},
    ...             {"name": "Broward", "population": 40000},
    ...             {"name": "Palm Beach", "population": 60000},
    ...         ],
    ...     },
    ...     {
    ...         "state": "Ohio",
    ...         "shortname": "OH",
    ...         "info": {"governor": "John Kasich"},
    ...         "counties": [
    ...             {"name": "Summit", "population": 1234},
    ...             {"name": "Cuyahoga", "population": 1337},
    ...         ],
    ...     },
    ... ]
    >>> result = pd.json_normalize(
    ...     data, "counties", ["state", "shortname", ["info", "governor"]]
    ... )
    >>> result
             name  population    state shortname info.governor
    0        Dade       12345   Florida    FL    Rick Scott
    1     Broward       40000   Florida    FL    Rick Scott
    2  Palm Beach       60000   Florida    FL    Rick Scott
    3      Summit        1234   Ohio       OH    John Kasich
    4    Cuyahoga        1337   Ohio       OH    John Kasich

    >>> data = {"A": [1, 2]}
    >>> pd.json_normalize(data, "A", record_prefix="Prefix.")
        Prefix.0
    0          1
    1          2

    Returns normalized data with columns prefixed with the given string.
    c���|}	t|t�r|D]}|�t|��||}�	|S||}	|S#t$rD}|rtd|�d��|��dk(rtjcYd}~Std|�d|�d��|�d}~wwxYw)zInternal function to pull fieldNzKey zS not found. If specifying a record_path, all elements of data should have the path.�ignorez) not found. To replace missing values of z% with np.nan, pass in errors='ignore')rrA�KeyError�np�nan)�js�spec�extract_record�result�field�e�errorss      �r�_pull_fieldz#json_normalize.<locals>._pull_field�s������	��$��%�!�E��~�&�u�o�-�#�E�]�F�"�(�
� �����
���	����1�#�1�2������!��v�v�
���1�#�F�q�c�J6�7�����	�s%�)9�9�	B�&B�(B�.B�Bc����||d��}t|t�s-tj|�rg}|St	|�d|�d|�d���|S)z�
        Internal function to pull field for records, and similar to
        _pull_field, but require to return list. And will raise error
        if has non iterable value.
        T)rNz has non list value z
 for path z. Must be list or null.)rrA�pd�isnull�	TypeError)rLrMrOrSs   �r�
_pull_recordsz%json_normalize.<locals>._pull_records�sj����R��d�;���&�$�'��y�y�� ����
�	 ��d�.�v�h�j���G,�,����
rr@c3�~K�|]0}|j�D�cgc]}t|t���c}���2ycc}w�w�N)�valuesrr)�.0�y�xs   r�	<genexpr>z!json_normalize.<locals>.<genexpr>�s0����G�$�Q�Q�X�X�Z�8�Z��
�1�d�#�Z�8�$��8�s�=�8�
=�r%r'rc	�h�
�t|t�r|g}t|�dkDrU|D]O}t�
��D]&\}}|dzt|�k(s��||d�||<�(�
||d|dd||dz���Qy|D]�}�||d�}|D�cgc]"}t|t�rt	|����n|��$}}�jt|��t�
��D]<\}}|dzt|�kDr||}	n�|||d�}	�|j|	��>�j
|���ycc}w)Nrrr�r&r`)rr�len�zipr!r"�extend)r1�path�	seen_metar&�obj�valr7�recs�r�meta_val�_metarSrX�_recursive_extract�lengthsr'�	meta_keys�	meta_vals�recordsr%s          ����������rrnz*json_normalize.<locals>._recursive_extract�s[����d�D�!��6�D��t�9�q�=��� #�E�9� 5�H�C���q�y�C��H�,�)4�S�#�b�'�)B�	�#��!6�#�3�t�A�w�<��a�b��9�E�TU�I�V����$�S�$�q�'�2��
"�	�"��"�!�T�*�%�Q�C�9�E���"�	�����s�4�y�)� #�E�9� 5�H�C���q�y�3�s�8�+�#,�S�>��#.�s�C���K�#@���c�N�)�)�(�3�!6����t�$�#��s�
'D/rbc�����|��SrZ�)r^�
record_prefixs �r�<lambda>z json_normalize.<locals>.<lambda>
s���M�?�1�#�1Fr)�columnszConflicting metadata name z, need distinguishing prefix )�dtyper)F)rL�dict[str, Any]rM�
list | strrN�bool�returnzScalar | Iterable)rLryrMrzr|rA)r)r&�intr|�None)rrArrrrr�NotImplementedErrorrB�anyr!r�join�renamer�
ValueErrorrJ�array�object�ndim�emptyrc�	enumerate�repeat)r1�record_path�meta�meta_prefixrurRr%r'�mrirOr,r-r[�irmrSrXrnrorprqrrs    ````       @@@@@@@@r�json_normalizer��s]����\FK����",��>B��	��:�(�$���d��{��	�D�$�	��v��	�D�#�,�,�	'�
�4��0E��D�z��!�!�	���L����!����/��#�>�?�?����G�$�G�G�$�D�c�Y�G�D�����
��T�
*�"�m���|���
��d�
#��v��8<�=��1�*�Q��%�Q�A�3�
.��=�E��G��G�(��.�I�*/�0�%�3����#��%�0�I�%�%�<�t�[�"�A�6�
�w�
�F�� ����'F��G�����!���1��"��a��A���;��,�Q�C�/L�M��
�
���!�6�*���;�;��?��X�X�s�1�v�i�v�6�F�!�!����1���q�	�%��M�M�'�*��q�	�%"�&�M��E
>��1s�
I�I
)rrr|r)r;�.rN)r$rr%rr&r}r'�
int | None)
r1rr2rr3ryr4rr|ry)r1ryr4rr|ry)r�)r#�dict | list[dict]r%rr|zdict | list[dict] | Any)NNNN�raiser�N)r1r�r�zstr | list | Noner�z"str | list[str | list[str]] | Noner��
str | Nonerur�rRr
r%rr'r�r|r)�
__future__r�collectionsrrr�typingrrr�numpyrJ�pandas._libs.writersr
�pandasrUr�collections.abcr�pandas._typingr
rrr!r6r>rBr�rtrr�<module>r�sU��#������6����(��
$���� �N��N�

�N��	N�
�N�b&�

�&��&�$�&��	&�
�&�R)�6�2"��2"�	�2"��2"�n&*�/3�"� $�!�� �k�
�k�"�k�-�k��	k�
�k�
�
k�

�k��k��kr

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists