Ë
    	êñiž#  ã                  ó"  — d dl mZ d dlZd dlmZmZmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ erd dlmZ d d	lmZ 	 	 	 	 	 	 	 	 	 	 dd
„Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 	 	 	 dd„Z e«       ddddeddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Zy)é    )ÚannotationsN)ÚIterableÚMappingÚSequence)ÚTYPE_CHECKINGÚAny)Úunstable)Ú	DataFrame)ÚN_INFER_DEFAULT)ÚJSONEncoder)ÚSchemac           	     óÀ   — |dkD  rSi }t        | t        «      rt        | |||¬«      }|S t        | t        «      r| D �cg c]  }t	        ||||¬«      ‘Œ }}|S |S | S c c}w )Nr   )ÚdataÚ	separatorÚ	max_levelÚencoder©r   r   r   )Ú
isinstanceÚdictÚ_normalize_json_orderedÚlistÚ_simple_json_normalize)r   r   r   r   Únormalized_json_objectÚrowÚnormalized_json_lists          úZ/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/polars/convert/normalize.pyr   r      s‘   € ð �1‚}à!#ÐÜ�dœDÔ!Ü%<ØØ#Ø#Øô	&Ð"ð" &Ð%ô ˜œdÔ#ð  ö$ð ô 'ØØ'Ø'Ø#ö	ð$Ð ð $ð (Ð'Ø%Ð%àˆùò$s   ½Ac           	     óÜ   — t        | t        «      rV|dkD  rD|r|› |› �nd}|dz
  }| j                  «       D ]   \  }}	|r|› |› �n|}
t        |	|
||||¬«       Œ" |S  || «      ||<   |S | ||<   |S )a   
    Main recursive function.

    Designed for the most basic use case of `pl.json_normalize(data)`,
    intended as a performance improvement.

    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
    max_level
        recursion depth
    encoder
        Custom JSON encoder; if not given, `json.dumps` is used.
    r   Ú é   ©r   Ú
key_stringÚnormalized_dictr   r   r   )r   r   ÚitemsÚ_normalize_json)r   r!   r"   r   r   r   Úkey_rootÚnested_max_levelÚkeyÚvalueÚnew_keys              r   r$   r$   2   s¤   € ô< �$œÔØ�qŠ=Ù5?˜*˜ i [Ñ1ÀRˆHØ(¨1™}Ðà"Ÿj™j›lò 	‘
��UÙ08˜X˜J s eÑ,¸c�ÜØØ&Ø$3Ø'Ø.Ø#öð	ð Ðñ	 +2°$«-ˆO˜JÑ'Ø"Ð"à&*ˆ˜
Ñ#ØÐó    c                óž   — i i }}| j                  «       D ]   \  }}t        |t        «      r|||<   Œ|||<   Œ" t        |di |||¬«      }i |¥|¥S )a  
    Order the top level keys and then recursively go to depth.

    Parameters
    ----------
    data
        Deserialized JSON objects (dict or list of dicts)
    separator
        Nested records will generate names separated by sep. e.g.,
        for `separator=".", {"foo": {"bar": 0}}` -> foo.bar.
    max_level
        Max number of levels(depth of dict) to normalize.
    encoder
        Custom JSON encoder; if not given, `json.dumps` is used.

    Returns
    -------
    dict or list of dicts, matching `normalized_json_object`
    r   r    )r#   r   r   r$   )	r   r   r   r   Útop_Únested_dataÚkÚvÚnested_s	            r   r   r   g   sr   € ð2 ˜Bˆ+€DØ—
‘
“ò ‰ˆˆ1Ü�aœÔØˆK˜ŠNàˆD�ŠGð	ô ØØØØØØô€Gð ˆdÐ�gÐÐr*   ú.T)r   r   ÚschemaÚstrictÚinfer_schema_lengthr   c               ó^  — |€d}|dz  }t        | t        «      rt        | «      dk(  rt        |¬«      S t        | t        «      r| g} n9t        | t
        «      rt        | t        «      st        | «      } nd}t        |«      ‚|€t        j                  }t        t        | |||¬«      |||¬«      S )u›  
    Normalize semi-structured deserialized JSON data into a flat table.

    Dictionary objects that will not be unnested/normalized are encoded
    as json string data. Unlike it pandas' counterpart, this function will
    not encode dictionaries as objects at any level.

    .. warning::
        This functionality is considered **unstable**. It may be changed
        at any point without it being considered a breaking change.

    Parameters
    ----------
    data
        Deserialized JSON objects.
    separator
        Nested records will generate names separated by sep. e.g.,
        for `separator=".", {"foo": {"bar": 0}}` -> foo.bar.
    max_level
        Max number of levels(depth of dict) to normalize.
        If None, normalizes all levels.
    schema
        Overwrite the `Schema` when the normalized data is passed to
        the `DataFrame` constructor.
    strict
        Whether Polars should be strict when constructing the DataFrame.
    infer_schema_length
        Number of rows to take into consideration to determine the schema.
    encoder
        Custom JSON encoder function; if not given, `json.dumps` is used.

    Examples
    --------
    >>> data = [
    ...     {
    ...         "id": 1,
    ...         "name": "Cole Volk",
    ...         "fitness": {"height": 180, "weight": 85},
    ...     },
    ...     {
    ...         "id": 2,
    ...         "name": "Faye Raker",
    ...         "fitness": {"height": 155, "weight": 58},
    ...     },
    ...     {
    ...         "name": "Mark Reg",
    ...         "fitness": {"height": 170, "weight": 78},
    ...     },
    ... ]
    >>> pl.json_normalize(data, max_level=1)
    shape: (3, 4)
    â”Œâ”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”�
    â”‚ id   â”† name       â”† fitness.height â”† fitness.weight â”‚
    â”‚ ---  â”† ---        â”† ---            â”† ---            â”‚
    â”‚ i64  â”† str        â”† i64            â”† i64            â”‚
    â•žâ•�â•�â•�â•�â•�â•�â•ªâ•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•ªâ•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•ªâ•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•¡
    â”‚ 1    â”† Cole Volk  â”† 180            â”† 85             â”‚
    â”‚ 2    â”† Faye Raker â”† 155            â”† 58             â”‚
    â”‚ null â”† Mark Reg   â”† 170            â”† 78             â”‚
    â””â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

    Normalize to a specific depth, using a custom JSON encoder
    (note that `orjson.dumps` encodes to bytes, not str).

    >>> import orjson
    >>> pl.json_normalize(data, max_level=0, encoder=orjson.dumps)
    shape: (3, 3)
    â”Œâ”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”�
    â”‚ id   â”† name       â”† fitness                       â”‚
    â”‚ ---  â”† ---        â”† ---                           â”‚
    â”‚ i64  â”† str        â”† binary                        â”‚
    â•žâ•�â•�â•�â•�â•�â•�â•ªâ•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•ªâ•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•¡
    â”‚ 1    â”† Cole Volk  â”† b"{"height":180,"weight":85}" â”‚
    â”‚ 2    â”† Faye Raker â”† b"{"height":155,"weight":58}" â”‚
    â”‚ null â”† Mark Reg   â”† b"{"height":170,"weight":78}" â”‚
    â””â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜
    l        r   r   )r2   z expected list or dict of objectsr   )r2   r3   r4   )r   r   Úlenr
   r   r   Ústrr   Ú
ValueErrorÚjsonÚdumpsr   )r   r   r   r2   r3   r4   r   Úmsgs           r   Újson_normalizer<   ’   s®   € ðp ÐØˆ	Ø��N€Iä�$œÔ!¤c¨$£i°1¢nÜ Ô'Ð'Ü	�Dœ'Ô	"Øˆv‰Ü	�Dœ(Ô	#¬J°t¼SÔ,AÜ�D‹z‰à0ˆÜ˜‹oÐà€Ü—*‘*ˆäÜØØØØô		
ð ØØ/ô
ð 
r*   )
r   ú/dict[Any, Any] | Sequence[dict[Any, Any] | Any]r   r7   r   Úintr   r   Úreturnz+dict[Any, Any] | list[dict[Any, Any]] | Any)r   r   r!   r7   r"   údict[str, Any]r   r7   r   r>   r   r   r?   r@   )
r   r@   r   r7   r   r>   r   r   r?   r@   )r   r=   r   r7   r   ú
int | Noner2   zSchema | Noner3   Úboolr4   rA   r   zJSONEncoder | Noner?   r
   )Ú
__future__r   r9   Úcollections.abcr   r   r   Útypingr   r   Úpolars._utils.unstabler	   Úpolars.dataframer
   Úpolars.datatypes.constantsr   Úpolars._typingr   Úpolars.schemar   r   r$   r   r<   © r*   r   ú<module>rL      sZ  ðõ #ã ß 7Ñ 7ß %å +Ý &Ý 6áÝ*Ý$ðØ
9ðàðð ðð ð	ð
 1óð@2Ø
ð2àð2ð $ð2ð ð	2ð
 ð2ð ð2ð ó2ðj(Ø
ð(àð(ð ð(ð ð	(ð
 ó(ñV 
ƒð Ø Ø ØØ&5Ø"&ñrØ
9ðrð ðrð ð	rð
 ðrð ðrð $ðrð  ðrð òró ñrr*   