
    Mh<C                    <   S SK Jr  S SKJrJr  S SKrS SKJrJrJ	r	  S SK
rS SKJr  S SKrS SKJr  \(       a  S SKJr  S SKJrJr  SS	 jr    S       SS
 jjr          SS jrSS jr S     SS jjr       S                 SS jjrg)    )annotations)abcdefaultdictN)TYPE_CHECKINGAnyDefaultDictconvert_json_to_lines)	DataFrame)Iterable)IgnoreRaiseScalarc                J    U S   S:X  d  U S   S:X  a  U $ U SS n [        U 5      $ )zB
Helper function that converts JSON lists to line delimited JSON.
r   []   r	   )ss    K/var/www/html/env/lib/python3.13/site-packages/pandas/io/json/_normalize.pyconvert_to_line_delimitsr       s4     Q43;1R5C<	!BA ##    c                    Sn[        U [        5      (       a  U /n Sn/ nU  H  n[        R                  " U5      nUR	                  5        H  u  p[        U	[
        5      (       d  [        U	5      n	US:X  a  U	nOX-   U	-   n[        U
[        5      (       a  Ub"  X4:  a  US:w  a  UR                  U	5      n
XU'   Mo  UR                  U	5      n
UR                  [        XX#S-   U5      5        M     UR                  U5        M     U(       a  US   $ U$ )a0  
A simplified json_normalize

Converts a nested dict into a flat dict ("record"), unlike json_normalize,
it does not attempt to extract a subset of the data.

Parameters
----------
ds : dict or list of dicts
prefix: the prefix, optional, default: ""
sep : str, default '.'
    Nested records will generate names separated by sep,
    e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar
level: int, optional, default: 0
    The number of levels in the json string.

max_level: int, optional, default: None
    The max depth to normalize.

Returns
-------
d - dict or list of dicts, matching `ds`

Examples
--------
>>> nested_to_record(
...     dict(flat1=1, dict1=dict(c=1, d=2), nested=dict(e=dict(c=1, d=2), d=2))
... )
{'flat1': 1, 'dict1.c': 1, 'dict1.d': 2, 'nested.e.c': 1, 'nested.e.d': 2, 'nested.d': 2}
FTr   r   )

isinstancedictcopydeepcopyitemsstrpopupdatenested_to_recordappend)dsprefixseplevel	max_level	singletonnew_dsdnew_dkvnewkeys               r   r!   r!   -   s   X I"dT	Fa GGIDAa%%Fz) a&&%%*<A:		!A$%&M		!ALL)!S!)YOP- . 	e3 6 ayMr   c                    [        U [        5      (       aG  U R                  5        H1  u  pEU U U 3nU(       d  UR                  U5      n[	        UUUUS9  M3     U$ XU'   U$ )a  
Main recursive function
Designed for the most basic use case of pd.json_normalize(data)
intended as a performance improvement, see #15621

Parameters
----------
data : Any
    Type dependent on types contained within nested Json
key_string : str
    New key (with separator(s) in) for data
normalized_dict : dict
    The new normalized/flattened Json dict
separator : str, default '.'
    Nested records will generate names separated by sep,
    e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar
data
key_stringnormalized_dict	separator)r   r   r   removeprefix_normalise_json)r1   r2   r3   r4   keyvaluenew_keys          r   r6   r6   ~   st    . $**,JC#YKu5G!..y9" /#	 '  '+
#r   c           
     (   U R                  5        VVs0 s H  u  p#[        U[        5      (       a  M  X#_M      nnn[        U R                  5        VVs0 s H  u  p#[        U[        5      (       d  M  X#_M      snnS0 US9n0 UEUE$ s  snnf s  snnf )aK  
Order the top level keys and then recursively go to depth

Parameters
----------
data : dict or list of dicts
separator : str, default '.'
    Nested records will generate names separated by sep,
    e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar

Returns
-------
dict or list of dicts, matching `normalised_json_object`
 r0   )r   r   r   r6   )r1   r4   r,   r-   	top_dict_nested_dict_s         r   _normalise_json_orderedr>      s     #'**,J,$!jD6I,IJ"#zz|C|tqz!T/Bdad|C	L )i(<(( KCs   BBB
3B
c                    0 n[        U [        5      (       a  [        XS9nU$ [        U [        5      (       a  U  Vs/ s H  n[	        X1S9PM     nnU$ U$ s  snf )a0  
A optimized basic json_normalize

Converts a nested dict into a flat dict ("record"), unlike
json_normalize and nested_to_record it doesn't do anything clever.
But for the most basic use cases it enhances performance.
E.g. pd.json_normalize(data)

Parameters
----------
ds : dict or list of dicts
sep : str, default '.'
    Nested records will generate names separated by sep,
    e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar

Returns
-------
frame : DataFrame
d - dict or list of dicts, matching `normalised_json_object`

Examples
--------
>>> _simple_json_normalize(
...     {
...         "flat1": 1,
...         "dict1": {"c": 1, "d": 2},
...         "nested": {"e": {"c": 1, "d": 2}, "d": 2},
...     }
... )
{'flat1': 1, 'dict1.c': 1, 'dict1.d': 2, 'nested.e.c': 1, 'nested.e.d': 2, 'nested.d': 2}

)r1   r4   r%   )r   r   r>   list_simple_json_normalize)r#   r%   normalised_json_objectrownormalised_json_lists        r   rB   rB      si    V  "d!8b!P "! 
B		PRSPR 6s DPRS##!!  Ts   Ac                  ^^^^^^^^^^^^  S       SU4S jjjmSU4S jjm[        U [        5      (       a  U (       d
  [        5       $ [        U [        5      (       a  U /n OF[        U [        R
                  5      (       a!  [        U [        5      (       d  [        U 5      n O[        eUc  Uc  Uc  Tc  Tc  [        [        U TS95      $ Uc-  [        S U  5       5      (       a  [        U TTS9n [        U 5      $ [        U[        5      (       d  U/nUc  / nO[        U[        5      (       d  U/nU Vs/ s H  n[        U[        5      (       a  UOU/PM     snm/ m/ m[        [        5      mT V	s/ s H  n	TR                  U	5      PM     sn	mSSUUUUUUUUUU4
S jjjmT" X0 SS9  [        T5      n
Tb  U
R                  U4S	 jS
9n
TR                  5        H  u  pUb  X;-   nX;   a  [        SU S35      e[         R"                  " U[$        S9nUR&                  S:  a;  [         R(                  " [+        U5      4[$        S9n[-        U5       H	  u  pXU'   M     UR/                  T5      X'   M     U
$ s  snf s  sn	f )a  
Normalize semi-structured JSON data into a flat table.

Parameters
----------
data : dict or list of dicts
    Unserialized JSON objects.
record_path : str or list of str, default None
    Path in each object to list of records. If not passed, data will be
    assumed to be an array of records.
meta : list of paths (str or list of str), default None
    Fields to use as metadata for each record in resulting table.
meta_prefix : str, default None
    If True, prefix records with dotted (?) path, e.g. foo.bar.field if
    meta is ['foo', 'bar'].
record_prefix : str, default None
    If True, prefix records with dotted (?) path, e.g. foo.bar.field if
    path to records is ['foo', 'bar'].
errors : {'raise', 'ignore'}, default 'raise'
    Configures error handling.

    * 'ignore' : will ignore KeyError if keys listed in meta are not
      always present.
    * 'raise' : will raise KeyError if keys listed in meta are not
      always present.
sep : str, default '.'
    Nested records will generate names separated by sep.
    e.g., for sep='.', {'foo': {'bar': 0}} -> foo.bar.
max_level : int, default None
    Max number of levels(depth of dict) to normalize.
    if None, normalizes all levels.

Returns
-------
frame : DataFrame
Normalize semi-structured JSON data into a flat table.

Examples
--------
>>> data = [
...     {"id": 1, "name": {"first": "Coleen", "last": "Volk"}},
...     {"name": {"given": "Mark", "family": "Regner"}},
...     {"id": 2, "name": "Faye Raker"},
... ]
>>> pd.json_normalize(data)
    id name.first name.last name.given name.family        name
0  1.0     Coleen      Volk        NaN         NaN         NaN
1  NaN        NaN       NaN       Mark      Regner         NaN
2  2.0        NaN       NaN        NaN         NaN  Faye Raker

>>> data = [
...     {
...         "id": 1,
...         "name": "Cole Volk",
...         "fitness": {"height": 130, "weight": 60},
...     },
...     {"name": "Mark Reg", "fitness": {"height": 130, "weight": 60}},
...     {
...         "id": 2,
...         "name": "Faye Raker",
...         "fitness": {"height": 130, "weight": 60},
...     },
... ]
>>> pd.json_normalize(data, max_level=0)
    id        name                        fitness
0  1.0   Cole Volk  {'height': 130, 'weight': 60}
1  NaN    Mark Reg  {'height': 130, 'weight': 60}
2  2.0  Faye Raker  {'height': 130, 'weight': 60}

Normalizes nested data up to level 1.

>>> data = [
...     {
...         "id": 1,
...         "name": "Cole Volk",
...         "fitness": {"height": 130, "weight": 60},
...     },
...     {"name": "Mark Reg", "fitness": {"height": 130, "weight": 60}},
...     {
...         "id": 2,
...         "name": "Faye Raker",
...         "fitness": {"height": 130, "weight": 60},
...     },
... ]
>>> pd.json_normalize(data, max_level=1)
    id        name  fitness.height  fitness.weight
0  1.0   Cole Volk             130              60
1  NaN    Mark Reg             130              60
2  2.0  Faye Raker             130              60

>>> data = [
...     {
...         "state": "Florida",
...         "shortname": "FL",
...         "info": {"governor": "Rick Scott"},
...         "counties": [
...             {"name": "Dade", "population": 12345},
...             {"name": "Broward", "population": 40000},
...             {"name": "Palm Beach", "population": 60000},
...         ],
...     },
...     {
...         "state": "Ohio",
...         "shortname": "OH",
...         "info": {"governor": "John Kasich"},
...         "counties": [
...             {"name": "Summit", "population": 1234},
...             {"name": "Cuyahoga", "population": 1337},
...         ],
...     },
... ]
>>> result = pd.json_normalize(
...     data, "counties", ["state", "shortname", ["info", "governor"]]
... )
>>> result
         name  population    state shortname info.governor
0        Dade       12345   Florida    FL    Rick Scott
1     Broward       40000   Florida    FL    Rick Scott
2  Palm Beach       60000   Florida    FL    Rick Scott
3      Summit        1234   Ohio       OH    John Kasich
4    Cuyahoga        1337   Ohio       OH    John Kasich

>>> data = {"A": [1, 2]}
>>> pd.json_normalize(data, "A", record_prefix="Prefix.")
    Prefix.0
0          1
1          2

Returns normalized data with columns prefixed with the given string.
c                *  > U n [        U[        5      (       a  U H  nUc  [        U5      eX4   nM     U$ X1   n U$ ! [         aJ  nU(       a  [        SU S35      UeTS:X  a  [        R                  s SnA$ [        SU SU S35      UeSnAff = f)zInternal function to pull fieldNzKey zS not found. If specifying a record_path, all elements of data should have the path.ignorez) not found. To replace missing values of z% with np.nan, pass in errors='ignore')r   rA   KeyErrornpnan)jsspecextract_recordresultfieldeerrorss         r   _pull_field#json_normalize.<locals>._pull_field  s     	$%%!E~&uo-#]F "(      	1# 1 2  !vv1#Fqc J6 7 	s%   0> > 
B,B4B:BBc                   > T" XSS9n[        U[        5      (       d3  [        R                  " U5      (       a  / nU$ [	        U  SU SU S35      eU$ )z
Internal function to pull field for records, and similar to
_pull_field, but require to return list. And will raise error
if has non iterable value.
T)rN   z has non list value z
 for path z. Must be list or null.)r   rA   pdisnull	TypeError)rL   rM   rO   rS   s      r   _pull_records%json_normalize.<locals>._pull_records  sn     Rd; &$''yy   	  d.vhj G, ,  r   r@   c              3     #    U  H3  oR                  5        Vs/ s H  n[        U[        5      PM     snv   M5     g s  snf 7fN)valuesr   r   ).0yxs      r   	<genexpr>!json_normalize.<locals>.<genexpr>  s-     G$QXXZ8Z
1d#Z8$8s   A=Ar%   r'   r   c           
     |  >
 [        U [        5      (       a  U /n [        U5      S:  aS  U  HL  n[        T
T5       H&  u  pVUS-   [        U5      :X  d  M  T" XES   5      X&'   M(     T" XAS      USS  X#S-   S9  MN     g U  H  nT" XAS   5      nU Vs/ s H%  n[        U[        5      (       a  [	        UTTS9OUPM'     nnTR                  [        U5      5        [        T
T5       H;  u  pVUS-   [        U5      :  a  X&   n	OT" XEUS  5      n	TU   R                  U	5        M=     TR                  U5        M     g s  snf )Nr   r   r   r&   rc   )r   r   lenzipr!   r"   extend)r1   path	seen_metar&   objvalr7   recsrmeta_val_metarS   rY   _recursive_extractlengthsr'   	meta_keys	meta_valsrecordsr%   s             r   rq   *json_normalize.<locals>._recursive_extract  sO   dD!!6Dt9q= #E9 5HCqyCH,)4Sb')B	 !6 #3Aw<ab9TUIV  $Sq'2
 "	 " "!T** %QC9E "	   s4y) #E9 5HCqy3s8+#,>#.sK#@cN))(3 !6 t$# s   ,D9re   c                   > T U  3$ r\    )r`   record_prefixs    r   <lambda> json_normalize.<locals>.<lambda>
  s    M?1#1Fr   )columnszConflicting metadata name z, need distinguishing prefix )dtyper   )F)rL   dict[str, Any]rM   
list | strrN   boolreturnzScalar | Iterable)rL   r~   rM   r   r   rA   )r   )r&   intr   None)r   rA   r   r   r   r   r   NotImplementedErrorrB   anyr!   r   joinrenamer   
ValueErrorrJ   arrayobjectndimemptyrf   	enumeraterepeat)r1   record_pathmetameta_prefixry   rR   r%   r'   mrl   rO   r,   r-   r]   irp   rS   rY   rq   rr   rs   rt   ru   s       ````       @@@@@@@@r   json_normalizer      sq   \ FK",>B	 :( $d{	D$		v	D#,,	'	'
40E0E Dz!! 	L!/#>??G$GGG $DcYGDT**"m|d##v8<=1*Q%%QA3.=E GG(.I*/0%3#%0I% % %< t"A6wF 'FG !"A;,QC/LM 
 !6*;;?XXs1viv6F!!q	 % MM'*	% "& ME > 1s   8$I=6J)r   r   r   r   )r;   .r   N)r$   r   r%   r   r&   r   r'   
int | None)
r1   r   r2   r   r3   r~   r4   r   r   r~   )r1   r~   r4   r   r   r~   )r   )r#   dict | list[dict]r%   r   r   zdict | list[dict] | Any)NNNNraiser   N)r1   r   r   zstr | list | Noner   z"str | list[str | list[str]] | Noner   
str | Nonery   r   rR   r   r%   r   r'   r   r   r   )
__future__r   collectionsr   r   r   typingr   r   r   numpyrJ   pandas._libs.writersr
   pandasrV   r   collections.abcr   pandas._typingr   r   r   r!   r6   r>   rB   r   rx   r   r   <module>r      sU   #    6  (
$  NN 
N 	N
 Nb&
&& $& 	&
 &R)6 2"2"	2" 2"n &*/3" $! k
k"k -k 	k
 k k 
k k kr   