Ë
    èlÖió  ã                   ór   — d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ ddd	ej                  dfd
„Zy)é    )ÚOrderedDict)ÚDecimal)Úutils)ÚNumber)ÚRow)Ú
TypeTesterNÚpropertyÚvaluec                 ó’  ‡— ddl m} |€g }nt        j                  |«      s|g}g }t	        «       }| j
                  D ]W  Št        ˆfd„|D «       «      }	|	|vrt	        «       ||	<   t        ‰|   «      }
‰|   }|
|vr|j                  |
«       |||	   |
<   ŒY |t        j                  k(  r5t        | j                  |   j                  t        «      rt        d«      }nd}||z   }g }g }|j                  «       D ]�  \  }}t!        |«      Št#        |«      dk(  r|j                  |d   «       n|j                  |«       |D ],  }
|
|v r‰j                  ||
   «       Œ‰j                  |«       Œ. |j                  t%        ‰|«      «       Œ’ |D �cg c]*  }| j&                  | j(                  j+                  |«         ‘Œ, }}|�t        |t,        «      rX|€
t-        «       n|}t/        t1        ||«      «      }|j3                  |j4                  «       ||_        |j7                  ||«      }n|t!        |«      z   } |||||¬«      S c c}w )aÇ  
    Create a new table with row values converted into columns.

    For example:

    +---------+-----------+---------+
    |  name   | property  | value   |
    +=========+===========+=========+
    |  Jane   | gender    | female  |
    +---------+-----------+---------+
    |  Jane   | race      | black   |
    +---------+-----------+---------+
    |  Jane   | age       | 24      |
    +---------+-----------+---------+
    |  ...    |  ...      |  ...    |
    +---------+-----------+---------+

    Can be denormalized so that each unique value in `field` becomes a
    column with `value` used for its values.

    +---------+----------+--------+-------+
    |  name   | gender   | race   | age   |
    +=========+==========+========+=======+
    |  Jane   | female   | black  | 24    |
    +---------+----------+--------+-------+
    |  Jack   | male     | white  | 35    |
    +---------+----------+--------+-------+
    |  Joe    | male     | black  | 28    |
    +---------+----------+--------+-------+

    If one or more keys are specified then the resulting table will
    automatically have :code:`row_names` set to those keys.

    This is the opposite of :meth:`.Table.normalize`.

    :param key:
        A column name or a sequence of column names that should be
        maintained as they are in the normalized table. Typically these
        are the tables unique identifiers and any metadata about them. Or,
        :code:`None` if there are no key columns.
    :param field_column:
        The column whose values should become column names in the new table.
    :param property_column:
        The column whose values should become the values of the property
        columns in the new table.
    :param default_value:
        Value to be used for missing values in the pivot table. If not
        specified :code:`Decimal(0)` will be used for aggregations that
        return :class:`.Number` data and :code:`None` will be used for
        all others.
    :param column_types:
        A sequence of column types with length equal to number of unique
        values in field_column or an instance of :class:`.TypeTester`.
        Defaults to a generic :class:`.TypeTester`.
    :returns:
        A new :class:`.Table`.
    r   )ÚTableNc              3   ó(   •K  — | ]	  }‰|   –— Œ y ­w)N© )Ú.0ÚkÚrows     €ú\/var/www/html/strategist-ai/venv_dbt/lib/python3.12/site-packages/agate/table/denormalize.pyú	<genexpr>zdenormalize.<locals>.<genexpr>P   s   øè ø€ Ò, 1˜˜A�Ñ,ùs   ƒé   )Ú	row_names)Úagate.tabler   r   Ú
issequencer   ÚrowsÚtupleÚstrÚappendÚdefaultÚ
isinstanceÚcolumnsÚ	data_typer   r   ÚitemsÚlistÚlenr   Úcolumn_typesÚcolumn_namesÚindexr   ÚdictÚzipÚupdateÚ_forceÚrun)ÚselfÚkeyÚproperty_columnÚvalue_columnÚdefault_valuer#   r   Úfield_namesÚrow_dataÚrow_keyÚfÚvÚnew_column_namesÚnew_rowsr   r   ÚnameÚkey_column_typesÚtesterÚforce_updateÚnew_column_typesr   s                        @r   Údenormalizer<   
   s@  ø€ õv "à
€{Ø‰Ü×Ñ˜cÔ"Øˆeˆà€KÜ‹}€Hà�y‰yò !ˆÜÓ,¨Ô,Ó,ˆà˜(Ñ"Ü +£ˆH�WÑä��OÑ$Ó%ˆØ�Ñˆà�KÑØ×Ñ˜qÔ!à ˆ�Ñ˜!Òð!ð œŸ™Ò%Ü�d—l‘l <Ñ0×:Ñ:¼FÔCÜ# A›J‰Mà ˆMà˜[Ñ(Ðà€HØ€Ià—‘Ó ò 4‰ˆˆ1Ü�1‹gˆäˆq‹6�QŠ;Ø×Ñ˜Q˜q™TÕ"à×Ñ˜QÔàò 	*ˆAØ�A‰vØ—
‘
˜1˜Q™4Õ à—
‘
˜=Õ)ð		*ð 	�‰œ˜CÐ!1Ó2Õ3ð4ð  VYÖYÈT˜×)Ñ)¨$×*;Ñ*;×*AÑ*AÀ$Ó*GÓHÐYÐÐYàÐœz¨,¼
ÔCØ!-Ð!5””¸<ˆÜœC Ð%5Ó6Ó7ˆØ×Ñ˜FŸM™MÔ*Ø$ˆŒà!Ÿ:™: hÐ0@ÓAÑà+¬d°<Ó.@Ñ@Ðá�Ð+Ð-=ÈÔSÐSùò Zs   Æ/I)Úcollectionsr   Údecimalr   Úagater   Úagate.data_typesr   Ú
agate.rowsr   Úagate.type_testerr   r   r<   r   ó    r   ú<module>rD      s3   ðÝ #Ý å Ý #Ý Ý (ð °
ÈÐ`e×`mÑ`mØ!ôzTrC   