hyb
2025-11-07 cadac0a99d87c53805a07f3b4ca7fd11e524fe4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
Ë
nñúh -ãóJ—dZddlmZddlmZmZmZddlZddlm    Z    ddl
m Z ddl m Z ddlmZdd    lmZdd
lmZdd lmZmZmZmZdd 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|«ryy    )
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)    rr rrÚ is_np_dtypeÚ
isinstancerrr)Úxs úOH:\Change_password\venv_build\Lib\site-packages\pandas/io/json/_table_schema.pyÚas_json_table_typer)5sc€ô<˜ÔØÜ    qÔ    ØÜ    ˜!Ô    ØÜ     ‰˜˜CÔ     ¤J¨q´?ÄKÐ2PÔ$QØÜ     ‰˜˜CÔ     ØÜ    ˜Ô    Øàó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>lsèø€Ò!F¸Q !§,¡,¨x×"8Ñ!Fù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_namesr@csù€ä
×јŸ™×)Ñ)Ñ*؏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(r|jdd«S|dk(r|jdd«S|dk(r|jdd«S|d    k(r|jdd
«S|d k(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#rJNrÚint64rÚfloat64rÚboolr"Ú timedelta64r rIzdatetime64[ns, ú]rGzperiod[zdatetime64[ns]r$rErFrD)rLrFÚobjectz#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›sU€ð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Ø &§¡¨&¯+©+IˆFÜ)¨&°)Ó<ˆDà˜T˜F !Ð$Ð $à#Ø     ŠØ ˜EÑ ! i°5Ñ&8Ü#Ø  Ñ/°Ñ7ÀÀyÑAQôð ð˜5Ñ  Ü—=‘=  zÑ!2Ó3Ð 3àä
Ð:¸3¸%Ð@Ó
AÐAr*cóR—|dur t|«}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èsu€ðp }Ü  Ó&ˆà€FØ €Fá Ø :‰:× Ñ  Ò !ܘl¨D¯J©JÓ7ˆDŒJÜ" 4§:¡:×#4Ñ#4°d·j±j×6FÑ6FÓGò )‘ tÜ=¸eÓD    Ø$(    ˜&Ñ!Ø— ‘ ˜iÕ(ñ )ð
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«vr t    d«‚|j |«}d    |dvr«|j |dd    «}t|jj«d
k(r,|jjd k(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>)ÚcolumnsrYz<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„DsU€ôH ˜¨MÔ :€EØ,1°(©O¸HÑ,EÖF 5v“ÐF€IÐFÜ    5˜‘=¨)Ô    4°YÑ    ?€Bð˜8‘_ XÑ.öà ð    ˆf‰ Ô8¸Ó?Ñ?ð€Fð𠘟 ™ ›Ñ'Ü!Ø Jó
ð    
ð
‰6Ó    €Bàu˜X‘Ñ&Ø \‰\˜% ™/¨,Ñ7Ó 8ˆÜ ˆrx‰x~‰~Ó  !Ò #؏x‰x}‰} Ò'Ø $—‘” ð €Ið@B¿x¹x¿~¹~öØ:;˜Ÿ ™  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-rXrqz bool | NonerrrXr…r‡)rzrXr…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*