ó
    Ñ]jD/  ã                  ó`  • 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)Úoption_context)Úlib)Úujson_loads)Ú	timezones)Ú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                ó6  • [        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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ÚstringÚany)	r   r   r   r   Úis_np_dtypeÚ
isinstancer   r   r   )Úxs    ÚY/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pandas/io/json/_table_schema.pyÚas_json_table_typer)   7   sx   € ô< ˜×ÑØÜ	�q×	Ñ	ØÜ	˜!×	Ñ	ØÜ	�Š˜˜C×	 Ñ	 ¤J¨q´?ÄKÐ2P×$QÑ$QØÜ	�Š˜˜C×	 Ñ	 ØÜ	˜×	Ñ	Øàó    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                  SS9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.F)Údeep)ÚcomÚall_not_noner-   ÚnamesÚlenÚnameÚwarningsÚwarnr   r$   ÚcopyÚnlevelsÚfill_missing_names)ÚdataÚnmss     r(   Úset_default_namesrB   e   s  € ä
×Ò˜Ÿ™×)Ñ)Ö*Ø�j‰j×ÑˆÜˆs‹8�q‹=˜TŸZ™ZŸ_™_°Ó7Ü�MŠMØ?Ü+Ó-òð ˆô �‹X˜‹\œcÑ!FÁ#Ó!F×FÑFÜ�MŠMØNÜ+Ó-òð ˆà�9‰9˜%ˆ9Ð €DØ‡z�z×Ñ˜AÓÜ×1Ò1°$·*±*×2BÑ2BÓCˆ�
‰
Ôð €Kð Ÿ*™*Ÿ/™/×4¨Wˆ�
‰
ŒØ€Kr*   c                ó˜  • 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      (       ag  [        R                  " UR                  5      (       a  SUS'   U$ [        R                  " UR                  5      n[        U[         5      (       a  XcS'   U$ [        U["        5      (       a  UR                  US	'   U$ )
NÚvalues)r:   ÚtypeÚenumÚconstraintsÚorderedÚfreqÚUTCÚtzÚextDtype)Údtyper:   r)   r&   r   Ú
categoriesrH   Úlistr   rI   Úfreqstrr   r
   Úis_utcrK   Úget_timezoneÚstrr   )ÚarrrM   r:   ÚfieldÚcatsrH   Úzones          r(   Ú!convert_pandas_type_to_json_fieldrX   }   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ô ×)Ò)¨%¯(©(Ó3ˆDÜ˜$¤×$Ñ$Ø"�d‘ð €Lô 
�Eœ>×	*Ñ	*Ø!ŸJ™JˆˆjÑØ€Lr*   c                óJ  • U S   n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  U R                  SS
5      $ US:X  a  gUS:X  a_  U R                  S5      (       a	  SU S    S3$ U R                  S5      (       a)  [        U S   5      n[        U5      R                  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=str)

>>> 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]'
rE   r#   rL   Nr   Úint64r   Úfloat64r   Úboolr"   Útimedelta64r    rK   zdatetime64[ns, Ú]rI   zperiod[zdatetime64[ns]r$   rG   rH   rF   )rN   rH   Úobjectz#Unsupported or invalid field type: )Úgetr   r   Ú_freqstrr   ÚregistryÚfindÚ
ValueError)rU   ÚtypÚoffsetrI   s       r(   Ú!convert_json_field_to_pandas_typerg   �   sM  € ðR �‰-€CØ
ˆhƒØ�y‰y˜ TÓ*Ð*Ø	�	Ó	Ø�y‰y˜ WÓ-Ð-Ø	�‹Ø�y‰y˜ YÓ/Ð/Ø	�	Ó	Ø�y‰y˜ VÓ,Ð,Ø	�
Ó	ØØ	�
Ó	Ø�9‰9�T�?‰?Ø$ U¨4¡[ M°Ð3Ð3Ø�Y‰Y�v×Ñä˜u V™}Ó-ˆFÜ˜vÓ&×/Ñ/ˆDà˜T˜F !Ð$Ð$à#Ø	�‹Ø˜EÓ! i°5Ó&8Ü#Ø  Ñ/°Ñ7ÀÀyÑAQñð ð ˜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:”  ax  [        SU R                  5      U l        [	        U R                  R
                  U R                  R                  SS9 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  pšU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``.

This method is a utility to generate a JSON-serializable schema
representation of a pandas Series or DataFrame, compatible with the
Table Schema specification. It enables structured data to be shared
and validated in various applications, ensuring consistency and
interoperability.

Parameters
----------
data : Series or DataFrame
    The input data for which the table schema is to be created.
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
    A dictionary representing the Table schema.

See Also
--------
DataFrame.to_json : Convert the object to a JSON string.
read_json : Convert a JSON string to pandas object.

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', 'extDtype': 'str'}, {'name': 'C', 'type': 'datetime'}], 'primaryKey': ['idx'], 'pandas_version': '1.4.0'}
Tr,   r   )Ústrictr:   ÚfieldsÚ
primaryKeyÚpandas_version)rB   r-   r>   r   ÚzipÚlevelsr8   rX   ÚappendÚndimÚitemsÚ	is_uniquer:   ÚTABLE_SCHEMA_VERSION)r@   r-   Úprimary_keyÚversionÚschemarj   Úlevelr:   Ú	new_fieldÚcolumnÚss              r(   Úbuild_table_schemar{   é   sb  € ðJ �‚}Ü  Ó&ˆà€FØ€FæØ�:‰:×Ñ Ó!Ü˜l¨D¯J©JÓ7ˆDŒJÜ" 4§:¡:×#4Ñ#4°d·j±j×6FÑ6FÈtÔT‘�Ü=¸eÓD�	Ø$(˜&Ñ!Ø—‘˜iÖ(ò  Uð
 �M‰MÔ;¸D¿J¹JÓGÔHà‡y�y�1ƒ}ØŸ™ž‰IˆFØ�M‰MÔ;¸AÓ>Ö?ò &ð 	�‰Ô7¸Ó=Ô>àˆ8ÑÞ�—‘×%×%¨+Ñ*=Ø�:‰:×Ñ Ó"Ø$(§J¡J§O¡OÐ#4ˆF�<Ò à#'§:¡:×#3Ñ#3ˆF�<Ò Ø	Ñ	 Ø*ˆ|ÑæÜ#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[        S	S
5         UR                  U5      nSSS5        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 ! , (       d  f       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_floatrv   rj   r:   r@   )Úcolumnsr]   z<table="orient" can not yet read ISO-formatted Timedelta datazfuture.distinguish_nan_and_naFNrk   r,   r-   r0   )r	   r   rg   rD   ÚNotImplementedErrorr   ÚastypeÚ	set_indexr9   r-   r8   r:   r1   )Újsonr}   ÚtablerU   Ú	col_orderÚdfÚdtypesr'   s           r(   Úparse_table_schemar‡   R  sx  € ôH ˜Ñ:€EØ,1°(©O¸HÒ,EÓFÒ,E 5�v”Ñ,E€IÐFÜ	�5˜‘=¨)Ñ	4°YÑ	?€Bð ˜8‘_ XÒ.óâ.ˆEð 	ˆf‰Ô8¸Ó?Ò?Ù.ð ð ð ˜Ÿ™›Ó'Ü!ØJó
ð 	
ô 
Ð7¸Õ	?Ø�Y‰Y�vÓˆ÷ 
@ð �u˜X‘Ó&Ø�\‰\˜% ™/¨,Ñ7Ó8ˆÜˆr�x‰x�~‰~Ó !Ó#Ø�x‰x�}‰} Ó'Ø $�—‘”ð €Ið @B¿x¹x¿~º~óÚ?M¸!Ÿ™ X×.Ñ.‘°AÒ5¹~ñˆB�H‰HŒNð €Iùò7 Gùò÷ 
@Õ	?üòs   ”E¾E"ÂE'Ä&#E8Å'
E5)r'   r   ÚreturnrS   )rˆ   údict[str, JSONSerializable])rˆ   zstr | CategoricalDtype)TNT)
r@   zDataFrame | Seriesr-   r\   rt   zbool | Noneru   r\   rˆ   r‰   )r}   r\   rˆ   r   )4Ú__doc__Ú
__future__r   Útypingr   r   r   r;   Úpandas._configr   Úpandas._libsr   Úpandas._libs.jsonr	   Úpandas._libs.tslibsr
   Úpandas.util._exceptionsr   Úpandas.core.dtypes.baser   rb   Úpandas.core.dtypes.commonr   r   r   r   Úpandas.core.dtypes.dtypesr   r   r   r   Úpandasr   Úpandas.core.commonÚcoreÚcommonr6   Úpandas.tseries.frequenciesr   Úpandas._typingr   r   r   Úpandas.core.indexes.multir   rs   r)   rB   rX   rg   r{   r‡   © r*   r(   Ú<module>r�      sÎ   ðñõ #÷ñ ó
 å )å Ý )Ý )Ý 4å 9÷ó ÷ó õ ß  Ð  å 0æ÷õ
 Ý4ð Ð ô+ò\ô0ô@IBð\ Ø#Øð	fØ
ðfàðfð ðfð ð	fð
 !õfõR@r*   