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__/_table_schema.cpython-312.pyc

�

MٜgJ-��J�dZddlmZddlmZmZmZddlZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZdd
lmZddlmZmZmZmZddlmZmZmZmZdd
lm Z ddl!m"cm#Z$ddl%m&Z&erddl'm(Z(m)Z)ddlm*Z*ddl+m,Z,dZ-dd�Z.d�Z/dd�Z0dd�Z1			d									dd�Z2dd�Z3y)zH
Table Schema builders

https://specs.frictionlessdata.io/table-schema/
�)�annotations)�
TYPE_CHECKING�Any�castN)�lib)�ujson_loads)�	timezones)�freq_to_period_freqstr)�find_stack_level)�	_registry)�
is_bool_dtype�is_integer_dtype�is_numeric_dtype�is_string_dtype)�CategoricalDtype�DatetimeTZDtype�ExtensionDtype�PeriodDtype)�	DataFrame)�	to_offset)�DtypeObj�JSONSerializable)�Series)�
MultiIndexz1.4.0c��t|�ryt|�ryt|�rytj|d�st|ttf�rytj|d�ryt|t�ryt|�ry	y)
a�
    Convert a NumPy / pandas type to its corresponding json_table.

    Parameters
    ----------
    x : np.dtype or ExtensionDtype

    Returns
    -------
    str
        the Table Schema data types

    Notes
    -----
    This table shows the relationship between NumPy / pandas dtypes,
    and Table Schema dtypes.

    ==============  =================
    Pandas type     Table Schema type
    ==============  =================
    int64           integer
    float64         number
    bool            boolean
    datetime64[ns]  datetime
    timedelta64[ns] duration
    object          str
    categorical     any
    =============== =================
    �integer�boolean�number�M�datetime�m�duration�any�string)
rr
rr�is_np_dtype�
isinstancerrrr)�xs �G/usr/local/lib/python3.12/site-packages/pandas/io/json/_table_schema.py�as_json_table_typer)5sp��<����	�q�	��	�!�	��	����C�	 �J�q�?�K�2P�$Q��	����C�	 ��	�A�~�	&��	��	���c��tj|jj�r�|jj}t	|�dk(r:|jj
dk(r!t
jdt���|St	|�dkDr1td�|D��rt
jdt���|S|j�}|jjdkDr:tj|jj�|j_|S|jj
xsd|j_|S)z?Sets index names to 'index' for regular, or 'level_x' for Multi��indexz-Index name of 'index' is not round-trippable.)�
stacklevelc3�>K�|]}|jd����y�w)�level_N)�
startswith)�.0r's  r(�	<genexpr>z$set_default_names.<locals>.<genexpr>ns����!F�#�Q�!�,�,�x�"8�#�s�z<Index names beginning with 'level_' are not round-trippable.)
�com�all_not_noner-�names�len�name�warnings�warnrr#�copy�nlevels�fill_missing_names)�data�nmss  r(�set_default_namesr@es���
������)�)�*��j�j�����s�8�q�=�T�Z�Z�_�_��7��M�M�?�+�-�
�����X��\�c�!F�#�!F�F��M�M�N�+�-�
����9�9�;�D��z�z���A���1�1�$�*�*�2B�2B�C��
�
���K��*�*�/�/�4�W��
�
���Kr*c�$�|j}|j�d}n|j}|t|�d�}t|t�r/|j
}|j}dt|�i|d<||d<|St|t�r|jj|d<|St|t�rAtj|j�rd|d<|S|jj|d<|St|t �r|j|d	<|S)
N�values)r8�type�enum�constraints�ordered�freq�UTC�tz�extDtype)�dtyper8r)r&r�
categoriesrF�listrrG�freqstrrr	�is_utcrI�zoner)�arrrKr8�field�catsrFs      r(�!convert_pandas_type_to_json_fieldrT}s���I�I�E�
�x�x�����x�x���"�5�)�*�E�
�%�)�*������-�-�� &��T�
�3��m��"��i���L�
�E�;�	'��
�
�*�*��f�
��L�
�E�?�	+����E�H�H�%��E�$�K��L� �(�(�-�-�E�$�K��L�
�E�>�	*�!�J�J��j���Lr*c��|d}|dk(ry|dk(r|jdd�S|dk(r|jdd�S|d	k(r|jdd
�S|dk(ry|d
k(rd|jd�r	d|d�d�S|jd�r8t|d�}|j|j}}t	||�}d|�d�Sy|dk(r;d|vrd|vrt|dd|d��Sd|vrt
j|d�Sytd|����)a
    Converts a JSON field descriptor into its corresponding NumPy / pandas type

    Parameters
    ----------
    field
        A JSON field descriptor

    Returns
    -------
    dtype

    Raises
    ------
    ValueError
        If the type of the provided field is unknown or currently unsupported

    Examples
    --------
    >>> convert_json_field_to_pandas_type({"name": "an_int", "type": "integer"})
    'int64'

    >>> convert_json_field_to_pandas_type(
    ...     {
    ...         "name": "a_categorical",
    ...         "type": "any",
    ...         "constraints": {"enum": ["a", "b", "c"]},
    ...         "ordered": True,
    ...     }
    ... )
    CategoricalDtype(categories=['a', 'b', 'c'], ordered=True, categories_dtype=object)

    >>> convert_json_field_to_pandas_type({"name": "a_datetime", "type": "datetime"})
    'datetime64[ns]'

    >>> convert_json_field_to_pandas_type(
    ...     {"name": "a_datetime_with_tz", "type": "datetime", "tz": "US/Central"}
    ... )
    'datetime64[ns, US/Central]'
    rCr$�objectrrJ�int64r�float64r�boolr"�timedelta64r rIzdatetime64[ns, �]rGzperiod[zdatetime64[ns]r#rErFrD)rLrFz#Unsupported or invalid field type: )	�getr�nr8r
r�registry�find�
ValueError)rR�typ�offset�freq_n�	freq_namerGs      r(�!convert_json_field_to_pandas_typere�sG��R��-�C�
�h���	�	�	��y�y��W�-�-�	����y�y��Y�/�/�	�	�	��y�y��V�,�,�	�
�	��	�
�	��9�9�T�?�$�U�4�[�M��3�3�
�Y�Y�v�
��u�V�}�-�F� &���&�+�+�I�F�)�&�)�<�D��T�F�!�$�$�#�	����E�!�i�5�&8�#� ��/��7��y�AQ��
��5�
 ��=�=��z�!2�3�3��
�:�3�%�@�
A�Ar*c�R�|durt|�}i}g}|r�|jjdkDrytd|j�|_t	|jj
|jj�D]&\}}t|�}||d<|j|��(n$|jt|j��|jdkDr3|j�D]\}	}
|jt|
���!n|jt|��||d<|rf|jjrP|�N|jjdk(r|jjg|d<n!|jj|d<n|�||d<|r	t|d<|S)a�
    Create a Table schema from ``data``.

    Parameters
    ----------
    data : Series, DataFrame
    index : bool, default True
        Whether to include ``data.index`` in the schema.
    primary_key : bool or None, default True
        Column names to designate as the primary key.
        The default `None` will set `'primaryKey'` to the index
        level or levels if the index is unique.
    version : bool, default True
        Whether to include a field `pandas_version` with the version
        of pandas that last revised the table schema. This version
        can be different from the installed pandas version.

    Returns
    -------
    dict

    Notes
    -----
    See `Table Schema
    <https://pandas.pydata.org/docs/user_guide/io.html#table-schema>`__ for
    conversion types.
    Timedeltas as converted to ISO8601 duration format with
    9 decimal places after the seconds field for nanosecond precision.

    Categoricals are converted to the `any` dtype, and use the `enum` field
    constraint to list the allowed values. The `ordered` attribute is included
    in an `ordered` field.

    Examples
    --------
    >>> from pandas.io.json._table_schema import build_table_schema
    >>> df = pd.DataFrame(
    ...     {'A': [1, 2, 3],
    ...      'B': ['a', 'b', 'c'],
    ...      'C': pd.date_range('2016-01-01', freq='d', periods=3),
    ...     }, index=pd.Index(range(3), name='idx'))
    >>> build_table_schema(df)
    {'fields': [{'name': 'idx', 'type': 'integer'}, {'name': 'A', 'type': 'integer'}, {'name': 'B', 'type': 'string'}, {'name': 'C', 'type': 'datetime'}], 'primaryKey': ['idx'], 'pandas_version': '1.4.0'}
    Tr,rr8�fields�
primaryKey�pandas_version)r@r-r<r�zip�levelsr6rT�append�ndim�items�	is_uniquer8�TABLE_SCHEMA_VERSION)r>r-�primary_key�version�schemarg�levelr8�	new_field�column�ss           r(�build_table_schemarx�sj��p
��}� ��&���F�
�F���:�:����!��l�D�J�J�7�D�J�"�4�:�:�#4�#4�d�j�j�6F�6F�G���t�=�e�D�	�$(�	�&�!��
�
�i�(� H�

�M�M�;�D�J�J�G�H��y�y�1�}�����I�F�A��M�M�;�A�>�?�&�	�
�
�7��=�>��F�8������%�%�+�*=��:�:����"�$(�J�J�O�O�#4�F�<� �#'�:�:�#3�#3�F�<� �	�	 �*��|���#7��� ��Mr*c��t||��}|ddD�cgc]}|d��	}}t|d|��|}|ddD�cic]}|dt|���}}d|j�vrt	d��|j|�}d	|dvr�|j
|dd	�}t|jj�d
k(r,|jjdk(rd|j_
|S|jjD�cgc]}|jd
�rdn|��c}|j_	|Scc}wcc}wcc}w)a
    Builds a DataFrame from a given schema

    Parameters
    ----------
    json :
        A JSON table schema
    precise_float : bool
        Flag controlling precision when decoding string to double values, as
        dictated by ``read_json``

    Returns
    -------
    df : DataFrame

    Raises
    ------
    NotImplementedError
        If the JSON table schema contains either timezone or timedelta data

    Notes
    -----
        Because :func:`DataFrame.to_json` uses the string 'index' to denote a
        name-less :class:`Index`, this function sets the name of the returned
        :class:`DataFrame` to ``None`` when said string is encountered with a
        normal :class:`Index`. For a :class:`MultiIndex`, the same limitation
        applies to any strings beginning with 'level_'. Therefore, an
        :class:`Index` name of 'index'  and :class:`MultiIndex` names starting
        with 'level_' are not supported.

    See Also
    --------
    build_table_schema : Inverse function.
    pandas.read_json
    )�
precise_floatrsrgr8r>)�columnsrZz<table="orient" can not yet read ISO-formatted Timedelta datarhr,r-Nr0)rrrerB�NotImplementedError�astype�	set_indexr7r-r6r8r1)�jsonrz�tablerR�	col_order�df�dtypesr's        r(�parse_table_schemar�Fs_��H
��M�:�E�,1�(�O�H�,E�F�,E�5��v��,E�I�F�	�5��=�)�	4�Y�	?�B��8�_�X�.��.�E�	�f�
�8��?�?�.�����
�
��'�!�J�
�	
�
���6�	�B��u�X��&�
�\�\�%��/�,�7�
8���r�x�x�~�~��!�#��x�x�}�}��'� $����
��I�@B�x�x�~�~��?M�!����X�.��A�5�~��B�H�H�N��I��5G����&s�D=�E�
E)r'r�return�str)r��dict[str, JSONSerializable])r�zstr | CategoricalDtype)TNT)
r>zDataFrame | Seriesr-rYrqzbool | NonerrrYr�r�)rzrYr�r)4�__doc__�
__future__r�typingrrrr9�pandas._libsr�pandas._libs.jsonr�pandas._libs.tslibsr	�pandas._libs.tslibs.dtypesr
�pandas.util._exceptionsr�pandas.core.dtypes.baserr^�pandas.core.dtypes.commonr
rrr�pandas.core.dtypes.dtypesrrrr�pandasr�pandas.core.common�core�commonr4�pandas.tseries.frequenciesr�pandas._typingrrr�pandas.core.indexes.multirrpr)r@rTrerxr��r*r(�<module>r�s����
#���
��)�)�=�4�9������ � �0���
�4���-�`�0�@JB�^�#��	Y�
�Y��Y��Y��	Y�
!�Y�x?r*

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