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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
U
¬ý°d‹µã@s¸ddlmZddlmZmZddlmZddlmZddlm    Z    ddl
m Z ddl m Z mZmZmZmZmZmZmZddlZdd    lmZdd
lmZmZdd lmZdd lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(dd l)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2m3Z3ddl4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=ddl>m?Z?ddl@mAZAddlBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKddlLmMZMddlNmOZOmPZPddlQmRZRe rÂddlSmTZTededdZUedgdd d!d"d#d$d"d%d$d&d$d#d'd(d)d*œd+d,„ƒZVedhd)d d!d"d#d$d"d%d$d&d$d#d'd(d"d*œd-d,„ƒZVdid5d d!d"d#d$d"d%d$d&d$d#d'd(d!d*œd6d,„ZVGd7d8„d8eƒZWGd9d:„d:eWƒZXGd;d<„d<eWƒZYGd=d>„d>eYƒZZeddddddddddddddddd?œd@d!dAdBdCd$d$d!d!d!d$d#d&dDd'dEdFdGdHœdIdJ„ƒZ[eddddddddddddddddKœd@d!dLdBdCd$d$d!d!d!d$d#d&dDd'dEdFdMdHœdNdJ„ƒZ[edddddddddddddddddOœd@d!dLdBdCd$d$d!d!d!d$d)d&dDd'dEdFdPdHœdQdJ„ƒZ[eddddddddddddddddddRœd@d!dAdBdCd$d$d!d!d!d$d)d&dDd'dEdFdSdHœdTdJ„ƒZ[e.eAdUeAdVdWdXddYddd0d0d2dddZd2dd3ddej\d[dRœd@d!d\dBdCd$d$d!d!d!d$dDd&dDd'dEdFd]dHœd^dJ„ƒZ[Gd_d`„d`ej]eeUƒZ^Gdadb„dbƒZ_Gdcdd„dde_ƒZ`Gdedf„dfe_ƒZadS)jé)Ú annotations)ÚABCÚabstractmethod)Úabc)ÚStringIO)Úislice)Ú TracebackType)Ú TYPE_CHECKINGÚAnyÚCallableÚGenericÚLiteralÚMappingÚTypeVarÚoverloadN)Úlib)ÚdumpsÚloads)ÚiNaT)
ÚCompressionOptionsÚDtypeArgÚ DtypeBackendÚFilePathÚ
IndexLabelÚ
JSONEngineÚJSONSerializableÚ
ReadBufferÚStorageOptionsÚ WriteBuffer)Úimport_optional_dependency©ÚAbstractMethodError)Údoc)Úcheck_dtype_backend)Ú
ensure_strÚis_period_dtype)ÚABCIndex)Ú
ArrowDtypeÚ    DataFrameÚ
MultiIndexÚSeriesÚisnaÚnotnaÚ to_datetime)Úconcat)Ú _shared_docs)    Ú    IOHandlesÚ dedup_namesÚextension_to_compressionÚ file_existsÚ
get_handleÚ is_fsspec_urlÚis_potential_multi_indexÚis_urlÚstringify_path)Úconvert_to_line_delimits)Úbuild_table_schemaÚparse_table_schema)Úvalidate_integer)ÚNDFrameÚFrameSeriesStrT)ÚframeÚseries)Úbound.z0FilePath | WriteBuffer[str] | WriteBuffer[bytes]r=ú
str | NoneÚstrÚintÚboolú(Callable[[Any], JSONSerializable] | NonerrzLiteral[('a', 'w')]ÚNone)Ú path_or_bufÚobjÚorientÚ date_formatÚdouble_precisionÚ force_asciiÚ    date_unitÚdefault_handlerÚlinesÚ compressionÚindexÚindentÚstorage_optionsÚmodeÚreturncCsdS©N©©rHrIrJrKrLrMrNrOrPrQrRrSrTrUrXrXúKd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/io/json/_json.pyÚto_jsonZsr[cCsdSrWrXrYrXrXrZr[nsÚepoché
TÚmsFÚinferÚwz7FilePath | WriteBuffer[str] | WriteBuffer[bytes] | Nonec Cs.|
s|dkrtdƒ‚|r(|dkr(tdƒ‚| dkrDd| ›d}t|ƒ‚| dkrd|rX|dkrdd    }t|ƒ‚|d
krˆt|tƒrˆ|j|jp‚d d }|d
kr t|tƒr t}n(t|tƒr°t}nt|tƒrÀt}nt    d ƒ‚|||||||||
| d     
¡}|ròt |ƒ}|dk    r&t || |    | d}|j  
|¡W5QRXn|SdS)N)ÚsplitÚtablez?'index=False' is only valid when 'orient' is 'split' or 'table'Úrecordsz3'lines' keyword only valid when 'orient' is records)Úar`zmode=z@ is not a valid option.Only 'w' and 'a' are currently supported.rdzMmode='a' (append) is only supported whenlines is True and orient is 'records'rbÚvalues)Únamez''obj' should be a Series or a DataFrame)rJrKrLÚ ensure_asciirNrOrRrS)rQrT)Ú
ValueErrorÚ
isinstancer*Zto_framerfr(ÚJSONTableWriterÚ SeriesWriterÚ FrameWriterÚNotImplementedErrorÚwriter9r4Úhandle)rHrIrJrKrLrMrNrOrPrQrRrSrTrUÚmsgÚwriterÚsÚhandlesrXrXrZr[‚s^ ÿ 
ÿÿ
 
÷
 
ÿc @sdeZdZUded<ddddddddd    dd
d œ
d d „Zdd„Zddœdd„Zeeddœdd„ƒƒZ    dS)ÚWriterrCÚ_default_orientNrr=rBrDrErFrG)
rIrJrKrLrgrNrRrOrSrVc
 
CsV||_|dkr|j}||_||_||_||_||_||_||_|    |_    d|_
|  ¡dSrW) rIrurJrKrLrgrNrOrRrSZis_copyÚ _format_axes)
ÚselfrIrJrKrLrgrNrRrOrSrXrXrZÚ__init__Òs zWriter.__init__cCs t|ƒ‚dSrWr ©rwrXrXrZrvïszWriter._format_axes©rVc
Cs0|jdk}t|j|j|j|j|j||j|jdS)NÚiso)rJrLrgrNÚ    iso_datesrOrS)    rKrÚ obj_to_writerJrLrgrNrOrS)rwr|rXrXrZrnòs
øz Writer.writeú"NDFrame | Mapping[IndexLabel, Any]cCsdS)zObject to write in JSON format.NrXryrXrXrZr}ÿszWriter.obj_to_write)Nr)
Ú__name__Ú
__module__Ú __qualname__Ú__annotations__rxrvrnÚpropertyrr}rXrXrXrZrtÏs
 ö" rtc@s*eZdZdZeddœdd„ƒZdd„ZdS)    rkrRr~rzcCs,|js"|jdkr"|jj|jjdœS|jSdS)Nra)rfÚdata)rRrJrIrfreryrXrXrZr}szSeriesWriter.obj_to_writecCs*|jjjs&|jdkr&td|j›dƒ‚dS)NrRz(Series index must be unique for orient='ú')rIrRÚ    is_uniquerJrhryrXrXrZrvszSeriesWriter._format_axesN©rr€rrurƒr}rvrXrXrXrZrksrkc@s*eZdZdZeddœdd„ƒZdd„ZdS)    rlÚcolumnsr~rzcCs0|js&|jdkr&|jjdd}|d=n|j}|S)Nra)rJrR)rRrJrIÚto_dict)rwr}rXrXrZr}s
zFrameWriter.obj_to_writecCsP|jjjs&|jdkr&td|j›dƒ‚|jjjsL|jdkrLtd|j›dƒ‚dS)z:
        Try to format axes if they are datelike.
        )rRrˆz+DataFrame index must be unique for orient='z'.)rRrˆrcz-DataFrame columns must be unique for orient='N)rIrRr†rJrhrˆryrXrXrZrv s ÿ ÿzFrameWriter._format_axesNr‡rXrXrXrZrlsrlc sJeZdZdZdddddddddd    d
œ    ‡fd d „ Zed dœdd„ƒZ‡ZS)rjrcNrrBrCrDrErFrG)    rJrKrLrgrNrRrOrSrVc
s.tƒj|||||||||    d    |dkr:d|›d}
t|
ƒ‚t||jd|_|jdkrht|jt    ƒrht
dƒ‚|jdkr„|j t |jj ƒks˜t|j |jj ¡ƒr¤d    }
t|
ƒ‚| ¡}|jd
gd j} t| ƒrÚ||  d d „¡|| <t|jjƒrò|j ¡|_|js
|jdd|_n|jdd|_d|_d|_||_dS)zù
        Adds a `schema` attribute with the Table Schema, resets
        the index (can't do in caller, because the schema inference needs
        to know what the index is, forces orient to records, and forces
        date_format to 'iso'.
        )rOrSr{z8Trying to write with `orient='table'` and `date_format='zH'`. Table Schema requires dates to be formatted with `date_format='iso'`©rRéz6orient='table' is not supported for MultiIndex columnséz/Overlapping names between the index and columnsÚ    timedelta)ÚincludecSs| ¡SrW)Ú    isoformat)ÚxrXrXrZÚ<lambda>oóz*JSONTableWriter.__init__.<locals>.<lambda>T)ZdropFrcN)Úsuperrxrhr:rRÚschemaÚndimrirˆr)rmrfÚsetÚnamesÚlenÚ intersectionÚcopyZ select_dtypesZapplymapr%ÚdtypeZ to_timestampZ reset_indexrIrKrJ) rwrIrJrKrLrgrNrRrOrSrpZ
timedeltas©Ú    __class__rXrZrx5sP÷ 
ÿÿÿþý  zJSONTableWriter.__init__r~rzcCs|j|jdœS)N)r”r„)r”rIryrXrXrZr}}szJSONTableWriter.obj_to_write)Nr)rr€rrurxrƒr}Ú __classcell__rXrXrœrZrj2s  ö$Hrj)rJÚtypr›Ú convert_axesÚ convert_datesÚkeep_default_datesÚ precise_floatrNÚencodingÚencoding_errorsrPrQÚnrowsrTÚ dtype_backendÚenginez.FilePath | ReadBuffer[str] | ReadBuffer[bytes]zLiteral['frame']úDtypeArg | Noneúbool | list[str]ú
int | NoneúDtypeBackend | lib.NoDefaultrúJsonReader[Literal['frame']])rHrJrŸr›r¡r¢r£rNr¤r¥rPÚ    chunksizerQr¦rTr§r¨rVcCsdSrWrX©rHrJrŸr›r r¡r¢r£rNr¤r¥rPr®rQr¦rTr§r¨rXrXrZÚ    read_json‚sr°)rJr›r r¡r¢r£rNr¤r¥rPrQr¦rTr§r¨zLiteral['series']úJsonReader[Literal['series']]cCsdSrWrXr¯rXrXrZr°›s)rJr›r r¡r¢r£rNr¤r¥rPr®rQr¦rTr§r¨r*cCsdSrWrXr¯rXrXrZr°´s)rJrŸr›r r¡r¢r£rNr¤r¥rPr®rQr¦rTr§r¨r(cCsdSrWrXr¯rXrXrZr°ÍsrTÚdecompression_optionsrH)rTr²r?ÚstrictÚujsonzLiteral[('frame', 'series')]zDataFrame | Series | JsonReadercCs˜|dkr|rtdƒ‚|dkr(|r(tdƒ‚t|ƒ|dkrD|dkrDd}|dkrX|dkrXd}t||||||||||    | | | |||
||d}| rŒ|S| ¡SdS)a”
    Convert a JSON string to pandas object.
 
    Parameters
    ----------
    path_or_buf : a valid JSON str, path object or file-like object
        Any valid string path is acceptable. The string could be a URL. Valid
        URL schemes include http, ftp, s3, and file. For file URLs, a host is
        expected. A local file could be:
        ``file://localhost/path/to/table.json``.
 
        If you want to pass in a path object, pandas accepts any
        ``os.PathLike``.
 
        By file-like object, we refer to objects with a ``read()`` method,
        such as a file handle (e.g. via builtin ``open`` function)
        or ``StringIO``.
    orient : str, optional
        Indication of expected JSON string format.
        Compatible JSON strings can be produced by ``to_json()`` with a
        corresponding orient value.
        The set of possible orients is:
 
        - ``'split'`` : dict like
          ``{{index -> [index], columns -> [columns], data -> [values]}}``
        - ``'records'`` : list like
          ``[{{column -> value}}, ... , {{column -> value}}]``
        - ``'index'`` : dict like ``{{index -> {{column -> value}}}}``
        - ``'columns'`` : dict like ``{{column -> {{index -> value}}}}``
        - ``'values'`` : just the values array
 
        The allowed and default values depend on the value
        of the `typ` parameter.
 
        * when ``typ == 'series'``,
 
          - allowed orients are ``{{'split','records','index'}}``
          - default is ``'index'``
          - The Series index must be unique for orient ``'index'``.
 
        * when ``typ == 'frame'``,
 
          - allowed orients are ``{{'split','records','index',
            'columns','values', 'table'}}``
          - default is ``'columns'``
          - The DataFrame index must be unique for orients ``'index'`` and
            ``'columns'``.
          - The DataFrame columns must be unique for orients ``'index'``,
            ``'columns'``, and ``'records'``.
 
    typ : {{'frame', 'series'}}, default 'frame'
        The type of object to recover.
 
    dtype : bool or dict, default None
        If True, infer dtypes; if a dict of column to dtype, then use those;
        if False, then don't infer dtypes at all, applies only to the data.
 
        For all ``orient`` values except ``'table'``, default is True.
 
    convert_axes : bool, default None
        Try to convert the axes to the proper dtypes.
 
        For all ``orient`` values except ``'table'``, default is True.
 
    convert_dates : bool or list of str, default True
        If True then default datelike columns may be converted (depending on
        keep_default_dates).
        If False, no dates will be converted.
        If a list of column names, then those columns will be converted and
        default datelike columns may also be converted (depending on
        keep_default_dates).
 
    keep_default_dates : bool, default True
        If parsing dates (convert_dates is not False), then try to parse the
        default datelike columns.
        A column label is datelike if
 
        * it ends with ``'_at'``,
 
        * it ends with ``'_time'``,
 
        * it begins with ``'timestamp'``,
 
        * it is ``'modified'``, or
 
        * it is ``'date'``.
 
    precise_float : bool, default False
        Set to enable usage of higher precision (strtod) function when
        decoding string to double values. Default (False) is to use fast but
        less precise builtin functionality.
 
    date_unit : str, default None
        The timestamp unit to detect if converting dates. The default behaviour
        is to try and detect the correct precision, but if this is not desired
        then pass one of 's', 'ms', 'us' or 'ns' to force parsing only seconds,
        milliseconds, microseconds or nanoseconds respectively.
 
    encoding : str, default is 'utf-8'
        The encoding to use to decode py3 bytes.
 
    encoding_errors : str, optional, default "strict"
        How encoding errors are treated. `List of possible values
        <https://docs.python.org/3/library/codecs.html#error-handlers>`_ .
 
        .. versionadded:: 1.3.0
 
    lines : bool, default False
        Read the file as a json object per line.
 
    chunksize : int, optional
        Return JsonReader object for iteration.
        See the `line-delimited json docs
        <https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#line-delimited-json>`_
        for more information on ``chunksize``.
        This can only be passed if `lines=True`.
        If this is None, the file will be read into memory all at once.
 
        .. versionchanged:: 1.2
 
           ``JsonReader`` is a context manager.
 
    {decompression_options}
 
        .. versionchanged:: 1.4.0 Zstandard support.
 
    nrows : int, optional
        The number of lines from the line-delimited jsonfile that has to be read.
        This can only be passed if `lines=True`.
        If this is None, all the rows will be returned.
 
        .. versionadded:: 1.1
 
    {storage_options}
 
        .. versionadded:: 1.2.0
 
    dtype_backend : {{"numpy_nullable", "pyarrow"}}, defaults to NumPy backed DataFrames
        Which dtype_backend to use, e.g. whether a DataFrame should have NumPy
        arrays, nullable dtypes are used for all dtypes that have a nullable
        implementation when "numpy_nullable" is set, pyarrow is used for all
        dtypes if "pyarrow" is set.
 
        The dtype_backends are still experimential.
 
        .. versionadded:: 2.0
 
    engine : {{"ujson", "pyarrow"}}, default "ujson"
        Parser engine to use. The ``"pyarrow"`` engine is only available when
        ``lines=True``.
 
        .. versionadded:: 2.0
 
    Returns
    -------
    Series or DataFrame
        The type returned depends on the value of `typ`.
 
    See Also
    --------
    DataFrame.to_json : Convert a DataFrame to a JSON string.
    Series.to_json : Convert a Series to a JSON string.
    json_normalize : Normalize semi-structured JSON data into a flat table.
 
    Notes
    -----
    Specific to ``orient='table'``, if a :class:`DataFrame` with a literal
    :class:`Index` name of `index` gets written with :func:`to_json`, the
    subsequent read operation will incorrectly set the :class:`Index` name to
    ``None``. This is because `index` is also used by :func:`DataFrame.to_json`
    to denote a missing :class:`Index` name, and the subsequent
    :func:`read_json` operation cannot distinguish between the two. The same
    limitation is encountered with a :class:`MultiIndex` and any names
    beginning with ``'level_'``.
 
    Examples
    --------
    >>> df = pd.DataFrame([['a', 'b'], ['c', 'd']],
    ...                   index=['row 1', 'row 2'],
    ...                   columns=['col 1', 'col 2'])
 
    Encoding/decoding a Dataframe using ``'split'`` formatted JSON:
 
    >>> df.to_json(orient='split')
        '{{"columns":["col 1","col 2"],"index":["row 1","row 2"],"data":[["a","b"],["c","d"]]}}'
    >>> pd.read_json(_, orient='split')
          col 1 col 2
    row 1     a     b
    row 2     c     d
 
    Encoding/decoding a Dataframe using ``'index'`` formatted JSON:
 
    >>> df.to_json(orient='index')
    '{{"row 1":{{"col 1":"a","col 2":"b"}},"row 2":{{"col 1":"c","col 2":"d"}}}}'
 
    >>> pd.read_json(_, orient='index')
          col 1 col 2
    row 1     a     b
    row 2     c     d
 
    Encoding/decoding a Dataframe using ``'records'`` formatted JSON.
    Note that index labels are not preserved with this encoding.
 
    >>> df.to_json(orient='records')
    '[{{"col 1":"a","col 2":"b"}},{{"col 1":"c","col 2":"d"}}]'
    >>> pd.read_json(_, orient='records')
      col 1 col 2
    0     a     b
    1     c     d
 
    Encoding with Table Schema
 
    >>> df.to_json(orient='table')
        '{{"schema":{{"fields":[{{"name":"index","type":"string"}},{{"name":"col 1","type":"string"}},{{"name":"col 2","type":"string"}}],"primaryKey":["index"],"pandas_version":"1.4.0"}},"data":[{{"index":"row 1","col 1":"a","col 2":"b"}},{{"index":"row 2","col 1":"c","col 2":"d"}}]}}'
    rbz)cannot pass both dtype and orient='table'z0cannot pass both convert_axes and orient='table'NT)rJrŸr›r r¡r¢r£rNr¤rPr®rQr¦rTr¥r§r¨)rhr#Ú
JsonReaderÚread)rHrJrŸr›r r¡r¢r£rNr¤r¥rPr®rQr¦rTr§r¨Z json_readerrXrXrZr°æsD  îc@s@eZdZdZddejdfdddddddd    d
d d d dœ dd„Zdd„Zdd„Zddœdd„Z    e
dddœdd„ƒZ e
dddœd d„ƒZ e
d!d"dœd#d„ƒZ d"dœd$d„Z d"dœd%d&„Z d dœd'd(„Z d)d)dœd*d+„Ze
dddœd,d-„ƒZe
dddœd.d-„ƒZe
d!d"dœd/d-„ƒZd"dœd0d-„Zd)dœd1d2„Zd3d4d5d d6œd7d8„ZdS)9rµzö
    JsonReader provides an interface for reading in a JSON file.
 
    If initialized with ``lines=True`` and ``chunksize``, can be iterated over
    ``chunksize`` lines at a time. Otherwise, calling ``read`` reads in the
    whole document.
    Nr³r´r>rEr«rrrBr¬rrG) rŸr¢r£rPr®rQr¦rTr¥r§r¨rVcCs:||_||_||_||_||_||_||_|    |_|
|_||_    | |_
||_ | |_ | |_ d|_||_||_d|_||_|j    dkrŽtd|j    ›dƒ‚|j dk    rÈtd|j dƒ|_ |j s¶tdƒ‚|j    dkrÈtd    ƒ‚|jdk    rðtd
|jdƒ|_|j sðtd ƒ‚|j    dkr|j s td ƒ‚||_n"|j    d kr6| |¡}| |¡|_dS)Nr>Úpyarrowr´zThe engine type z is currently not supported.r®rŒz*chunksize can only be passed if lines=Truer·z<currently pyarrow engine doesn't support chunksize parameterr¦z&nrows can only be passed if lines=TruezEcurrently pyarrow engine only supports the line-delimited JSON formatr´)rJrŸr›r r¡r¢r£rNr¤r¨rQrTrPr®Ú
nrows_seenr¦r¥rsr§rhr<r„Ú_get_data_from_filepathÚ_preprocess_data)rwÚfilepath_or_bufferrJrŸr›r r¡r¢r£rNr¤rPr®rQr¦rTr¥r§r¨r„rXrXrZrxsX
 ÿ
 
ÿ
 ÿ 
zJsonReader.__init__c    CsPt|dƒr.|js.|js.|| ¡}W5QRXt|dƒsL|jsD|jrLt|ƒ}|S)a&
        At this point, the data either has a `read` attribute (e.g. a file
        object or a StringIO) or is a string that is a JSON document.
 
        If self.chunksize, we prepare the data for the `__next__` method.
        Otherwise, we read it into memory for the `read` method.
        r¶)Úhasattrr®r¦r¶r)rwr„rXrXrZrº`s zJsonReader._preprocess_datacCs˜t|ƒ}t|tƒr*t|ƒs*t|ƒs*t|ƒrRt|d|j|j|j    |j
d|_ |j j }nBt|tƒr”|  ¡ dtdd„tDƒƒ¡r”t|ƒs”td|›dƒ‚|S)aÝ
        The function read_json accepts three input types:
            1. filepath (string-like)
            2. file-like object (e.g. open file object, StringIO)
            3. JSON string
 
        This method turns (1) into (2) to simplify the rest of the processing.
        It returns input types (2) and (3) unchanged.
 
        It raises FileNotFoundError if the input is a string ending in
        one of .json, .json.gz, .json.bz2, etc. but no such file exists.
        Úr)r¤rQrTÚerrors)ú.jsoncss|]}d|›VqdS)r¿NrX)Ú.0ÚcrXrXrZÚ    <genexpr>‘sz5JsonReader._get_data_from_filepath.<locals>.<genexpr>zFile z does not exist)r8rirCr7r5r3r4r¤rQrTr¥rsroÚlowerÚendswithÚtupler2ÚFileNotFoundError)rwr»rXrXrZr¹ps8ÿþýüú
ÿÿþûz"JsonReader._get_data_from_filepathrCrzcCs&dd dd„dd„|DƒDƒ¡›dS)zG
        Combines a list of JSON objects into one JSON object.
        ú[ú,cSsg|] }|r|‘qSrXrX©rÀÚlinerXrXrZÚ
<listcomp>žsz-JsonReader._combine_lines.<locals>.<listcomp>css|]}| ¡VqdSrW)ÚstriprÉrXrXrZržsz,JsonReader._combine_lines.<locals>.<genexpr>ú])Újoin)rwrPrXrXrZÚ_combine_lines™s$ÿzJsonReader._combine_linesr­r()rwrVcCsdSrWrXryrXrXrZr¶¡szJsonReader.readr±r*cCsdSrWrXryrXrXrZr¶¥sz(JsonReader[Literal[('frame', 'series')]]zDataFrame | SeriescCsdSrWrXryrXrXrZr¶©sc
 
Cs<|,|jdkrrtdƒ}| |j¡}|jdkr6t}n$|jdkrVddlm}|ƒj}nd}|j    |dW5QR£S|jdkr.|j
rè|j r”t |ƒ}qô|j rÂtt|j|j ƒƒ}| |¡}| |¡}qôt|jƒ}| d    ¡}    | | |    ¡¡}n | |j¡}|jtjk    r|jd
|jd W5QR£S|W5QR£SW5QRXdS) zA
        Read the whole JSON input into a pandas object.
        r·z pyarrow.jsonZnumpy_nullabler)Ú_arrow_dtype_mappingN)Z types_mapperr´Ú
F©Z infer_objectsr§)r¨rr°r„r§r'Zpandas.io._utilrÐÚgetZ    to_pandasrPr®r.r¦ÚlistrrÏÚ_get_object_parserr$rarÚ
no_defaultÚconvert_dtypes)
rwZ pyarrow_jsonZpa_tableÚmappingrÐrIrPÚ
lines_jsonr„Z
data_linesrXrXrZr¶­s:
 
 
 
 
 
 
 
 ÿc    Cs„|j}|j}|j|j|j|j|j|j|j|jdœ}d}|dkrNt    |f|Ž 
¡}|dks^|dkr€t |t ƒsp||d<t |f|Ž 
¡}|S)z>
        Parses a json document into a pandas object.
        )rJr›r r¡r¢r£rNr§Nr?r@r›)rŸr›rJr r¡r¢r£rNr§Ú FrameParserÚparserirEÚ SeriesParser)rwÚjsonrŸr›ÚkwargsrIrXrXrZrÕ×s&ø
 
zJsonReader._get_object_parsercCs|jdk    r|j ¡dS)z©
        If we opened a stream earlier, in _get_data_from_filepath, we should
        close it.
 
        If an open stream or file was passed, we leave it open.
        N)rsÚcloseryrXrXrZrßòs
zJsonReader.closezJsonReader[FrameSeriesStrT]cCs|SrWrXryrXrXrZÚ__iter__üszJsonReader.__iter__cCsdSrWrXryrXrXrZÚ__next__ÿszJsonReader.__next__cCsdSrWrXryrXrXrZráscCsdSrWrXryrXrXrZrásc
CsÖ|jr|j|jkr| ¡t‚tt|j|jƒƒ}|s@| ¡t‚zB| |¡}|     |¡}t
|j|jt |ƒƒ|_ |jt |ƒ7_Wn.t k
r°}z| ¡|‚W5d}~XYnX|jtjk    rÎ|jd|jdS|SdS)NFrÒ)r¦r¸rßÚ StopIterationrÔrr„r®rÏrÕÚranger˜rRÚ    Exceptionr§rrÖr×)rwrPrÙrIÚexrXrXrZrá s*
 
 ÿcCs|SrWrXryrXrXrZÚ    __enter__'szJsonReader.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | None)Úexc_typeÚ    exc_valueÚ    tracebackrVcCs | ¡dSrW)rß)rwrçrèrérXrXrZÚ__exit__*szJsonReader.__exit__)rr€rÚ__doc__rrÖrxrºr¹rÏrr¶rÕrßràrárærêrXrXrXrZrµs8í&D)*
rµc    @s²eZdZUded<ded<dZdddd    dœZd
d d d d d
ejfd dddddddœdd„Zddœdd„Z    dd„Z
dd„Z ddœdd„Z dd„Z d'ddd œd!d"„Zd#d$„Zd%d&„Zd
S)(ÚParserztuple[str, ...]Ú _split_keysrCru)rrr^ÚusÚnsi€3ál,b/l`'ºrlF[L'€NTFr©rErªr¬rG)r›r r¡r¢r£r§rVc
 
Cs’||_|dkr|j}||_||_|dk    rX| ¡}||jkrJtd|j›ƒ‚|j||_n |jd|_||_    ||_
||_ ||_ ||_ d|_|    |_dS)Nzdate_unit must be one of rr)rÝrurJr›rÃÚ _STAMP_UNITSrhÚ _MIN_STAMPSÚ    min_stampr£r r¡rNr¢rIr§)
rwrÝrJr›r r¡r¢r£rNr§rXrXrZrx?s$ 
 zParser.__init__rzcCs8t| ¡ƒ t|jƒ¡}|r4d |¡}td|›ƒ‚dS)zT
        Checks that dict has only the appropriate keys for orient='split'.
        z, z!JSON data had unexpected key(s): N)r–ÚkeysÚ
differencerírÎrh)rwÚdecodedZbad_keysZbad_keys_joinedrXrXrZÚcheck_keys_splitds
zParser.check_keys_splitcCs2| ¡|jdkrdS|jr$| ¡| ¡|jSrW)Ú_parserIr Ú _convert_axesÚ_try_convert_typesryrXrXrZrÛms
z Parser.parsecCs t|ƒ‚dSrWr ryrXrXrZr÷wsz Parser._parsecCsP|j}|dk    st‚|jD]2}|j|| |¡ddd\}}|rt|j||ƒqdS)z&
        Try to convert axes.
        NFT)rfr„Ú
use_dtypesr¡)rIÚAssertionErrorZ _AXIS_ORDERSÚ_try_convert_dataZ    _get_axisÚsetattr)rwrIZ    axis_nameZnew_axisÚresultrXrXrZrøzs 
ü
zParser._convert_axescCs t|ƒ‚dSrWr ryrXrXrZrùŠszParser._try_convert_types)rúr¡c
Cs|r’|js.tt|ƒƒr|dfS| tj¡dfS|jdkr:nXt|jtƒrR|j |¡n|j}|dk    r’z|     |¡dfWSt
t fk
r|dfYSX|r°|  |¡\}}|r°|dfS|j tjk    rÎt|tƒsÎ|dfS|jdkrz|     d¡}Wnt
t fk
rYnX|jjdkrH|jdkrHz|     d¡}Wnt
t fk
rFYnXt|ƒrœ|jdkrœz |     d¡}||k ¡r||}Wnt
t tfk
ršYnX|jd    krÒz|     d¡}Wnt
t fk
rÐYnX|d
krút|ƒrú|jd krú|dfS|dfS) zO
        Try to parse a ndarray like into a column by inferring dtype.
        FTNÚobjectÚfloat64Úf)ÚfloatrÿÚint64rDrRra)r›Úallr,ZfillnaÚnpÚnanriÚdictrÓÚastypeÚ    TypeErrorrhÚ_try_convert_to_dater§rrÖr&Úkindr˜Ú OverflowErrorrJ)rwrfr„rúr¡r›Únew_datarþrXrXrZrüs^  
ÿ  
  zParser._try_convert_datac Cst|ƒs|dfS|}|jdkr`z| d¡}Wn2tk
rH|dfYSttfk
r^YnXt|jjtj    ƒržt
|j ƒ||j kB|j t kB}| ¡sž|dfS|jr¬|jfn|j}|D]@}zt|d|d}Wntttfk
rêYq¶YnX|dfS|dfS)zÌ
        Try to parse a ndarray like into a date column.
 
        Try to coerce object in epoch/iso formats and integer/float in epoch
        formats. Return a boolean if parsing was successful.
        FrÿrÚraise)r¾ÚunitT)r˜r›rr r    rhÚ
issubclassÚtyperÚnumberr+Z_valuesròrrrNrðr-)rwr„r Zin_rangeZ
date_unitsrNrXrXrZr
Ûs6
 ÿþÿ
 zParser._try_convert_to_datecCs t|ƒ‚dSrWr ryrXrXrZÚ_try_convert_datesszParser._try_convert_dates)TT)rr€rr‚rðrñrrÖrxrörÛr÷rørùrür
rrXrXrXrZrì3s4
ü ö%    
ûN'rìc@s0eZdZdZdZddœdd„Zddœdd„Zd    S)
rÜrR)rfrRr„rGrzcCsRt|j|jd}|jdkrDdd„| ¡Dƒ}| |¡tf|Ž|_n
t|ƒ|_dS)N©r£racSsi|]\}}t|ƒ|“qSrX©rC©rÀÚkÚvrXrXrZÚ
<dictcomp>sz'SeriesParser._parse.<locals>.<dictcomp>)rrÝr£rJÚitemsrör*rI)rwr„rõrXrXrZr÷
s 
 
zSeriesParser._parsecCs4|jdkrdS|jd|j|jd\}}|r0||_dS)Nr„©r¡)rIrür¡)rwrIrþrXrXrZrùs
ÿ
zSeriesParser._try_convert_typesN)rr€rrurír÷rùrXrXrXrZrÜs
rÜc@sNeZdZdZdZddœdd„Zdddœdd    „Zddœd
d „Zddœd d „ZdS)rÚrˆ)rˆrRr„rGrzcCsô|j}|j}|dkr.tt||jddd|_nÂ|dkr˜dd„t||jd ¡Dƒ}| |¡dd„|dDƒ}t|t    |dƒƒ|d<tfd    di|—Ž|_nX|d
kr¾tj
t||jddd
d |_n2|d krØt ||jd|_ntt||jddd|_dS) Nrˆr)r›racSsi|]\}}t|ƒ|“qSrXrrrXrXrZr+sÿz&FrameParser._parse.<locals>.<dictcomp>cSs"g|]}t|tƒrt|ƒn|‘qSrX)rirÔrÅ)rÀÚcolrXrXrZrË0sÿz&FrameParser._parse.<locals>.<listcomp>r›rR)r›rJrb) rÝrJr(rr£rIrrör1r6Ú    from_dictr;)rwrÝrJrõZ
orig_namesrXrXrZr÷"s@ ÿ
þ
þþ ý
 ÿzFrameParser._parseNc Cs”|dkrdd„}|j}|dk    s"t‚d}i}t| ¡ƒD]8\}\}}|||ƒrf|||ƒ\}    }
|
rf|    }d}|||<q6|rt||jd} |j| _| |_dS)zM
        Take a conversion function and possibly recreate the frame.
        NcSsdS)NTrX©rrÁrXrXrZr‘Kr’z0FrameParser._process_converter.<locals>.<lambda>FTrŠ)rIrûÚ    enumeraterr(rRrˆ) rwrZfiltrIZ needs_new_objZnew_objÚirrÁr rþZ    new_framerXrXrZÚ_process_converterFs" 
 
zFrameParser._process_convertercs2ˆjdkrdSˆjrˆ ¡ˆ ‡fdd„¡dS)Ncsˆj||ddS)NFr)rürryrXrZr‘gr’z0FrameParser._try_convert_types.<locals>.<lambda>)rIr¡rr!ryrXryrZrù`s
 
ÿzFrameParser._try_convert_typescs\ˆjdkrdSˆj}t|tƒr"g}t|ƒ‰ddœdd„‰ˆ ‡fdd„‡‡‡fdd„¡dS)NrErzcSsTt|tƒsdS| ¡}| d¡sL| d¡sL|dksL|dksL|dksL| d¡rPdSdS)    zK
            Return if this col is ok to try for a date parse.
            FZ_atÚ_timeÚmodifiedÚdateÚdatetimeÚ    timestampT)rirCrÃrÄÚ
startswith)rZ    col_lowerrXrXrZÚis_okts"
ÿþýüûúz-FrameParser._try_convert_dates.<locals>.is_okcs
ˆ |¡SrW)r
rryrXrZr‘ˆr’z0FrameParser._try_convert_dates.<locals>.<lambda>csˆjrˆ|ƒp|ˆkSrW)r¢r©r¡r(rwrXrZr‘‰s)rIr¡rirEr–r!)rwZconvert_dates_list_boolrXr)rZrjs
 
 
þzFrameParser._try_convert_dates)N)    rr€rrurír÷r!rùrrXrXrXrZrÚs $
rÚ) ............) ............) Nr\r]Tr^NFr_TrNr`)bÚ
__future__rrrrÚ collectionsÚiorÚ    itertoolsrÚtypesrÚtypingr    r
r r r rrrÚnumpyrZ pandas._libsrZpandas._libs.jsonrrZpandas._libs.tslibsrZpandas._typingrrrrrrrrrrZpandas.compat._optionalrZ pandas.errorsr!Zpandas.util._decoratorsr"Zpandas.util._validatorsr#Zpandas.core.dtypes.commonr$r%Zpandas.core.dtypes.genericr&Zpandasr'r(r)r*r+r,r-Zpandas.core.reshape.concatr.Zpandas.core.shared_docsr/Zpandas.io.commonr0r1r2r3r4r5r6r7r8Zpandas.io.json._normalizer9Zpandas.io.json._table_schemar:r;Zpandas.io.parsers.readersr<Zpandas.core.genericr=r>r[rtrkrlrjr°rÖÚIteratorrµrìrÜrÚrXrXrXrZÚ<module>s^     (   0     $      ,   ò.ò.ò,M6Pí6í6í6í6
þí6+"T