
    MhJ-                    `   S r SSKJr  SSKJrJrJr  SSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJrJrJrJr  SSKJrJrJrJr  SSKJ r   SSK!J"s  J#r$  SSK%J&r&  \(       a  SSK'J(r(J)r)  SSKJ*r*  SSK+J,r,  Sr-SS jr.S r/SS jr0SS jr1   S         SS jjr2SS jr3g)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)
MultiIndexz1.4.0c                b   [        U 5      (       a  g[        U 5      (       a  g[        U 5      (       a  g[        R                  " U S5      (       d  [        U [        [        45      (       a  g[        R                  " U S5      (       a  g[        U [        5      (       a  g[        U 5      (       a  g	g)
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)
r   r   r   r   is_np_dtype
isinstancer   r   r   r   )xs    N/var/www/html/env/lib/python3.13/site-packages/pandas/io/json/_table_schema.pyas_json_table_typer)   5   s    < 	q			!			C	 	 Jq?K2P$Q$Q	C	 	 	A~	&	&			    c                   [         R                  " U R                  R                  6 (       a  U R                  R                  n[	        U5      S:X  a9  U R                  R
                  S:X  a  [        R                  " S[        5       S9  U $ [	        U5      S:  a4  [        S U 5       5      (       a  [        R                  " S[        5       S9  U $ U R                  5       n U R                  R                  S:  a;  [         R                  " U R                  R                  5      U R                  l        U $ U R                  R
                  =(       d    SU R                  l        U $ )z?Sets index names to 'index' for regular, or 'level_x' for Multi   indexz-Index name of 'index' is not round-trippable.)
stacklevelc              3  B   #    U  H  oR                  S 5      v   M     g7f)level_N)
startswith).0r'   s     r(   	<genexpr>$set_default_names.<locals>.<genexpr>n   s     !F#Q,,x"8"8#s   z<Index names beginning with 'level_' are not round-trippable.)comall_not_noner-   nameslennamewarningswarnr   r#   copynlevelsfill_missing_names)datanmss     r(   set_default_namesrA   e   s    
))*jjs8q=TZZ__7MM?+-  X\c!F#!FFFMMN+- 99;DzzA11$**2B2BC

 K **//4W

Kr*   c                Z   U R                   nU R                  c  SnOU R                  nU[        U5      S.n[        U[        5      (       a.  UR
                  nUR                  nS[        U5      0US'   XSS'   U$ [        U[        5      (       a  UR                  R                  US'   U$ [        U[        5      (       aH  [        R                  " UR                  5      (       a  SUS'   U$ UR                  R                  US'    U$ [        U[         5      (       a  UR                  US	'   U$ )
Nvalues)r9   typeenumconstraintsorderedfreqUTCtzextDtype)dtyper9   r)   r&   r   
categoriesrG   listr   rH   freqstrr   r	   is_utcrJ   zoner   )arrrL   r9   fieldcatsrG   s         r(   !convert_pandas_type_to_json_fieldrU   }   s   IIE
xxxx"5)*E
 %)**-- &T
3m"i L 
E;	'	'

**f L 
E?	+	+EHH%%E$K L  ((--E$K L 
E>	*	*!JJjLr*   c                B   U S   nUS:X  a  gUS:X  a  U R                  SS5      $ US:X  a  U R                  SS5      $ US	:X  a  U R                  SS
5      $ US:X  a  gUS:X  al  U R                  S5      (       a	  SU S    S3$ U R                  S5      (       a6  [        U S   5      nUR                  UR                  pC[	        X45      nSU S3$ gUS:X  a?  SU ;   a  SU ;   a  [        U S   S   U S   S9$ SU ;   a  [        R                  " U S   5      $ g[        SU 35      e)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]'
rD   r$   objectr   rK   int64r   float64r   boolr"   timedelta64r    rJ   zdatetime64[ns, ]rH   zperiod[zdatetime64[ns]r#   rF   rG   rE   )rM   rG   z#Unsupported or invalid field type: )	getr   nr9   r
   r   registryfind
ValueError)rS   typoffsetfreq_n	freq_namerH   s         r(   !convert_json_field_to_pandas_typerf      sH   R -C
h			yyW--	yyY//			yyV,,	
		
	99T??$U4[M33YYvuV}-F &&++I)&<DTF!$$#	E!i5&8# /7yAQ  5 ==z!233
:3%@
AAr*   c                   USL a  [        U 5      n 0 n/ nU(       a  U R                  R                  S:  ay  [        SU R                  5      U l        [	        U R                  R
                  U R                  R                  5       H%  u  pg[        U5      nXxS'   UR                  U5        M'     O$UR                  [        U R                  5      5        U R                  S:  a4  U R                  5        H  u  pUR                  [        U
5      5        M!     OUR                  [        U 5      5        XTS'   U(       am  U R                  R                  (       aR  UcO  U R                  R                  S:X  a  U R                  R                  /US'   O!U R                  R                  US'   OUb  X$S'   U(       a	  [        US'   U$ )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,   r   r9   fields
primaryKeypandas_version)rA   r-   r=   r   ziplevelsr7   rU   appendndimitems	is_uniquer9   TABLE_SCHEMA_VERSION)r?   r-   primary_keyversionschemarh   levelr9   	new_fieldcolumnss              r(   build_table_schemary      s`   p } &FF::!lDJJ7DJ"4::#4#4djj6F6FG=eD	$(&!i(  H
 MM;DJJGHyy1}IFMM;A>? & 	7=>8%%+*=::"$(JJOO#4F< #'::#3#3F< 		 *|#7 Mr*   c                   [        XS9nUS   S    Vs/ s H  o3S   PM	     nn[        US   US9U   nUS   S    Vs0 s H  nUS   [        U5      _M     nnSUR                  5       ;   a  [	        S5      eUR                  U5      nS	US   ;   a  UR                  US   S	   5      n[        UR                  R                  5      S
:X  a-  UR                  R                  S:X  a  SUR                  l
        U$ UR                  R                   Vs/ s H  owR                  S5      (       a  SOUPM     snUR                  l	        U$ s  snf s  snf s  snf )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_floatrt   rh   r9   r?   )columnsr[   z<table="orient" can not yet read ISO-formatted Timedelta datari   r,   r-   Nr0   )r   r   rf   rC   NotImplementedErrorastype	set_indexr8   r-   r7   r9   r1   )jsonr{   tablerS   	col_orderdfdtypesr'   s           r(   parse_table_schemar   F  s\   H :E,1(OH,EF,E5v,EIF	5=)	4Y	?B 8_X..E 	f8??.   '!J
 	
 
6	BuX&\\%/,78rxx~~!#xx}}' $ I @Bxx~~?M!X..A5~BHHN I5 G&s   EE#E)r'   r   returnstr)r   dict[str, JSONSerializable])r   zstr | CategoricalDtype)TNT)
r?   zDataFrame | Seriesr-   rZ   rr   zbool | Noners   rZ   r   r   )r{   rZ   r   r   )4__doc__
__future__r   typingr   r   r   r:   pandas._libsr   pandas._libs.jsonr   pandas._libs.tslibsr	   pandas._libs.tslibs.dtypesr
   pandas.util._exceptionsr   pandas.core.dtypes.baser   r_   pandas.core.dtypes.commonr   r   r   r   pandas.core.dtypes.dtypesr   r   r   r   pandasr   pandas.core.commoncorecommonr5   pandas.tseries.frequenciesr   pandas._typingr   r   r   pandas.core.indexes.multir   rq   r)   rA   rU   rf   ry   r    r*   r(   <module>r      s   
 # 
   ) ) = 4 9        0
 4  -`0@JB^ #	Y
YY Y 	Y
 !Yx?r*   